MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestDocumentChangeEvent

Function TestDocumentChangeEvent

db/event_manager_test.go:83–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestDocumentChangeEvent(t *testing.T) {
84 ctx := base.TestCtx(t)
85 terminator := make(chan bool)
86 defer close(terminator)
87
88 em := NewEventManager(terminator)
89 em.Start(ctx, 0, -1)
90
91 // Setup test data
92 ids := make([]string, 20)
93 for i := 0; i < 20; i++ {
94 ids[i] = fmt.Sprintf("%d", i)
95 }
96 eventForTest := func(i int) (Body, string, base.Set) {
97 testBody := Body{
98 BodyId: ids[i],
99 "value": i,
100 }
101 var channelSet base.Set
102 if i%2 == 0 {
103 channelSet = base.SetFromArray([]string{"Even"})
104 } else {
105 channelSet = base.SetFromArray([]string{"Odd"})
106 }
107 return testBody, ids[i], channelSet
108 }
109 resultChannel := make(chan interface{}, 10)
110 // Setup test handler
111 testHandler := &TestingHandler{HandledEvent: DocumentChange}
112 testHandler.SetChannel(resultChannel)
113 em.RegisterEventHandler(ctx, testHandler, DocumentChange)
114 // Raise events
115 for i := 0; i < 10; i++ {
116 body, docid, channels := eventForTest(i)
117 bodyBytes := base.MustJSONMarshal(t, body)
118 err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docid, "", channels, false)
119 assert.NoError(t, err)
120 }
121
122 assertChannelLengthWithTimeout(t, resultChannel, 10, 10*time.Second)
123
124}
125
126func TestDBStateChangeEvent(t *testing.T) {
127 ctx := base.TestCtx(t)

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
SetChannelMethod · 0.95
RegisterEventHandlerMethod · 0.95
TestCtxFunction · 0.92
SetFromArrayFunction · 0.92
MustJSONMarshalFunction · 0.92
NewEventManagerFunction · 0.85

Tested by

no test coverage detected