3131)
3232from test .utils import (
3333 EventListener ,
34+ OvertCommandListener ,
3435 async_wait_until ,
3536)
3637
@@ -54,7 +55,7 @@ class AsyncTestCommandMonitoring(AsyncIntegrationTest):
5455 @async_client_context .require_connection
5556 async def _setup_class (cls ):
5657 await super ()._setup_class ()
57- cls .listener = EventListener ()
58+ cls .listener = OvertCommandListener ()
5859 cls .client = await cls .unmanaged_async_rs_or_single_client (
5960 event_listeners = [cls .listener ], retryWrites = False
6061 )
@@ -1100,11 +1101,13 @@ async def test_first_batch_helper(self):
11001101
11011102 @async_client_context .require_version_max (6 , 1 , 99 )
11021103 async def test_sensitive_commands (self ):
1103- listeners = self .client ._event_listeners
1104+ listener = EventListener ()
1105+ client = await self .async_rs_or_single_client (event_listeners = [listener ])
1106+ listeners = client ._event_listeners
11041107
1105- self . listener .reset ()
1108+ listener .reset ()
11061109 cmd = SON ([("getnonce" , 1 )])
1107- listeners .publish_command_start (cmd , "pymongo_test" , 12345 , await self . client .address , None ) # type: ignore[arg-type]
1110+ listeners .publish_command_start (cmd , "pymongo_test" , 12345 , await client .address , None ) # type: ignore[arg-type]
11081111 delta = datetime .timedelta (milliseconds = 100 )
11091112 listeners .publish_command_success (
11101113 delta ,
@@ -1115,15 +1118,15 @@ async def test_sensitive_commands(self):
11151118 None ,
11161119 database_name = "pymongo_test" ,
11171120 )
1118- started = self . listener .started_events [0 ]
1119- succeeded = self . listener .succeeded_events [0 ]
1120- self .assertEqual (0 , len (self . listener .failed_events ))
1121+ started = listener .started_events [0 ]
1122+ succeeded = listener .succeeded_events [0 ]
1123+ self .assertEqual (0 , len (listener .failed_events ))
11211124 self .assertIsInstance (started , monitoring .CommandStartedEvent )
11221125 self .assertEqual ({}, started .command )
11231126 self .assertEqual ("pymongo_test" , started .database_name )
11241127 self .assertEqual ("getnonce" , started .command_name )
11251128 self .assertIsInstance (started .request_id , int )
1126- self .assertEqual (await self . client .address , started .connection_id )
1129+ self .assertEqual (await client .address , started .connection_id )
11271130 self .assertIsInstance (succeeded , monitoring .CommandSucceededEvent )
11281131 self .assertEqual (succeeded .duration_micros , 100000 )
11291132 self .assertEqual (started .command_name , succeeded .command_name )
@@ -1140,7 +1143,7 @@ class AsyncTestGlobalListener(AsyncIntegrationTest):
11401143 @async_client_context .require_connection
11411144 async def _setup_class (cls ):
11421145 await super ()._setup_class ()
1143- cls .listener = EventListener ()
1146+ cls .listener = OvertCommandListener ()
11441147 # We plan to call register(), which internally modifies _LISTENERS.
11451148 cls .saved_listeners = copy .deepcopy (monitoring ._LISTENERS )
11461149 monitoring .register (cls .listener )
0 commit comments