Skip to content

Commit 36d4490

Browse files
committed
fix tests
1 parent d6d43e7 commit 36d4490

File tree

7 files changed

+21
-18
lines changed

7 files changed

+21
-18
lines changed

pymongo/asynchronous/pool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,8 +1355,9 @@ async def _get_conn(
13551355
timeout = 0.01
13561356
if not await _async_cond_wait(self._max_connecting_cond, timeout):
13571357
# Check whether we should continue to wait for the backoff condition.
1358-
if self._backoff and (deadline is None or deadline < time.monotonic()):
1359-
if self._backoff_connection_time > time.monotonic():
1358+
curr_time = time.monotonic()
1359+
if self._backoff and (deadline is None or curr_time < deadline):
1360+
if self._backoff_connection_time > curr_time:
13601361
continue
13611362
break
13621363
# Timed out, notify the next thread to ensure a

pymongo/synchronous/pool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,9 @@ def _get_conn(
13531353
timeout = 0.01
13541354
if not _cond_wait(self._max_connecting_cond, timeout):
13551355
# Check whether we should continue to wait for the backoff condition.
1356-
if self._backoff and (deadline is None or deadline < time.monotonic()):
1357-
if self._backoff_connection_time > time.monotonic():
1356+
curr_time = time.monotonic()
1357+
if self._backoff and (deadline is None or curr_time < deadline):
1358+
if self._backoff_connection_time > curr_time:
13581359
continue
13591360
break
13601361
# Timed out, notify the next thread to ensure a

test/asynchronous/test_pooling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ async def test_connection_timeout_message(self):
517517
async def test_pool_check_backoff(self):
518518
# Test that Pool recovers from two connection failures in a row.
519519
# This exercises code at the end of Pool._check().
520-
cx_pool = await self.create_pool(max_pool_size=1, connect_timeout=1, wait_queue_timeout=1)
520+
cx_pool = await self.create_pool(max_pool_size=1, connect_timeout=1, wait_queue_timeout=10)
521521
self.addAsyncCleanup(cx_pool.close)
522522

523523
async with cx_pool.checkout() as conn:
@@ -526,7 +526,7 @@ async def test_pool_check_backoff(self):
526526
await conn.conn.close()
527527

528528
# Enable backoff.
529-
cx_pool.backoff()
529+
await cx_pool.backoff()
530530

531531
# Swap pool's address with a bad one.
532532
address, cx_pool.address = cx_pool.address, ("foo.com", 1234)

test/discovery_and_monitoring/unified/backoff-heartbeat-failure.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"observeEvents": [
5151
"commandStartedEvent",
5252
"poolBackoffEvent",
53-
"poolReadyEvent",
5453
"poolClearedEvent",
5554
"serverHeartbeatFailedEvent",
5655
"serverHeartbeatSucceededEvent"
@@ -143,9 +142,6 @@
143142
"client": "client",
144143
"eventType": "cmap",
145144
"events": [
146-
{
147-
"poolReadyEvent": {}
148-
},
149145
{
150146
"poolBackoffEvent": {}
151147
},

test/discovery_and_monitoring/unified/backoff-heartbeat-success.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"observeEvents": [
5151
"commandStartedEvent",
5252
"poolBackoffEvent",
53-
"poolReadyEvent",
5453
"poolClearedEvent",
5554
"serverHeartbeatFailedEvent",
5655
"serverHeartbeatSucceededEvent"
@@ -154,9 +153,6 @@
154153
"client": "client",
155154
"eventType": "cmap",
156155
"events": [
157-
{
158-
"poolReadyEvent": {}
159-
},
160156
{
161157
"poolBackoffEvent": {}
162158
},

test/discovery_and_monitoring/unified/backoff-network-error-fail.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@
202202
"client": "setupClient",
203203
"failPoint": {
204204
"configureFailPoint": "failCommand",
205-
"mode": {
206-
"times": 6
207-
},
205+
"mode": "always",
208206
"data": {
209207
"failCommands": [
210208
"isMaster",
@@ -244,6 +242,17 @@
244242
"count": 5
245243
}
246244
},
245+
{
246+
"name": "failPoint",
247+
"object": "testRunner",
248+
"arguments": {
249+
"client": "setupClient",
250+
"failPoint": {
251+
"configureFailPoint": "failCommand",
252+
"mode": "off"
253+
}
254+
}
255+
},
247256
{
248257
"name": "failPoint",
249258
"object": "testRunner",

test/test_pooling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def test_connection_timeout_message(self):
515515
def test_pool_check_backoff(self):
516516
# Test that Pool recovers from two connection failures in a row.
517517
# This exercises code at the end of Pool._check().
518-
cx_pool = self.create_pool(max_pool_size=1, connect_timeout=1, wait_queue_timeout=1)
518+
cx_pool = self.create_pool(max_pool_size=1, connect_timeout=1, wait_queue_timeout=10)
519519
self.addCleanup(cx_pool.close)
520520

521521
with cx_pool.checkout() as conn:

0 commit comments

Comments
 (0)