-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathttl_set_test.go
59 lines (50 loc) · 1.15 KB
/
ttl_set_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package statsig
import (
"testing"
"time"
)
func TestTTLSet_AddAndContains(t *testing.T) {
set := NewTTLSet()
set.Add("key1")
if !set.Contains("key1") {
t.Errorf("key1 should exist in the set")
}
if set.Contains("key2") {
t.Errorf("key2 should not exist in the set")
}
}
func TestTTLSet_Reset(t *testing.T) {
set := NewTTLSet()
set.Add("key1")
set.Add("key2")
set.store = make(map[string]struct{})
if set.Contains("key1") {
t.Errorf("key1 should not exist after reset")
}
if set.Contains("key2") {
t.Errorf("key2 should not exist after reset")
}
}
func TestTTLSet_StartResetThread(t *testing.T) {
set := NewTTLSet()
set.resetInterval = 10 * time.Millisecond
set.StartResetThread()
set.Add("key1")
time.Sleep(20 * time.Millisecond)
if set.Contains("key1") {
t.Errorf("key1 should not exist after automatic reset")
}
set.Shutdown()
}
func TestTTLSet_Shutdown(t *testing.T) {
set := NewTTLSet()
set.resetInterval = 10 * time.Millisecond
set.StartResetThread()
set.Add("key1")
set.Shutdown()
time.Sleep(20 * time.Millisecond)
set.Add("key2")
if !set.Contains("key2") {
t.Errorf("shutdown should prevent automatic reset")
}
}