blob: 7403bb1c12c06c40c070fe9fb5367bed7945c386 [file] [log] [blame]
Serge Bazanskie643fd62023-02-14 00:01:38 +01001package sinbin
2
3import (
4 "testing"
5 "time"
6)
7
8// TestSinbinBasics performs some basic tests on the Sinbin.
9func TestSinbinBasics(t *testing.T) {
10 var s Sinbin[string]
11
12 if s.Penalized("foo") {
13 t.Errorf("'foo' should not be penalized as it hasn't yet been added")
14 }
15 s.Add("foo", time.Now().Add(-1*time.Second))
16 if s.Penalized("foo") {
17 t.Errorf("'foo' should not be penalized as it has been added with an expired time")
18 }
19 s.Add("bar", time.Now().Add(time.Hour))
20 if !s.Penalized("bar") {
21 t.Errorf("'bar' should be penalized as it has been added with an hour long penalty")
22 }
23
24 // Force sweep.
25 s.lastSweep = time.Now().Add(-1 * time.Hour)
26 s.sweepUnlocked()
27
28 if len(s.bench) != 1 {
29 t.Errorf("there should only be one element on the bench")
30 }
31 if _, ok := s.bench["bar"]; !ok {
32 t.Errorf("the bench should contain 'bar'")
33 }
34}