Skip to content

Commit 8b66889

Browse files
authored
PYTHON-5208 Add spec test for wait queue timeout errors do not clear the pool (#2199)
Also stop running the ping command to advance session cluster times in the unified tests.
1 parent 5177e4e commit 8b66889

File tree

3 files changed

+190
-18
lines changed

3 files changed

+190
-18
lines changed

test/asynchronous/unified_format.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ def __init__(self, test_class):
222222
self._listeners: Dict[str, EventListenerUtil] = {}
223223
self._session_lsids: Dict[str, Mapping[str, Any]] = {}
224224
self.test: UnifiedSpecTestMixinV1 = test_class
225-
self._cluster_time: Mapping[str, Any] = {}
226225

227226
def __contains__(self, item):
228227
return item in self._entities
@@ -421,13 +420,11 @@ def get_lsid_for_session(self, session_name):
421420
# session has been closed.
422421
return self._session_lsids[session_name]
423422

424-
async def advance_cluster_times(self) -> None:
423+
async def advance_cluster_times(self, cluster_time) -> None:
425424
"""Manually synchronize entities when desired"""
426-
if not self._cluster_time:
427-
self._cluster_time = (await self.test.client.admin.command("ping")).get("$clusterTime")
428425
for entity in self._entities.values():
429-
if isinstance(entity, AsyncClientSession) and self._cluster_time:
430-
entity.advance_cluster_time(self._cluster_time)
426+
if isinstance(entity, AsyncClientSession) and cluster_time:
427+
entity.advance_cluster_time(cluster_time)
431428

432429

433430
class UnifiedSpecTestMixinV1(AsyncIntegrationTest):
@@ -1044,7 +1041,7 @@ async def _testOperation_targetedFailPoint(self, spec):
10441041

10451042
async def _testOperation_createEntities(self, spec):
10461043
await self.entity_map.create_entities_from_spec(spec["entities"], uri=self._uri)
1047-
await self.entity_map.advance_cluster_times()
1044+
await self.entity_map.advance_cluster_times(self._cluster_time)
10481045

10491046
def _testOperation_assertSessionTransactionState(self, spec):
10501047
session = self.entity_map[spec["session"]]
@@ -1443,11 +1440,12 @@ async def _run_scenario(self, spec, uri=None):
14431440
await self.entity_map.create_entities_from_spec(
14441441
self.TEST_SPEC.get("createEntities", []), uri=uri
14451442
)
1443+
self._cluster_time = None
14461444
# process initialData
14471445
if "initialData" in self.TEST_SPEC:
14481446
await self.insert_initial_data(self.TEST_SPEC["initialData"])
1449-
self._cluster_time = (await self.client.admin.command("ping")).get("$clusterTime")
1450-
await self.entity_map.advance_cluster_times()
1447+
self._cluster_time = self.client._topology.max_cluster_time()
1448+
await self.entity_map.advance_cluster_times(self._cluster_time)
14511449

14521450
if "expectLogMessages" in spec:
14531451
expect_log_messages = spec["expectLogMessages"]

test/csot/waitQueueTimeout.json

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
{
2+
"description": "WaitQueueTimeoutError does not clear the pool",
3+
"schemaVersion": "1.9",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "4.4",
7+
"topologies": [
8+
"single",
9+
"replicaset",
10+
"sharded"
11+
]
12+
}
13+
],
14+
"createEntities": [
15+
{
16+
"client": {
17+
"id": "failPointClient",
18+
"useMultipleMongoses": false
19+
}
20+
},
21+
{
22+
"client": {
23+
"id": "client",
24+
"uriOptions": {
25+
"maxPoolSize": 1,
26+
"appname": "waitQueueTimeoutErrorTest"
27+
},
28+
"useMultipleMongoses": false,
29+
"observeEvents": [
30+
"commandStartedEvent",
31+
"poolClearedEvent"
32+
]
33+
}
34+
},
35+
{
36+
"database": {
37+
"id": "database",
38+
"client": "client",
39+
"databaseName": "test"
40+
}
41+
}
42+
],
43+
"tests": [
44+
{
45+
"description": "WaitQueueTimeoutError does not clear the pool",
46+
"operations": [
47+
{
48+
"name": "failPoint",
49+
"object": "testRunner",
50+
"arguments": {
51+
"client": "failPointClient",
52+
"failPoint": {
53+
"configureFailPoint": "failCommand",
54+
"mode": {
55+
"times": 1
56+
},
57+
"data": {
58+
"failCommands": [
59+
"ping"
60+
],
61+
"blockConnection": true,
62+
"blockTimeMS": 500,
63+
"appName": "waitQueueTimeoutErrorTest"
64+
}
65+
}
66+
}
67+
},
68+
{
69+
"name": "createEntities",
70+
"object": "testRunner",
71+
"arguments": {
72+
"entities": [
73+
{
74+
"thread": {
75+
"id": "thread0"
76+
}
77+
}
78+
]
79+
}
80+
},
81+
{
82+
"name": "runOnThread",
83+
"object": "testRunner",
84+
"arguments": {
85+
"thread": "thread0",
86+
"operation": {
87+
"name": "runCommand",
88+
"object": "database",
89+
"arguments": {
90+
"command": {
91+
"ping": 1
92+
},
93+
"commandName": "ping"
94+
}
95+
}
96+
}
97+
},
98+
{
99+
"name": "waitForEvent",
100+
"object": "testRunner",
101+
"arguments": {
102+
"client": "client",
103+
"event": {
104+
"commandStartedEvent": {
105+
"commandName": "ping"
106+
}
107+
},
108+
"count": 1
109+
}
110+
},
111+
{
112+
"name": "runCommand",
113+
"object": "database",
114+
"arguments": {
115+
"timeoutMS": 100,
116+
"command": {
117+
"hello": 1
118+
},
119+
"commandName": "hello"
120+
},
121+
"expectError": {
122+
"isTimeoutError": true
123+
}
124+
},
125+
{
126+
"name": "waitForThread",
127+
"object": "testRunner",
128+
"arguments": {
129+
"thread": "thread0"
130+
}
131+
},
132+
{
133+
"name": "runCommand",
134+
"object": "database",
135+
"arguments": {
136+
"command": {
137+
"hello": 1
138+
},
139+
"commandName": "hello"
140+
}
141+
}
142+
],
143+
"expectEvents": [
144+
{
145+
"client": "client",
146+
"eventType": "command",
147+
"events": [
148+
{
149+
"commandStartedEvent": {
150+
"commandName": "ping",
151+
"databaseName": "test",
152+
"command": {
153+
"ping": 1
154+
}
155+
}
156+
},
157+
{
158+
"commandStartedEvent": {
159+
"commandName": "hello",
160+
"databaseName": "test",
161+
"command": {
162+
"hello": 1
163+
}
164+
}
165+
}
166+
]
167+
},
168+
{
169+
"client": "client",
170+
"eventType": "cmap",
171+
"events": []
172+
}
173+
]
174+
}
175+
]
176+
}

