BUG:dynamicbanscore deadlock

This commit is contained in:
Jin 2020-03-07 07:55:05 +08:00 committed by John C. Vernaleo
parent 9e94ccbd0e
commit 96f3808dc9
2 changed files with 13 additions and 1 deletions

View file

@ -71,7 +71,7 @@ type DynamicBanScore struct {
func (s *DynamicBanScore) String() string {
s.mtx.Lock()
r := fmt.Sprintf("persistent %v + transient %v at %v = %v as of now",
s.persistent, s.transient, s.lastUnix, s.Int())
s.persistent, s.transient, s.lastUnix, s.int(time.Now()))
s.mtx.Unlock()
return r
}

View file

@ -66,3 +66,15 @@ func TestDynamicBanScoreReset(t *testing.T) {
t.Errorf("Failed to reset ban score.")
}
}
// TestDynamicBanScoreString
func TestDynamicBanScoreString(t *testing.T) {
var bs DynamicBanScore
base := time.Now()
r := bs.increase(100, 50, base)
if r != 150 {
t.Errorf("Unexpected result %d after ban score increase.", r)
}
t.Log(bs.String())
}