Skip to content

Commit 4726c3c

Browse files
committed
Fix failures
1 parent 58ca6f0 commit 4726c3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+94
-190
lines changed

test/asynchronous/test_async_cancellation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import asyncio
1919
import sys
20-
from test.utils_shared import async_get_pool, delay, one
20+
from test.asynchronous.utils import async_get_pool
21+
from test.utils_shared import delay, one
2122

2223
sys.path[0:0] = [""]
2324

test/asynchronous/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
)
6262
from test.asynchronous.pymongo_mocks import AsyncMockClient
6363
from test.asynchronous.utils import (
64-
AsyncFunctionCallRecorder,
6564
async_get_pool,
6665
async_wait_until,
6766
asyncAssertRaisesExactly,
@@ -70,6 +69,7 @@
7069
from test.utils_shared import (
7170
NTHREADS,
7271
CMAPListener,
72+
FunctionCallRecorder,
7373
delay,
7474
gevent_monkey_patched,
7575
is_greenthread_patched,
@@ -513,7 +513,7 @@ async def test_connection_timeout_ms_propagates_to_DNS_resolver(self):
513513
# Patch the resolver.
514514
from pymongo.srv_resolver import _resolve
515515

516-
patched_resolver = AsyncFunctionCallRecorder(_resolve)
516+
patched_resolver = FunctionCallRecorder(_resolve)
517517
pymongo.srv_resolver._resolve = patched_resolver
518518

519519
def reset_resolver():

test/asynchronous/test_collection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sys
2222
from codecs import utf_8_decode
2323
from collections import defaultdict
24+
from test.asynchronous.utils import async_get_pool, async_is_mongos
2425
from typing import Any, Iterable, no_type_check
2526

2627
from pymongo.asynchronous.database import AsyncDatabase
@@ -37,8 +38,6 @@
3738
IMPOSSIBLE_WRITE_CONCERN,
3839
EventListener,
3940
OvertCommandListener,
40-
async_get_pool,
41-
async_is_mongos,
4241
async_wait_until,
4342
)
4443

test/asynchronous/test_connection_monitoring.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
import sys
2121
import time
2222
from pathlib import Path
23+
from test.asynchronous.utils import async_get_pool, async_get_pools
2324

2425
sys.path[0:0] = [""]
2526

26-
from test.asynchronous import AsyncIntegrationTest, client_knobs, unittest
27+
from test.asynchronous import AsyncIntegrationTest, async_client_context, client_knobs, unittest
2728
from test.asynchronous.pymongo_mocks import DummyMonitor
2829
from test.asynchronous.utils_spec_runner import AsyncSpecTestCreator, SpecRunnerTask
2930
from test.utils_shared import (
3031
CMAPListener,
31-
async_client_context,
32-
async_get_pool,
33-
async_get_pools,
3432
async_wait_until,
3533
camel_to_snake,
3634
)

test/asynchronous/test_connections_survive_primary_stepdown_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import annotations
1717

1818
import sys
19+
from test.asynchronous.utils import async_ensure_all_connected
1920

2021
sys.path[0:0] = [""]
2122

@@ -27,7 +28,6 @@
2728
from test.asynchronous.helpers import async_repl_set_step_down
2829
from test.utils_shared import (
2930
CMAPListener,
30-
async_ensure_all_connected,
3131
)
3232

3333
from bson import SON

test/asynchronous/test_gridfs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
sys.path[0:0] = [""]
2929

3030
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
31-
from test.utils_shared import async_joinall, one
31+
from test.asynchronous.utils import async_joinall
32+
from test.utils_shared import one
3233

3334
import gridfs
3435
from bson.binary import Binary

test/asynchronous/test_gridfs_bucket.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
sys.path[0:0] = [""]
3030

3131
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
32-
from test.utils_shared import async_joinall, joinall, one
32+
from test.asynchronous.utils import async_joinall
33+
from test.utils_shared import one
3334

3435
import gridfs
3536
from bson.binary import Binary

test/asynchronous/test_heartbeat_monitoring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
from __future__ import annotations
1717

1818
import sys
19+
from test.asynchronous.utils import AsyncMockPool
1920

2021
sys.path[0:0] = [""]
2122

2223
from test.asynchronous import AsyncIntegrationTest, client_knobs, unittest
23-
from test.utils_shared import AsyncMockPool, HeartbeatEventListener, async_wait_until
24+
from test.utils_shared import HeartbeatEventListener, async_wait_until
2425

2526
from pymongo.asynchronous.monitor import Monitor
2627
from pymongo.errors import ConnectionFailure

test/asynchronous/test_load_balancer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import threading
2424
from asyncio import Event
2525
from test.asynchronous.helpers import ConcurrentRunner, ExceptionCatchingTask
26+
from test.asynchronous.utils import async_get_pool
2627

2728
import pytest
2829

@@ -31,7 +32,6 @@
3132
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
3233
from test.asynchronous.unified_format import generate_test_classes
3334
from test.utils_shared import (
34-
async_get_pool,
3535
async_wait_until,
3636
create_async_event,
3737
)

test/asynchronous/test_max_staleness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
sys.path[0:0] = [""]
2929

3030
from test.asynchronous import AsyncPyMongoTestCase, async_client_context, unittest
31-
from test.utils_shared_selection_tests import create_selection_tests
31+
from test.asynchronous.utils_selection_tests import create_selection_tests
3232

3333
from pymongo.errors import ConfigurationError
3434
from pymongo.server_selectors import writable_server_selector

test/asynchronous/test_pooling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import socket
2222
import sys
2323
import time
24+
from test.asynchronous.utils import async_get_pool, async_joinall
2425

2526
from bson.codec_options import DEFAULT_CODEC_OPTIONS
2627
from bson.son import SON
@@ -33,7 +34,7 @@
3334

3435
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
3536
from test.asynchronous.helpers import ConcurrentRunner
36-
from test.utils_shared import async_get_pool, async_joinall, delay
37+
from test.utils_shared import delay
3738

3839
from pymongo.asynchronous.pool import Pool, PoolOptions
3940
from pymongo.socket_checker import SocketChecker

test/asynchronous/test_retryable_reads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pprint
2020
import sys
2121
import threading
22+
from test.asynchronous.utils import async_set_fail_point
2223

2324
from pymongo.errors import AutoReconnect
2425

@@ -34,7 +35,6 @@
3435
from test.utils_shared import (
3536
CMAPListener,
3637
OvertCommandListener,
37-
async_set_fail_point,
3838
)
3939

4040
from pymongo.monitoring import (

test/asynchronous/test_retryable_writes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import pprint
2121
import sys
2222
import threading
23+
from test.asynchronous.utils import async_set_fail_point
2324

2425
sys.path[0:0] = [""]
2526

@@ -35,7 +36,6 @@
3536
DeprecationFilter,
3637
EventListener,
3738
OvertCommandListener,
38-
async_set_fail_point,
3939
)
4040
from test.version import Version
4141

test/asynchronous/test_server_selection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
sys.path[0:0] = [""]
3232

3333
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
34-
from test.asynchronous.utils import AsyncFunctionCallRecorder, async_wait_until
34+
from test.asynchronous.utils import async_wait_until
3535
from test.asynchronous.utils_selection_tests import (
3636
create_selection_tests,
3737
get_topology_settings_dict,
@@ -41,6 +41,7 @@
4141
make_server_description,
4242
)
4343
from test.utils_shared import (
44+
FunctionCallRecorder,
4445
OvertCommandListener,
4546
)
4647

@@ -122,7 +123,7 @@ async def test_invalid_server_selector(self):
122123

123124
@async_client_context.require_replica_set
124125
async def test_selector_called(self):
125-
selector = AsyncFunctionCallRecorder(lambda x: x)
126+
selector = FunctionCallRecorder(lambda x: x)
126127

127128
# Client setup.
128129
mongo_client = await self.async_rs_or_single_client(server_selector=selector)
@@ -175,7 +176,7 @@ async def test_latency_threshold_application(self):
175176

176177
@async_client_context.require_replica_set
177178
async def test_server_selector_bypassed(self):
178-
selector = AsyncFunctionCallRecorder(lambda x: x)
179+
selector = FunctionCallRecorder(lambda x: x)
179180

180181
scenario_def = {
181182
"topology_description": {

test/asynchronous/test_server_selection_in_window.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from test.utils_shared import (
2727
CMAPListener,
2828
OvertCommandListener,
29-
async_get_pool,
3029
async_wait_until,
3130
)
3231

test/asynchronous/test_srv_polling.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
import asyncio
1919
import sys
2020
import time
21+
from test.utils_shared import FunctionCallRecorder
2122
from typing import Any
2223

2324
sys.path[0:0] = [""]
2425

2526
from test.asynchronous import AsyncPyMongoTestCase, client_knobs, unittest
26-
from test.asynchronous.utils import AsyncFunctionCallRecorder, async_wait_until
27+
from test.asynchronous.utils import async_wait_until
2728

2829
import pymongo
2930
from pymongo import common
@@ -69,7 +70,7 @@ def mock_get_hosts_and_min_ttl(resolver, *args):
6970

7071
patch_func: Any
7172
if self.count_resolver_calls:
72-
patch_func = AsyncFunctionCallRecorder(mock_get_hosts_and_min_ttl)
73+
patch_func = FunctionCallRecorder(mock_get_hosts_and_min_ttl)
7374
else:
7475
patch_func = mock_get_hosts_and_min_ttl
7576

test/asynchronous/unified_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
client_knobs,
3636
unittest,
3737
)
38+
from test.asynchronous.utils import async_get_pool
3839
from test.asynchronous.utils_spec_runner import SpecRunnerTask
3940
from test.unified_format_shared import (
4041
KMS_TLS_OPTS,
@@ -50,7 +51,6 @@
5051
with_metaclass,
5152
)
5253
from test.utils_shared import (
53-
async_get_pool,
5454
async_wait_until,
5555
camel_to_snake,
5656
camel_to_snake_args,

test/asynchronous/utils.py

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,57 +17,19 @@
1717

1818
import asyncio
1919
import contextlib
20-
import copy
21-
import functools
22-
import os
2320
import random
24-
import re
25-
import shutil
26-
import sys
27-
import threading
2821
import time
29-
import unittest
30-
import warnings
3122
from asyncio import iscoroutinefunction
32-
from collections import abc, defaultdict
33-
from functools import partial
34-
from test import client_context, db_pwd, db_user
35-
from test.asynchronous import async_client_context
36-
from typing import Any, List
37-
38-
from bson import json_util
39-
from bson.objectid import ObjectId
23+
4024
from bson.son import SON
41-
from pymongo import AsyncMongoClient, monitoring, operations, read_preferences
42-
from pymongo._asyncio_task import create_task
43-
from pymongo.cursor_shared import CursorType
44-
from pymongo.errors import ConfigurationError, OperationFailure
25+
from pymongo import AsyncMongoClient
26+
from pymongo.errors import ConfigurationError
4527
from pymongo.hello import HelloCompat
46-
from pymongo.helpers_shared import _SENSITIVE_COMMANDS
47-
from pymongo.lock import _async_create_lock, _create_lock
48-
from pymongo.monitoring import (
49-
ConnectionCheckedInEvent,
50-
ConnectionCheckedOutEvent,
51-
ConnectionCheckOutFailedEvent,
52-
ConnectionCheckOutStartedEvent,
53-
ConnectionClosedEvent,
54-
ConnectionCreatedEvent,
55-
ConnectionReadyEvent,
56-
PoolClearedEvent,
57-
PoolClosedEvent,
58-
PoolCreatedEvent,
59-
PoolReadyEvent,
60-
)
28+
from pymongo.lock import _async_create_lock
6129
from pymongo.operations import _Op
62-
from pymongo.read_concern import ReadConcern
6330
from pymongo.read_preferences import ReadPreference
6431
from pymongo.server_selectors import any_server_selector, writable_server_selector
65-
from pymongo.server_type import SERVER_TYPE
66-
from pymongo.synchronous.collection import ReturnDocument
67-
from pymongo.synchronous.mongo_client import MongoClient
6832
from pymongo.synchronous.pool import _CancellationContext, _PoolGeneration
69-
from pymongo.uri_parser import parse_uri
70-
from pymongo.write_concern import WriteConcern
7133

7234
_IS_SYNC = False
7335

@@ -246,31 +208,3 @@ async def update_is_writable(self, is_writable):
246208

247209
async def remove_stale_sockets(self, *args, **kwargs):
248210
pass
249-
250-
251-
class AsyncFunctionCallRecorder:
252-
"""Utility class to wrap a callable and record its invocations."""
253-
254-
def __init__(self, function):
255-
self._function = function
256-
self._call_list = []
257-
258-
async def __call__(self, *args, **kwargs):
259-
self._call_list.append((args, kwargs))
260-
if iscoroutinefunction(self._function):
261-
return await self._function(*args, **kwargs)
262-
else:
263-
return self._function(*args, **kwargs)
264-
265-
def reset(self):
266-
"""Wipes the call list."""
267-
self._call_list = []
268-
269-
def call_list(self):
270-
"""Returns a copy of the call list."""
271-
return self._call_list[:]
272-
273-
@property
274-
def call_count(self):
275-
"""Returns the number of times the function has been called."""
276-
return len(self._call_list)

test/asynchronous/utils_selection_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
import os
2020
import sys
2121
from test.asynchronous import AsyncPyMongoTestCase
22+
from test.asynchronous.utils import AsyncMockPool
2223

2324
sys.path[0:0] = [""]
2425

2526
from test import unittest
2627
from test.pymongo_mocks import DummyMonitor
27-
from test.utils_shared import AsyncMockPool, parse_read_preference
28-
from test.utils_shared_selection_tests_shared import (
28+
from test.utils_selection_tests_shared import (
2929
get_addresses,
3030
get_topology_type_name,
3131
make_server_description,
3232
)
33+
from test.utils_shared import parse_read_preference
3334

3435
from bson import json_util
3536
from pymongo.asynchronous.settings import TopologySettings

0 commit comments

Comments
 (0)