Skip to content

Commit 19700d1

Browse files
matthewdaleBenjamin Rewis
authored andcommitted
GODRIVER-2265 Further improve the assertions in the SDAM heartbeat test. (#844)
1 parent ca73d0d commit 19700d1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

mongo/integration/sdam_prose_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,25 @@ func TestSDAMProse(t *testing.T) {
4141
// For number of nodes N, interval I, and duration D, a Client should process at most X
4242
// operations:
4343
//
44-
// X = (N * (1 handshake + D/I heartbeats + D/I RTTs))
44+
// X = (N * (2 handshakes + D/I heartbeats + D/I RTTs))
4545
//
4646
// Assert that a Client processes the expected number of operations for heartbeats sent at
4747
// an interval between I and 2*I to account for different actual heartbeat intervals under
4848
// different runtime conditions.
4949

50-
duration := 2 * time.Second
50+
// Measure the actual amount of time between the start of the test and when we inspect the
51+
// sent messages. The sleep duration will be at least the specified duration but
52+
// possibly longer, which could lead to extra heartbeat messages, so account for that in
53+
// the assertions.
54+
start := time.Now()
55+
time.Sleep(2 * time.Second)
56+
messages := mt.GetProxiedMessages()
57+
duration := time.Since(start)
5158

5259
numNodes := len(options.Client().ApplyURI(mtest.ClusterURI()).Hosts)
53-
maxExpected := numNodes * (1 + 2*int(duration/heartbeatInterval))
54-
minExpected := numNodes * (1 + 2*int(duration/(heartbeatInterval*2)))
60+
maxExpected := numNodes * (2 + 2*int(duration/heartbeatInterval))
61+
minExpected := numNodes * (2 + 2*int(duration/(heartbeatInterval*2)))
5562

56-
time.Sleep(duration)
57-
messages := mt.GetProxiedMessages()
5863
assert.True(
5964
mt,
6065
len(messages) >= minExpected && len(messages) <= maxExpected,

0 commit comments

Comments
 (0)