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

Function TestCustomHandler

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

Source from the content-addressed store, hash-verified

210}
211
212func TestCustomHandler(t *testing.T) {
213 ctx := base.TestCtx(t)
214 terminator := make(chan bool)
215 defer close(terminator)
216
217 em := NewEventManager(terminator)
218 em.Start(ctx, 0, -1)
219
220 ids := make([]string, 20)
221 for i := 0; i < 20; i++ {
222 ids[i] = fmt.Sprintf("%d", i)
223 }
224
225 eventForTest := func(i int) (Body, string, base.Set) {
226 testBody := Body{
227 BodyId: ids[i],
228 "value": i,
229 }
230 var channelSet base.Set
231 if i%2 == 0 {
232 channelSet = base.SetFromArray([]string{"Even"})
233 } else {
234 channelSet = base.SetFromArray([]string{"Odd"})
235 }
236 return testBody, ids[i], channelSet
237 }
238
239 resultChannel := make(chan interface{}, 20)
240
241 testHandler := &TestingHandler{HandledEvent: DocumentChange}
242 testHandler.SetChannel(resultChannel)
243 em.RegisterEventHandler(ctx, testHandler, DocumentChange)
244
245 for i := 0; i < 10; i++ {
246 body, docid, channels := eventForTest(i)
247 bodyBytes := base.MustJSONMarshal(t, body)
248 err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docid, "", channels, false)
249 assert.NoError(t, err)
250 }
251
252 assertChannelLengthWithTimeout(t, resultChannel, 10, 10*time.Second)
253
254}
255
256func TestUnhandledEvent(t *testing.T) {
257 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