Skip to content

Commit 2aab105

Browse files
GODRIVER-2667 PR Changes
1 parent 619a5b0 commit 2aab105

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

mongo/integration/unified_runner_events_helper_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ func waitForEvent(mt *mtest.T, test *testCase, op *operation) {
8888
expectedCount := int(op.Arguments.Lookup("count").Int32())
8989

9090
callback := func() bool {
91+
// Stop loop if callback has been canceled.
92+
select {
93+
case <-context.Background().Done():
94+
return true
95+
default:
96+
}
97+
9198
var count int
9299
// Spec tests only ever wait for ServerMarkedUnknown SDAM events for the time being.
93100
if eventType == "ServerMarkedUnknownEvent" {
@@ -126,11 +133,20 @@ func recordPrimary(mt *mtest.T, testCase *testCase) {
126133
}
127134

128135
func waitForPrimaryChange(mt *mtest.T, testCase *testCase, op *operation) {
136+
callback := func() bool {
137+
// Stop loop if callback has been canceled.
138+
select {
139+
case <-context.Background().Done():
140+
return true
141+
default:
142+
}
143+
144+
return getPrimaryAddress(mt, testCase.testTopology, false) != testCase.recordedPrimary
145+
}
146+
129147
timeout := convertValueToMilliseconds(mt, op.Arguments.Lookup("timeoutMS"))
130148
assert.Eventually(mt,
131-
func() bool {
132-
return getPrimaryAddress(mt, testCase.testTopology, false) != testCase.recordedPrimary
133-
},
149+
callback,
134150
timeout,
135151
100*time.Millisecond,
136152
"expected primary address to be different within the timeout period")

0 commit comments

Comments
 (0)