MCPcopy Create free account
hub / github.com/couchbase/moss / TestNewCollectionCloseEvents

Function TestNewCollectionCloseEvents

collection_test.go:37–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestNewCollectionCloseEvents(t *testing.T) {
38 events := map[EventKind]int{}
39 durations := map[EventKind]time.Duration{}
40
41 co := CollectionOptions{
42 OnEvent: func(e Event) {
43 events[e.Kind]++
44 durations[e.Kind] += e.Duration
45 },
46 }
47
48 m, err := NewCollection(co)
49 if err != nil || m == nil {
50 t.Errorf("expected moss")
51 }
52
53 co2 := m.Options()
54 if co2.OnEvent == nil {
55 t.Errorf("expected non-nil on-event")
56 }
57
58 err = m.Start()
59 if err != nil {
60 t.Errorf("expected Start ok")
61 }
62
63 b, err := m.NewBatch(0, 0)
64 if err != nil || b == nil {
65 t.Errorf("expected b ok")
66 }
67
68 b.Set([]byte("a"), []byte("A"))
69
70 err = m.Close()
71 if err != nil {
72 t.Errorf("expected Close ok")
73 }
74
75 if len(events) != 2 ||
76 events[EventKindCloseStart] != 1 ||
77 events[EventKindClose] != 1 {
78 t.Errorf("expected 2 close events")
79 }
80
81 // On platforms where timing granularity is too coarse, the close operation
82 // cannot be timed within that granularity (1ms) reliably.
83 if !IsTimingCoarse &&
84 durations[EventKindClose] <= 0 {
85 t.Errorf("expected close to take some time")
86 }
87
88 b1, err := m.NewBatch(0, 0)
89 if err != ErrClosed || b1 != nil {
90 t.Errorf("expected err-close")
91 }
92
93 err = m.ExecuteBatch(b, WriteOptions{})
94 if err != ErrClosed {

Callers

nothing calls this directly

Calls 8

OptionsMethod · 0.95
StartMethod · 0.95
NewBatchMethod · 0.95
SetMethod · 0.95
CloseMethod · 0.95
ExecuteBatchMethod · 0.95
SnapshotMethod · 0.95
NewCollectionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…