test/unified_format.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def __init__(self, test_class):
221221
self._listeners: Dict[str, EventListenerUtil] = {}
222222
self._session_lsids: Dict[str, Mapping[str, Any]] = {}
223223
self.test: UnifiedSpecTestMixinV1 = test_class
224-
self._cluster_time: Mapping[str, Any] = {}
225224

226225
def __contains__(self, item):
227226
return item in self._entities
@@ -420,13 +419,11 @@ def get_lsid_for_session(self, session_name):
420419
# session has been closed.
421420
return self._session_lsids[session_name]
422421

423-
def advance_cluster_times(self) -> None:
422+
def advance_cluster_times(self, cluster_time) -> None:
424423
"""Manually synchronize entities when desired"""
425-
if not self._cluster_time:
426-
self._cluster_time = (self.test.client.admin.command("ping")).get("$clusterTime")
427424
for entity in self._entities.values():
428-
if isinstance(entity, ClientSession) and self._cluster_time:
429-
entity.advance_cluster_time(self._cluster_time)
425+
if isinstance(entity, ClientSession) and cluster_time:
426+
entity.advance_cluster_time(cluster_time)
430427

431428

432429
class UnifiedSpecTestMixinV1(IntegrationTest):
@@ -1035,7 +1032,7 @@ def _testOperation_targetedFailPoint(self, spec):
10351032

10361033
def _testOperation_createEntities(self, spec):
10371034
self.entity_map.create_entities_from_spec(spec["entities"], uri=self._uri)
1038-
self.entity_map.advance_cluster_times()
1035+
self.entity_map.advance_cluster_times(self._cluster_time)
10391036

10401037
def _testOperation_assertSessionTransactionState(self, spec):
10411038
session = self.entity_map[spec["session"]]
@@ -1428,11 +1425,12 @@ def _run_scenario(self, spec, uri=None):
14281425
self._uri = uri
14291426
self.entity_map = EntityMapUtil(self)
14301427
self.entity_map.create_entities_from_spec(self.TEST_SPEC.get("createEntities", []), uri=uri)
1428+
self._cluster_time = None
14311429
# process initialData
14321430
if "initialData" in self.TEST_SPEC:
14331431
self.insert_initial_data(self.TEST_SPEC["initialData"])
1434-
self._cluster_time = (self.client.admin.command("ping")).get("$clusterTime")
1435-
self.entity_map.advance_cluster_times()
1432+
self._cluster_time = self.client._topology.max_cluster_time()
1433+
self.entity_map.advance_cluster_times(self._cluster_time)
14361434

14371435
if "expectLogMessages" in spec:
14381436
expect_log_messages = spec["expectLogMessages"]

0 commit comments

Comments
 (0)