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

Function TestSlowExecutionProcessing

db/event_manager_test.go:168–210  ·  view source on GitHub ↗

Test sending many events with slow-running execution to validate they get dropped after hitting the max concurrent goroutines

(t *testing.T)

Source from the content-addressed store, hash-verified

166// Test sending many events with slow-running execution to validate they get dropped after hitting
167// the max concurrent goroutines
168func TestSlowExecutionProcessing(t *testing.T) {
169 ctx := base.TestCtx(t)
170 terminator := make(chan bool)
171 defer close(terminator)
172 base.SetUpTestLogging(t, base.LevelInfo, base.KeyEvents)
173
174 em := NewEventManager(terminator)
175 em.Start(ctx, 0, -1)
176
177 ids := make([]string, 20)
178 for i := 0; i < 20; i++ {
179 ids[i] = fmt.Sprintf("%d", i)
180 }
181
182 eventForTest := func(i int) (Body, string, base.Set) {
183 testBody := Body{
184 BodyId: ids[i],
185 "value": i,
186 }
187 var channelSet base.Set
188 if i%2 == 0 {
189 channelSet = base.SetFromArray([]string{"Even"})
190 } else {
191 channelSet = base.SetFromArray([]string{"Odd"})
192 }
193 return testBody, ids[i], channelSet
194 }
195
196 resultChannel := make(chan interface{}, 100)
197 testHandler := &TestingHandler{HandledEvent: DocumentChange, handleDelay: 500}
198 testHandler.SetChannel(resultChannel)
199 em.RegisterEventHandler(ctx, testHandler, DocumentChange)
200
201 for i := 0; i < 20; i++ {
202 body, docid, channels := eventForTest(i % 10)
203 bodyBytes := base.MustJSONMarshal(t, body)
204 err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docid, "", channels, false)
205 assert.NoError(t, err)
206 }
207
208 assertChannelLengthWithTimeout(t, resultChannel, 20, 10*time.Second)
209
210}
211
212func TestCustomHandler(t *testing.T) {
213 ctx := base.TestCtx(t)

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected