Skip to content

Commit f0bb7c8

Browse files
committed
address review comments
1 parent fadef89 commit f0bb7c8

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

test/asynchronous/test_connection_monitoring.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import annotations
1717

1818
import os
19+
import pathlib
1920
import sys
2021
import time
2122

@@ -83,7 +84,12 @@
8384

8485
class AsyncTestCMAP(AsyncIntegrationTest):
8586
# 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+
)
8793

8894
# Test operations:
8995

@@ -128,7 +134,7 @@ def check_out(self, op):
128134
if label:
129135
self.labels[label] = conn
130136
else:
131-
self.addAsyncCleanup(conn.aclose_conn, None)
137+
self.addAsyncCleanup(conn.close_conn, None)
132138

133139
def check_in(self, op):
134140
"""Run the 'checkIn' operation."""
@@ -260,7 +266,6 @@ async def run_scenario(self, scenario_def, test):
260266
client._topology.open()
261267
else:
262268
client._get_topology()
263-
self.addAsyncCleanup(client.close)
264269
self.pool = list(client._topology._servers.values())[0].pool
265270

266271
# Map of target names to Thread objects.
@@ -317,13 +322,11 @@ async def cleanup():
317322
#
318323
async def test_1_client_connection_pool_options(self):
319324
client = await self.async_rs_or_single_client(**self.POOL_OPTIONS)
320-
self.addAsyncCleanup(client.close)
321325
pool_opts = (await async_get_pool(client)).opts
322326
self.assertEqual(pool_opts.non_default_options, self.POOL_OPTIONS)
323327

324328
async def test_2_all_client_pools_have_same_options(self):
325329
client = await self.async_rs_or_single_client(**self.POOL_OPTIONS)
326-
self.addAsyncCleanup(client.close)
327330
await client.admin.command("ping")
328331
# Discover at least one secondary.
329332
if await async_client_context.has_secondaries:
@@ -339,14 +342,12 @@ async def test_3_uri_connection_pool_options(self):
339342
opts = "&".join([f"{k}={v}" for k, v in self.POOL_OPTIONS.items()])
340343
uri = f"mongodb://{await async_client_context.pair}/?{opts}"
341344
client = await self.async_rs_or_single_client(uri)
342-
self.addAsyncCleanup(client.close)
343345
pool_opts = (await async_get_pool(client)).opts
344346
self.assertEqual(pool_opts.non_default_options, self.POOL_OPTIONS)
345347

346348
async def test_4_subscribe_to_events(self):
347349
listener = CMAPListener()
348350
client = await self.async_single_client(event_listeners=[listener])
349-
self.addAsyncCleanup(client.close)
350351
self.assertEqual(listener.event_count(PoolCreatedEvent), 1)
351352

352353
# Creates a new connection.
@@ -370,7 +371,6 @@ async def test_4_subscribe_to_events(self):
370371
async def test_5_check_out_fails_connection_error(self):
371372
listener = CMAPListener()
372373
client = await self.async_single_client(event_listeners=[listener])
373-
self.addAsyncCleanup(client.close)
374374
pool = await async_get_pool(client)
375375

376376
def mock_connect(*args, **kwargs):
@@ -399,7 +399,6 @@ async def test_5_check_out_fails_auth_error(self):
399399
client = await self.async_single_client_noauth(
400400
username="notauser", password="fail", event_listeners=[listener]
401401
)
402-
self.addAsyncCleanup(client.close)
403402

404403
# Attempt to create a new connection.
405404
with self.assertRaisesRegex(OperationFailure, "failed"):
@@ -471,8 +470,9 @@ async def tests(self, scenario_def):
471470
return [scenario_def]
472471

473472

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()
476476

477477

478478
if __name__ == "__main__":

test/test_connection_monitoring.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import annotations
1717

1818
import os
19+
import pathlib
1920
import sys
2021
import time
2122

@@ -83,7 +84,12 @@
8384

8485
class TestCMAP(IntegrationTest):
8586
# 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+
)
8793

8894
# Test operations:
8995

@@ -260,7 +266,6 @@ def run_scenario(self, scenario_def, test):
260266
client._topology.open()
261267
else:
262268
client._get_topology()
263-
self.addCleanup(client.close)
264269
self.pool = list(client._topology._servers.values())[0].pool
265270

266271
# Map of target names to Thread objects.
@@ -317,13 +322,11 @@ def cleanup():
317322
#
318323
def test_1_client_connection_pool_options(self):
319324
client = self.rs_or_single_client(**self.POOL_OPTIONS)
320-
self.addCleanup(client.close)
321325
pool_opts = (get_pool(client)).opts
322326
self.assertEqual(pool_opts.non_default_options, self.POOL_OPTIONS)
323327

324328
def test_2_all_client_pools_have_same_options(self):
325329
client = self.rs_or_single_client(**self.POOL_OPTIONS)
326-
self.addCleanup(client.close)
327330
client.admin.command("ping")
328331
# Discover at least one secondary.
329332
if client_context.has_secondaries:
@@ -339,14 +342,12 @@ def test_3_uri_connection_pool_options(self):
339342
opts = "&".join([f"{k}={v}" for k, v in self.POOL_OPTIONS.items()])
340343
uri = f"mongodb://{client_context.pair}/?{opts}"
341344
client = self.rs_or_single_client(uri)
342-
self.addCleanup(client.close)
343345
pool_opts = (get_pool(client)).opts
344346
self.assertEqual(pool_opts.non_default_options, self.POOL_OPTIONS)
345347

346348
def test_4_subscribe_to_events(self):
347349
listener = CMAPListener()
348350
client = self.single_client(event_listeners=[listener])
349-
self.addCleanup(client.close)
350351
self.assertEqual(listener.event_count(PoolCreatedEvent), 1)
351352

352353
# Creates a new connection.
@@ -370,7 +371,6 @@ def test_4_subscribe_to_events(self):
370371
def test_5_check_out_fails_connection_error(self):
371372
listener = CMAPListener()
372373
client = self.single_client(event_listeners=[listener])
373-
self.addCleanup(client.close)
374374
pool = get_pool(client)
375375

376376
def mock_connect(*args, **kwargs):
@@ -399,7 +399,6 @@ def test_5_check_out_fails_auth_error(self):
399399
client = self.single_client_noauth(
400400
username="notauser", password="fail", event_listeners=[listener]
401401
)
402-
self.addCleanup(client.close)
403402

404403
# Attempt to create a new connection.
405404
with self.assertRaisesRegex(OperationFailure, "failed"):
@@ -471,8 +470,9 @@ def tests(self, scenario_def):
471470
return [scenario_def]
472471

473472

474-
test_creator = CMAPSpecTestCreator(create_test, TestCMAP, TestCMAP.TEST_PATH)
475-
test_creator.create_tests()
473+
if _IS_SYNC:
474+
test_creator = CMAPSpecTestCreator(create_test, TestCMAP, TestCMAP.TEST_PATH)
475+
test_creator.create_tests()
476476

477477

478478
if __name__ == "__main__":

0 commit comments

Comments
 (0)