-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwatchable_store_test.go
More file actions
50 lines (46 loc) · 1.18 KB
/
Copy pathwatchable_store_test.go
File metadata and controls
50 lines (46 loc) · 1.18 KB
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
package mvcc
import (
"testing"
"time"
)
func TestConcurrentCompactionAndWatch(t *testing.T) {
st := &store{
currentRev: 10,
}
store := &watchableStore{
store: st,
synced: watcherGroup{
watchers: make(map[*watcher]struct{}),
},
unsynced: watcherGroup{
watchers: make(map[*watcher]struct{}),
},
}
// Simulate concurrent compaction and watch creation
ch := make(chan WatchResponse, 1)
compactDone := make(chan struct{})
go func() {
time.Sleep(10 * time.Millisecond)
store.compact(5)
close(compactDone)
}()
_, err := store.watch([]byte("foo"), nil, 5, 1, ch)
if err == nil {
// Wait for compaction to complete
<-compactDone
// If watch creation succeeded, syncWatchers should catch it if compaction has progressed
store.syncWatchers()
select {
case resp := <-ch:
if resp.CompactRevision != 5 {
t.Errorf("expected CompactRevision 5, got %d", resp.CompactRevision)
}
default:
// If no response was sent, it means the watch was established without receiving ErrCompacted
// which is a failure.
t.Errorf("expected watch to fail with ErrCompacted")
}
} else if err != ErrCompacted {
t.Errorf("expected ErrCompacted, got %v", err)
}
}