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

Function assertChannelLengthWithTimeout

db/event_manager_test.go:936–954  ·  view source on GitHub ↗

asserts that the number of items seen in the channel within the specified time limit is the same as the expected value. WARNING: This function will drain the channel of items!

(t *testing.T, c chan interface{}, expectedLength int, timeout time.Duration)

Source from the content-addressed store, hash-verified

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!
936func assertChannelLengthWithTimeout(t *testing.T, c chan interface{}, expectedLength int, timeout time.Duration) {
937 count := 0
938 for {
939 if count >= expectedLength {
940 // Make sure there are no additional items on the channel after a short wait.
941 // This avoids relying on the longer timeout value for the final check.
942 time.Sleep(timeout / 100)
943 assert.Equal(t, expectedLength, count+len(c))
944 return
945 }
946
947 select {
948 case _ = <-c:
949 count++
950 case <-time.After(timeout):
951 t.Fatalf("timed out waiting for items on channel... got: %d, expected: %d", count, expectedLength)
952 }
953 }
954}
955
956func mockDBStateChangeEvent(dbName string, state string, reason string, adminInterface string) *DBStateChangeEvent {
957 body := make(Body, 5)

Callers 5

TestDocumentChangeEventFunction · 0.85
TestDBStateChangeEventFunction · 0.85
TestCustomHandlerFunction · 0.85
TestUnhandledEventFunction · 0.85

Calls 3

AfterMethod · 0.80
EqualMethod · 0.45
FatalfMethod · 0.45

Tested by

no test coverage detected