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)
| 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! |
| 936 | func 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 | |
| 956 | func mockDBStateChangeEvent(dbName string, state string, reason string, adminInterface string) *DBStateChangeEvent { |
| 957 | body := make(Body, 5) |
no test coverage detected