forked from yahoo/gryffin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_test.go
56 lines (45 loc) · 1.18 KB
/
session_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
package gryffin
import (
"sync"
"testing"
"time"
)
func TestNewGryffinStore(t *testing.T) {
t.Parallel()
store1 := NewSharedGryffinStore()
store2 := NewSharedGryffinStore()
var wg sync.WaitGroup
wg.Add(1)
go func() {
store1.See("foo", "oracle", uint64(0x1234))
b := <-store1.GetSndChan()
t.Log("Store1 got ", string(b))
store2.GetRcvChan() <- b
store1.See("foo", "hash", uint64(0x5678))
b = <-store1.GetSndChan()
t.Log("Store1 got ", string(b))
store2.GetRcvChan() <- b
wg.Done()
}()
wg.Wait()
for i := 0; i < 100000; i++ {
if store2.Seen("foo", "oracle", uint64(0x1234), 2) {
t.Logf("Store2 see the new oracle value in %d microseconds.", i)
break
}
time.Sleep(1 * time.Microsecond)
}
if !store2.Seen("foo", "oracle", uint64(0x1234), 2) {
t.Error("2nd store should see the oracle value in oracle.", store2.Oracles)
}
for i := 0; i < 100000; i++ {
if store2.Seen("foo", "hash", uint64(0x5678), 2) {
t.Logf("Store2 see the new hash value in %d microseconds.", i)
break
}
time.Sleep(1 * time.Microsecond)
}
if !store2.Seen("foo", "hash", uint64(0x5678), 2) {
t.Error("2nd store should see the hash value in hashes.", store2.Hashes)
}
}