(t *testing.T)
| 254 | } |
| 255 | |
| 256 | func TestUnhandledEvent(t *testing.T) { |
| 257 | ctx := base.TestCtx(t) |
| 258 | terminator := make(chan bool) |
| 259 | defer close(terminator) |
| 260 | |
| 261 | em := NewEventManager(terminator) |
| 262 | em.Start(ctx, 0, -1) |
| 263 | |
| 264 | ids := make([]string, 20) |
| 265 | for i := 0; i < 20; i++ { |
| 266 | ids[i] = fmt.Sprintf("%d", i) |
| 267 | } |
| 268 | |
| 269 | eventForTest := func(i int) (Body, string, base.Set) { |
| 270 | testBody := Body{ |
| 271 | BodyId: ids[i], |
| 272 | "value": i, |
| 273 | } |
| 274 | var channelSet base.Set |
| 275 | if i%2 == 0 { |
| 276 | channelSet = base.SetFromArray([]string{"Even"}) |
| 277 | } else { |
| 278 | channelSet = base.SetFromArray([]string{"Odd"}) |
| 279 | } |
| 280 | return testBody, ids[i], channelSet |
| 281 | } |
| 282 | |
| 283 | resultChannel := make(chan interface{}, 10) |
| 284 | |
| 285 | // create handler for an unhandled event |
| 286 | testHandler := &TestingHandler{HandledEvent: math.MaxUint8} |
| 287 | testHandler.SetChannel(resultChannel) |
| 288 | em.RegisterEventHandler(ctx, testHandler, math.MaxUint8) |
| 289 | |
| 290 | // send DocumentChange events to handler |
| 291 | for i := 0; i < 10; i++ { |
| 292 | body, docid, channels := eventForTest(i) |
| 293 | bodyBytes := base.MustJSONMarshal(t, body) |
| 294 | err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docid, "", channels, false) |
| 295 | assert.NoError(t, err) |
| 296 | } |
| 297 | |
| 298 | // Validate that no events were handled |
| 299 | assertChannelLengthWithTimeout(t, resultChannel, 0, 10*time.Second) |
| 300 | |
| 301 | } |
| 302 | |
| 303 | // Uses WebhookRequest for simplified tracking of POST requests received by HTTP. |
| 304 | // A mutex has been embedded in WebhookRequest to avoid race conditions. |
nothing calls this directly
no test coverage detected