Commit 2f15d8e7 authored by yahtoo's avatar yahtoo Committed by Paladz

Fix banscore string deadlock bug (#1724)

parent a950d842
......@@ -67,7 +67,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
}
......
......@@ -77,3 +77,16 @@ func TestReset(t *testing.T) {
t.Errorf("Failed to reset ban score.")
}
}
func TestString(t *testing.T) {
want := "persistent 100 + transient 0 at 0 = 100 as of now"
var bs DynamicBanScore
if bs.Int() != 0 {
t.Errorf("Initial state is not zero.")
}
bs.Increase(100, 0)
if bs.String() != want {
t.Fatal("DynamicBanScore String test error.")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment