-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsocketstate_test.go
More file actions
42 lines (38 loc) · 875 Bytes
/
socketstate_test.go
File metadata and controls
42 lines (38 loc) · 875 Bytes
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
package live
import (
"context"
"fmt"
"testing"
"time"
)
func TestMemorySocketStateStore(t *testing.T) {
ctx := context.Background()
m := &MemorySocketStateStore{
janitorFrequency: 50 * time.Millisecond,
gets: make(chan mssGetop),
sets: make(chan mssSetop),
dels: make(chan mssDelop),
clean: make(chan bool),
}
go m.operate(ctx)
go m.janitor(ctx)
ID := SocketID("a")
state := SocketState{
Render: []byte("test"),
}
if err := m.Set(ID, state, 100*time.Millisecond); err != nil {
t.Error(err)
}
s, err := m.Get(ID)
if err != nil {
t.Error(fmt.Errorf("initial get: %w", err))
}
if string(s.Render) != string(state.Render) {
t.Error("state doesnt match")
}
time.Sleep(150 * time.Millisecond)
_, err = m.Get(ID)
if err == nil {
t.Error(fmt.Errorf("state should be clear: %w", err))
}
}