-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinmem_store_test.go
48 lines (36 loc) · 876 Bytes
/
inmem_store_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
package session
import (
"log"
"os"
"testing"
"time"
"github.com/icza/mighty"
)
func TestInMemStore(t *testing.T) {
eq, neq := mighty.EqNeq(t)
st := NewInMemStore()
defer st.Close()
eq(nil, st.Get("asdf"))
s := NewSession()
st.Add(s)
time.Sleep(10 * time.Millisecond)
eq(s, st.Get(s.ID()))
neq(s.Accessed(), s.Created())
st.Remove(s)
eq(nil, st.Get(s.ID()))
}
func TestInMemStoreSessCleaner(t *testing.T) {
eq := mighty.Eq(t)
st := NewInMemStoreOptions(&InMemStoreOptions{
SessCleanerInterval: 10 * time.Millisecond,
Logger: log.New(os.Stderr, "test~", log.LstdFlags|log.Llongfile),
})
defer st.Close()
s := NewSessionOptions(&SessOptions{Timeout: 50 * time.Millisecond})
st.Add(s)
eq(s, st.Get(s.ID()))
time.Sleep(30 * time.Millisecond)
eq(s, st.Get(s.ID()))
time.Sleep(80 * time.Millisecond)
eq(nil, st.Get(s.ID()))
}