Skip to content

Commit 4ccc008

Browse files
matthewdaleBenjamin Rewis
authored andcommitted
GODRIVER-2265 Further improve the assertions in the SDAM heartbeat test. (#844)
1 parent 63ad6ba commit 4ccc008

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
@@ -42,20 +42,25 @@ func TestSDAMProse(t *testing.T) {
4242
// For number of nodes N, interval I, and duration D, a Client should process at most X
4343
// operations:
4444
//
45-
// X = (N * (1 handshake + D/I heartbeats + D/I RTTs))
45+
// X = (N * (2 handshakes + D/I heartbeats + D/I RTTs))
4646
//
4747
// Assert that a Client processes the expected number of operations for heartbeats sent at
4848
// an interval between I and 2*I to account for different actual heartbeat intervals under
4949
// different runtime conditions.
5050

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

5360
numNodes := len(options.Client().ApplyURI(mtest.ClusterURI()).Hosts)
54-
maxExpected := numNodes * (1 + 2*int(duration/heartbeatInterval))
55-
minExpected := numNodes * (1 + 2*int(duration/(heartbeatInterval*2)))
61+
maxExpected := numNodes * (2 + 2*int(duration/heartbeatInterval))
62+
minExpected := numNodes * (2 + 2*int(duration/(heartbeatInterval*2)))
5663

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

0 commit comments

Comments
 (0)