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

Function TestWebhookOverflows

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

Source from the content-addressed store, hash-verified

526}
527
528func TestWebhookOverflows(t *testing.T) {
529 if true { // Modify conditions or re-enable once CBG-2281 is fixed
530 t.Skip("Test skipped")
531 }
532 base.LongRunningTest(t)
533
534 terminator := make(chan bool)
535 defer close(terminator)
536
537 ts, wr := InitWebhookTest()
538 defer ts.Close()
539 url := ts.URL
540
541 ids := make([]string, 200)
542 for i := 0; i < 200; i++ {
543 ids[i] = fmt.Sprintf("%d", i)
544 }
545
546 eventForTest := func(i int) (Body, string, base.Set) {
547 testBody := Body{
548 BodyId: ids[i],
549 "value": i,
550 }
551 var channelSet base.Set
552 if i%2 == 0 {
553 channelSet = base.SetFromArray([]string{"Even"})
554 } else {
555 channelSet = base.SetFromArray([]string{"Odd"})
556 }
557 return testBody, ids[i], channelSet
558 }
559
560 // Test fast fill, fast webhook
561 log.Println("Test fast fill, fast webhook")
562 wr.Clear()
563 em := NewEventManager(terminator)
564 ctx := base.TestCtx(t)
565 em.Start(ctx, 5, -1)
566 timeout := uint64(60)
567 webhookHandler, _ := NewWebhook(ctx, fmt.Sprintf("%s/echo", url), "", &timeout, nil)
568 em.RegisterEventHandler(ctx, webhookHandler, DocumentChange)
569 for i := 0; i < 100; i++ {
570 body, docId, channels := eventForTest(i % 10)
571 bodyBytes := base.MustJSONMarshal(t, body)
572 err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docId, "", channels, false)
573 assert.NoError(t, err)
574 }
575 err := em.waitForProcessedTotal(ctx, 100, DefaultWaitForWebhook)
576 assert.NoError(t, err)
577 assert.Equal(t, int64(100), em.GetEventsProcessedSuccess())
578
579 // CBG-2281 skip test temporarily under windows
580 // if runtime.GOOS != "windows" {
581 // Test queue full, slow webhook. Drops events
582 log.Println("Test queue full, slow webhook")
583 wr.Clear()
584 errCount := 0
585 em = NewEventManager(terminator)

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
RegisterEventHandlerMethod · 0.95
waitForProcessedTotalMethod · 0.95
LongRunningTestFunction · 0.92
SetFromArrayFunction · 0.92
TestCtxFunction · 0.92
MustJSONMarshalFunction · 0.92
InitWebhookTestFunction · 0.85
NewEventManagerFunction · 0.85
NewWebhookFunction · 0.85

Tested by

no test coverage detected