16
16
from __future__ import annotations
17
17
18
18
import os
19
+ import pathlib
19
20
import sys
20
21
import time
21
22
83
84
84
85
class AsyncTestCMAP (AsyncIntegrationTest ):
85
86
# Location of JSON test specifications.
86
- TEST_PATH = os .path .join (os .path .dirname (os .path .realpath (__file__ )), "connection_monitoring" )
87
+ if _IS_SYNC :
88
+ _TEST_PATH = os .path .join (pathlib .Path (__file__ ).resolve ().parent , "connection_monitoring" )
89
+ else :
90
+ _TEST_PATH = os .path .join (
91
+ pathlib .Path (__file__ ).resolve ().parent .parent , "connection_monitoring"
92
+ )
87
93
88
94
# Test operations:
89
95
@@ -128,7 +134,7 @@ def check_out(self, op):
128
134
if label :
129
135
self .labels [label ] = conn
130
136
else :
131
- self .addAsyncCleanup (conn .aclose_conn , None )
137
+ self .addAsyncCleanup (conn .close_conn , None )
132
138
133
139
def check_in (self , op ):
134
140
"""Run the 'checkIn' operation."""
@@ -260,7 +266,6 @@ async def run_scenario(self, scenario_def, test):
260
266
client ._topology .open ()
261
267
else :
262
268
client ._get_topology ()
263
- self .addAsyncCleanup (client .close )
264
269
self .pool = list (client ._topology ._servers .values ())[0 ].pool
265
270
266
271
# Map of target names to Thread objects.
@@ -317,13 +322,11 @@ async def cleanup():
317
322
#
318
323
async def test_1_client_connection_pool_options (self ):
319
324
client = await self .async_rs_or_single_client (** self .POOL_OPTIONS )
320
- self .addAsyncCleanup (client .close )
321
325
pool_opts = (await async_get_pool (client )).opts
322
326
self .assertEqual (pool_opts .non_default_options , self .POOL_OPTIONS )
323
327
324
328
async def test_2_all_client_pools_have_same_options (self ):
325
329
client = await self .async_rs_or_single_client (** self .POOL_OPTIONS )
326
- self .addAsyncCleanup (client .close )
327
330
await client .admin .command ("ping" )
328
331
# Discover at least one secondary.
329
332
if await async_client_context .has_secondaries :
@@ -339,14 +342,12 @@ async def test_3_uri_connection_pool_options(self):
339
342
opts = "&" .join ([f"{ k } ={ v } " for k , v in self .POOL_OPTIONS .items ()])
340
343
uri = f"mongodb://{ await async_client_context .pair } /?{ opts } "
341
344
client = await self .async_rs_or_single_client (uri )
342
- self .addAsyncCleanup (client .close )
343
345
pool_opts = (await async_get_pool (client )).opts
344
346
self .assertEqual (pool_opts .non_default_options , self .POOL_OPTIONS )
345
347
346
348
async def test_4_subscribe_to_events (self ):
347
349
listener = CMAPListener ()
348
350
client = await self .async_single_client (event_listeners = [listener ])
349
- self .addAsyncCleanup (client .close )
350
351
self .assertEqual (listener .event_count (PoolCreatedEvent ), 1 )
351
352
352
353
# Creates a new connection.
@@ -370,7 +371,6 @@ async def test_4_subscribe_to_events(self):
370
371
async def test_5_check_out_fails_connection_error (self ):
371
372
listener = CMAPListener ()
372
373
client = await self .async_single_client (event_listeners = [listener ])
373
- self .addAsyncCleanup (client .close )
374
374
pool = await async_get_pool (client )
375
375
376
376
def mock_connect (* args , ** kwargs ):
@@ -399,7 +399,6 @@ async def test_5_check_out_fails_auth_error(self):
399
399
client = await self .async_single_client_noauth (
400
400
username = "notauser" , password = "fail" , event_listeners = [listener ]
401
401
)
402
- self .addAsyncCleanup (client .close )
403
402
404
403
# Attempt to create a new connection.
405
404
with self .assertRaisesRegex (OperationFailure , "failed" ):
@@ -471,8 +470,9 @@ async def tests(self, scenario_def):
471
470
return [scenario_def ]
472
471
473
472
474
- test_creator = CMAPSpecTestCreator (create_test , AsyncTestCMAP , AsyncTestCMAP .TEST_PATH )
475
- test_creator .create_tests ()
473
+ if _IS_SYNC :
474
+ test_creator = CMAPSpecTestCreator (create_test , AsyncTestCMAP , AsyncTestCMAP .TEST_PATH )
475
+ test_creator .create_tests ()
476
476
477
477
478
478
if __name__ == "__main__" :
0 commit comments