Skip to content

Commit 2dae369

Browse files
committed
Merge resolution
1 parent 31cde95 commit 2dae369

File tree

9 files changed

+47
-38
lines changed

9 files changed

+47
-38
lines changed

test/asynchronous/test_discovery_and_monitoring.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,32 @@
2626

2727
sys.path[0:0] = [""]
2828

29-
from test.asynchronous import AsyncIntegrationTest, AsyncPyMongoTestCase, AsyncUnitTest, unittest
29+
from test.asynchronous import (
30+
AsyncIntegrationTest,
31+
AsyncPyMongoTestCase,
32+
AsyncUnitTest,
33+
async_client_context,
34+
unittest,
35+
)
3036
from test.asynchronous.pymongo_mocks import DummyMonitor
3137
from test.asynchronous.unified_format import generate_test_classes
32-
from test.utils import (
38+
from test.asynchronous.utils import (
39+
async_get_pool,
40+
)
41+
from test.utils_shared import (
3342
CMAPListener,
3443
HeartbeatEventListener,
3544
HeartbeatEventsListListener,
3645
assertion_context,
3746
async_barrier_wait,
38-
async_client_context,
3947
async_create_barrier,
40-
async_get_pool,
4148
async_wait_until,
4249
server_name_to_type,
4350
)
4451
from unittest.mock import patch
4552

4653
from bson import Timestamp, json_util
47-
from pymongo import AsyncMongoClient, common, monitoring
54+
from pymongo import common, monitoring
4855
from pymongo.asynchronous.settings import TopologySettings
4956
from pymongo.asynchronous.topology import Topology, _ErrorContext
5057
from pymongo.errors import (
@@ -291,7 +298,7 @@ async def test_ignore_stale_connection_errors(self):
291298
if not _IS_SYNC and sys.version_info < (3, 11):
292299
self.skipTest("Test requires asyncio.Barrier (added in Python 3.11)")
293300
N_TASKS = 5
294-
barrier = async_create_barrier(N_TASKS, timeout=30)
301+
barrier = async_create_barrier(N_TASKS)
295302
client = await self.async_rs_or_single_client(minPoolSize=N_TASKS)
296303

297304
# Wait for initial discovery.

test/asynchronous/test_monitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
sys.path[0:0] = [""]
2626

2727
from test.asynchronous import AsyncIntegrationTest, async_client_context, connected, unittest
28-
from test.utils import (
29-
ServerAndTopologyEventListener,
28+
from test.asynchronous.utils import (
3029
async_wait_until,
3130
)
31+
from test.utils_shared import ServerAndTopologyEventListener
3232

3333
from pymongo.periodic_executor import _EXECUTORS
3434

test/asynchronous/test_session.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
from test.asynchronous import (
3232
AsyncIntegrationTest,
33-
AsyncPyMongoTestCase,
3433
AsyncUnitTest,
3534
SkipTest,
3635
async_client_context,

test/asynchronous/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import asyncio
1919
import contextlib
2020
import random
21+
import threading # Used in the synchronized version of this file
2122
import time
2223
from asyncio import iscoroutinefunction
2324

test/test_discovery_and_monitoring.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,38 @@
2020
import socketserver
2121
import sys
2222
import threading
23-
from test.utils import get_pool
2423
from asyncio import StreamReader, StreamWriter
2524
from pathlib import Path
2625
from test.helpers import ConcurrentRunner
2726

2827
sys.path[0:0] = [""]
2928

30-
from test import IntegrationTest, PyMongoTestCase, UnitTest, unittest
29+
from test import (
30+
IntegrationTest,
31+
PyMongoTestCase,
32+
UnitTest,
33+
client_context,
34+
unittest,
35+
)
3136
from test.pymongo_mocks import DummyMonitor
3237
from test.unified_format import generate_test_classes
38+
from test.utils import (
39+
get_pool,
40+
)
3341
from test.utils_shared import (
3442
CMAPListener,
3543
HeartbeatEventListener,
3644
HeartbeatEventsListListener,
3745
assertion_context,
3846
barrier_wait,
39-
client_context,
4047
create_barrier,
4148
server_name_to_type,
4249
wait_until,
4350
)
4451
from unittest.mock import patch
4552

4653
from bson import Timestamp, json_util
47-
from pymongo import MongoClient, common, monitoring
54+
from pymongo import common, monitoring
4855
from pymongo.errors import (
4956
AutoReconnect,
5057
ConfigurationError,
@@ -291,7 +298,7 @@ def test_ignore_stale_connection_errors(self):
291298
if not _IS_SYNC and sys.version_info < (3, 11):
292299
self.skipTest("Test requires asyncio.Barrier (added in Python 3.11)")
293300
N_TASKS = 5
294-
barrier = create_barrier(N_TASKS, timeout=30)
301+
barrier = create_barrier(N_TASKS)
295302
client = self.rs_or_single_client(minPoolSize=N_TASKS)
296303

297304
# Wait for initial discovery.

test/test_monitor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424

2525
sys.path[0:0] = [""]
2626

27-
from test import IntegrationTest, connected, unittest
28-
from test.utils_shared import (
2927
from test import IntegrationTest, client_context, connected, unittest
3028
from test.utils import (
31-
ServerAndTopologyEventListener,
3229
wait_until,
3330
)
31+
from test.utils_shared import ServerAndTopologyEventListener
3432

3533
from pymongo.periodic_executor import _EXECUTORS
3634

test/test_session.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@
3030

3131
from test import (
3232
IntegrationTest,
33-
PyMongoTestCase,
3433
SkipTest,
3534
UnitTest,
3635
client_context,
3736
unittest,
3837
)
39-
from test.utils_shared import (
4038
from test.helpers import client_knobs
41-
from test.utils import (
39+
from test.utils_shared import (
4240
EventListener,
4341
HeartbeatEventListener,
4442
OvertCommandListener,

test/utils.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import asyncio
1919
import contextlib
2020
import random
21+
import threading # Used in the synchronized version of this file
2122
import time
2223
from asyncio import iscoroutinefunction
2324

@@ -206,21 +207,3 @@ def update_is_writable(self, is_writable):
206207

207208
def remove_stale_sockets(self, *args, **kwargs):
208209
pass
209-
def create_event():
210-
return threading.Event()
211-
212-
213-
def async_create_barrier(N_TASKS, timeout: float | None = None):
214-
return asyncio.Barrier(N_TASKS)
215-
216-
217-
def create_barrier(N_TASKS, timeout: float | None = None):
218-
return threading.Barrier(N_TASKS, timeout=timeout)
219-
220-
221-
async def async_barrier_wait(barrier, timeout: float | None = None):
222-
await asyncio.wait_for(barrier.wait(), timeout=timeout)
223-
224-
225-
def barrier_wait(barrier, timeout: float | None = None):
226-
barrier.wait()

test/utils_shared.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,19 @@ def create_async_event():
687687

688688
def create_event():
689689
return threading.Event()
690+
691+
692+
def async_create_barrier(n_tasks: int):
693+
return asyncio.Barrier(n_tasks)
694+
695+
696+
def create_barrier(n_tasks: int, timeout: float | None = None):
697+
return threading.Barrier(n_tasks, timeout=timeout)
698+
699+
700+
async def async_barrier_wait(barrier, timeout: float | None = None):
701+
await asyncio.wait_for(barrier.wait(), timeout=timeout)
702+
703+
704+
def barrier_wait(barrier, timeout: float | None = None):
705+
barrier.wait(timeout=timeout)

0 commit comments

Comments
 (0)