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