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

Function TestUnavailableWebhook

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

Source from the content-addressed store, hash-verified

888}
889
890func TestUnavailableWebhook(t *testing.T) {
891 ts, wr := InitWebhookTest()
892 defer ts.Close()
893
894 terminator := make(chan bool)
895 defer close(terminator)
896
897 ids := make([]string, 20)
898 for i := 0; i < 20; i++ {
899 ids[i] = fmt.Sprintf("%d", i)
900 }
901
902 eventForTest := func(k string, v int) (Body, string, base.Set) {
903 testBody := Body{
904 BodyId: ids[v],
905 "value": k,
906 }
907 var channelSet base.Set
908 if v%2 == 0 {
909 channelSet = base.SetFromArray([]string{"Even"})
910 } else {
911 channelSet = base.SetFromArray([]string{"Odd"})
912 }
913 return testBody, ids[v], channelSet
914 }
915
916 // Test unreachable webhook
917
918 em := NewEventManager(terminator)
919 ctx := base.TestCtx(t)
920 em.Start(ctx, 0, -1)
921 webhookHandler, _ := NewWebhook(ctx, "http://badhost:1000/echo", "", nil, nil)
922 em.RegisterEventHandler(ctx, webhookHandler, DocumentChange)
923 for i := 0; i < 10; i++ {
924 body, docId, channels := eventForTest(strconv.Itoa(-i), i)
925 bodyBytes := base.MustJSONMarshal(t, body)
926 err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docId, "", channels, false)
927 assert.NoError(t, err)
928 }
929 time.Sleep(50 * time.Millisecond)
930 assert.Equal(t, 0, wr.GetCount())
931
932}
933
934// asserts that the number of items seen in the channel within the specified time limit is the same as the expected value.
935// WARNING: This function will drain the channel of items!

Callers

nothing calls this directly

Calls 12

StartMethod · 0.95
RegisterEventHandlerMethod · 0.95
SetFromArrayFunction · 0.92
TestCtxFunction · 0.92
MustJSONMarshalFunction · 0.92
InitWebhookTestFunction · 0.85
NewEventManagerFunction · 0.85
NewWebhookFunction · 0.85
GetCountMethod · 0.80
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected