@@ -60,13 +60,6 @@ def setUp(self):
6060 self .mock_stub .GetMetadata = Mock (return_value = self .mock_metadata )
6161 self .grpc_watcher .stub = self .mock_stub
6262 self .grpc_watcher .active = True
63- self .shutdown_thread = lambda : threading .Thread (
64- target = self .shutdown_after_x_seconds
65- )
66-
67- def shutdown_after_x_seconds (self , seconds = 1 ):
68- time .sleep (seconds )
69- self .grpc_watcher .shutdown ()
7063
7164 def test_listen_with_sync_metadata_and_sync_context (self ):
7265 sync_context = Struct ()
@@ -81,9 +74,12 @@ def test_listen_with_sync_metadata_and_sync_context(self):
8174 )
8275 self .mock_stub .SyncFlags = Mock (return_value = mock_stream_with_sync_context )
8376
84- self .shutdown_thread ().start ()
77+ listener = threading .Thread (target = self .grpc_watcher .listen )
78+ listener .start ()
8579
86- self .grpc_watcher .listen ()
80+ time .sleep (0.5 )
81+ self .grpc_watcher .shutdown ()
82+ listener .join (timeout = 1 )
8783
8884 self .emit_provider_ready .assert_called_once_with (
8985 ProviderEventDetails (message = "gRPC sync connection established" ),
@@ -98,9 +94,12 @@ def test_listen_with_sync_metadata_only(self):
9894 )
9995 self .mock_stub .SyncFlags = Mock (return_value = mock_stream_no_sync_context )
10096
101- self .shutdown_thread ().start ()
97+ listener = threading .Thread (target = self .grpc_watcher .listen )
98+ listener .start ()
10299
103- self .grpc_watcher .listen ()
100+ time .sleep (0.5 )
101+ self .grpc_watcher .shutdown ()
102+ listener .join (timeout = 1 )
104103
105104 self .emit_provider_ready .assert_called_once_with (
106105 ProviderEventDetails (message = "gRPC sync connection established" ),
@@ -115,9 +114,13 @@ def test_listen_with_sync_metadata_disabled_in_config(self):
115114 ]
116115 )
117116 self .mock_stub .SyncFlags = Mock (return_value = mock_stream_no_sync_context )
118- self .shutdown_thread ().start ()
119117
120- self .grpc_watcher .listen ()
118+ listener = threading .Thread (target = self .grpc_watcher .listen )
119+ listener .start ()
120+
121+ time .sleep (0.5 )
122+ self .grpc_watcher .shutdown ()
123+ listener .join (timeout = 1 )
121124
122125 self .mock_stub .GetMetadata .assert_not_called ()
123126
0 commit comments