Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-2265 Further improve the assertions in the SDAM heartbeat test. #844

Merged
merged 1 commit into from Feb 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions mongo/integration/sdam_prose_test.go
Expand Up @@ -43,20 +43,25 @@ func TestSDAMProse(t *testing.T) {
// For number of nodes N, interval I, and duration D, a Client should process at most X
// operations:
//
// X = (N * (1 handshake + D/I heartbeats + D/I RTTs))
// X = (N * (2 handshakes + D/I heartbeats + D/I RTTs))
//
// Assert that a Client processes the expected number of operations for heartbeats sent at
// an interval between I and 2*I to account for different actual heartbeat intervals under
// different runtime conditions.

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

numNodes := len(options.Client().ApplyURI(mtest.ClusterURI()).Hosts)
maxExpected := numNodes * (1 + 2*int(duration/heartbeatInterval))
minExpected := numNodes * (1 + 2*int(duration/(heartbeatInterval*2)))
maxExpected := numNodes * (2 + 2*int(duration/heartbeatInterval))
minExpected := numNodes * (2 + 2*int(duration/(heartbeatInterval*2)))

time.Sleep(duration)
messages := mt.GetProxiedMessages()
assert.True(
mt,
len(messages) >= minExpected && len(messages) <= maxExpected,
Expand Down