Skip to content

Commit 97a84e1

Browse files
authored
PYTHON-2697 Fix races in various CMAP spec tests (mongodb#685)
1 parent f86b2c6 commit 97a84e1

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

test/cmap/pool-checkout-no-idle.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"style": "unit",
44
"description": "must destroy and must not check out an idle connection if found while iterating available connections",
55
"poolOptions": {
6-
"maxIdleTimeMS": 10
6+
"maxIdleTimeMS": 10,
7+
"backgroundThreadIntervalMS": -1
78
},
89
"operations": [
910
{
@@ -24,11 +25,6 @@
2425
{
2526
"name": "checkOut"
2627
},
27-
{
28-
"name": "waitForEvent",
29-
"event": "ConnectionClosed",
30-
"count": 1
31-
},
3228
{
3329
"name": "waitForEvent",
3430
"event": "ConnectionCheckedOut",
@@ -56,6 +52,11 @@
5652
"connectionId": 1,
5753
"reason": "idle",
5854
"address": 42
55+
},
56+
{
57+
"type": "ConnectionCheckedOut",
58+
"connectionId": 2,
59+
"address": 42
5960
}
6061
],
6162
"ignore": [

test/cmap/pool-checkout-no-stale.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"version": 1,
33
"style": "unit",
44
"description": "must destroy and must not check out a stale connection if found while iterating available connections",
5+
"poolOptions": {
6+
"backgroundThreadIntervalMS": -1
7+
},
58
"operations": [
69
{
710
"name": "ready"
@@ -23,11 +26,6 @@
2326
{
2427
"name": "checkOut"
2528
},
26-
{
27-
"name": "waitForEvent",
28-
"event": "ConnectionClosed",
29-
"count": 1
30-
},
3129
{
3230
"name": "waitForEvent",
3331
"event": "ConnectionCheckedOut",
@@ -59,6 +57,11 @@
5957
"connectionId": 1,
6058
"reason": "stale",
6159
"address": 42
60+
},
61+
{
62+
"type": "ConnectionCheckedOut",
63+
"connectionId": 2,
64+
"address": 42
6265
}
6366
],
6467
"ignore": [

test/cmap/pool-clear-min-size.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"style": "unit",
44
"description": "pool clear halts background minPoolSize establishments",
55
"poolOptions": {
6-
"minPoolSize": 1
6+
"minPoolSize": 1,
7+
"backgroundThreadIntervalMS": 50
78
},
89
"operations": [
910
{

test/cmap/pool-create-min-size-error.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"poolOptions": {
2525
"minPoolSize": 1,
26+
"backgroundThreadIntervalMS": 50,
2627
"appName": "poolCreateMinSizeErrorTest"
2728
},
2829
"operations": [

test/cmap/wait-queue-timeout.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "must aggressively timeout threads enqueued longer than waitQueueTimeoutMS",
55
"poolOptions": {
66
"maxPoolSize": 1,
7-
"waitQueueTimeoutMS": 20
7+
"waitQueueTimeoutMS": 50
88
},
99
"operations": [
1010
{

test/test_cmap.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,13 @@ def run_scenario(self, scenario_def, test):
229229
opts['event_listeners'] = [self.listener]
230230
opts['_monitor_class'] = DummyMonitor
231231
opts['connect'] = False
232-
with client_knobs(kill_cursor_frequency=.05,
232+
# Support backgroundThreadIntervalMS, default to 50ms.
233+
interval = opts.pop('backgroundThreadIntervalMS', 50)
234+
if interval < 0:
235+
kill_cursor_frequency = 99999999
236+
else:
237+
kill_cursor_frequency = interval/1000.0
238+
with client_knobs(kill_cursor_frequency=kill_cursor_frequency,
233239
min_heartbeat_interval=.05):
234240
client = single_client(**opts)
235241
# Update the SD to a known type because the DummyMonitor will not.
@@ -242,7 +248,12 @@ def run_scenario(self, scenario_def, test):
242248
client_context.port)]
243249
client._topology._description = updated_topology_description(
244250
client._topology._description, sd)
245-
client._get_topology()
251+
# When backgroundThreadIntervalMS is negative we do not start the
252+
# background thread to ensure it never runs.
253+
if interval < 0:
254+
client._topology.open()
255+
else:
256+
client._get_topology()
246257
self.addCleanup(client.close)
247258
self.pool = list(client._topology._servers.values())[0].pool
248259

0 commit comments

Comments
 (0)