@@ -56,57 +56,19 @@ async def asyncTearDown(self):
5656 await self .executor .join (timeout = 2 )
5757
5858
59- class TestAsyncPeriodicExecutorRepr ( AsyncUnitTest ):
59+ class TestAsyncPeriodicExecutor ( AsyncPeriodicExecutorTestBase ):
6060 async def test_repr_contains_class_and_name (self ):
6161 executor = _make_executor (name = "exec" )
6262 executor_repr = repr (executor )
6363 self .assertIn ("AsyncPeriodicExecutor" , executor_repr )
6464 self .assertIn ("exec" , executor_repr )
6565
66-
67- class TestAsyncPeriodicExecutorBasic (AsyncPeriodicExecutorTestBase ):
68- async def test_update_interval (self ):
69- self .executor .update_interval (60 )
70- self .assertEqual (self .executor ._interval , 60 )
71-
72- async def test_skip_sleep (self ):
73- self .assertFalse (self .executor ._skip_sleep )
74- self .executor .skip_sleep ()
75- self .assertTrue (self .executor ._skip_sleep )
76-
77-
78- class TestAsyncPeriodicExecutorLifecycle (AsyncPeriodicExecutorTestBase ):
79- async def test_open_starts_worker (self ):
80- self .executor .open ()
81- if _IS_SYNC :
82- self .assertIsNotNone (self .executor ._thread )
83- self .assertTrue (self .executor ._thread .is_alive ())
84- else :
85- self .assertIsNotNone (self .executor ._task )
86-
87- async def test_close_sets_stopped (self ):
88- self .executor .open ()
89- self .executor .close ()
90- self .assertTrue (self .executor ._stopped )
91- await self .executor .join (timeout = 1 )
92-
9366 async def test_join_without_open_is_safe (self ):
94- await self .executor .join (timeout = 0.01 )
67+ try :
68+ await self .executor .join (timeout = 0.01 )
69+ except Exception as e :
70+ self .fail (f"join() raised unexpected Exception { e } " )
9571
96- async def test_multiple_open_calls_have_no_effect (self ):
97- self .executor .open ()
98- if _IS_SYNC :
99- worker_id = id (self .executor ._thread )
100- else :
101- worker_id = id (self .executor ._task )
102- self .executor .open ()
103- if _IS_SYNC :
104- self .assertEqual (worker_id , id (self .executor ._thread ))
105- else :
106- self .assertEqual (worker_id , id (self .executor ._task ))
107-
108-
109- class TestAsyncPeriodicExecutorTarget (AsyncPeriodicExecutorTestBase ):
11072 async def test_target_returning_false_stops_executor (self ):
11173 if _IS_SYNC :
11274 ran = threading .Event ()
@@ -119,12 +81,8 @@ async def target():
11981
12082 self .executor = _make_executor (target = target )
12183 self .executor .open ()
122- if _IS_SYNC :
123- self .assertTrue (ran .wait (timeout = 2 ), "target never ran" )
124- else :
125- await asyncio .wait_for (ran .wait (), timeout = 2 )
12684 await self .executor .join (timeout = 2 )
127- self .assertTrue (self . executor . _stopped )
85+ self .assertTrue (ran . is_set (), "target never ran" )
12886
12987 async def test_target_exception_stops_executor (self ):
13088 if _IS_SYNC :
@@ -144,11 +102,10 @@ def target():
144102
145103 self .executor = _make_executor (target = target )
146104 self .executor .open ()
147- self .assertTrue (ran .wait (timeout = 2 ), "target never ran" )
148105 self .executor .join (timeout = 2 )
106+ self .assertTrue (ran .is_set (), "target never ran" )
149107 finally :
150108 threading .excepthook = orig_excepthook
151- self .assertTrue (self .executor ._stopped )
152109 self .assertEqual (len (captured_exc ), 1 )
153110 self .assertIsInstance (captured_exc [0 ], RuntimeError )
154111 else :
@@ -160,17 +117,16 @@ async def target():
160117
161118 self .executor = _make_executor (target = target )
162119 self .executor .open ()
163- await asyncio .wait_for (ran .wait (), timeout = 2 )
164120 await self .executor .join (timeout = 2 )
165- self .assertTrue (self . executor . _stopped )
121+ self .assertTrue (ran . is_set (), "target never ran" )
166122 if self .executor ._task is not None and self .executor ._task .done ():
167123 self .executor ._task .exception ()
168124
169125 async def test_skip_sleep_flag_skips_interval (self ):
170126 call_times = []
171127
172128 async def target ():
173- call_times .append (time .monotonic () if _IS_SYNC else asyncio . get_running_loop (). time () )
129+ call_times .append (time .monotonic ())
174130 if len (call_times ) >= 2 :
175131 return False
176132 return True
@@ -217,14 +173,9 @@ async def target():
217173 self .executor = _make_executor (target = target )
218174 self .executor .open ()
219175 await self .executor .join (timeout = 2 )
220- self .assertTrue (self .executor ._stopped )
221- if not _IS_SYNC :
222- first_task = self .executor ._task
223176 self .executor .open ()
224177 await self .executor .join (timeout = 2 )
225178 self .assertGreaterEqual (called [0 ], 2 )
226- if not _IS_SYNC :
227- self .assertIsNot (self .executor ._task , first_task )
228179
229180
230181class TestShouldStop (AsyncUnitTest ):
@@ -273,8 +224,6 @@ def target():
273224 executor .open ()
274225 self .assertTrue (ran .wait (timeout = 2 ), "target never ran" )
275226 _shutdown_executors ()
276- executor .join (timeout = 2 )
277- self .assertTrue (executor ._stopped )
278227
279228 def test_shutdown_executors_safe_when_empty (self ):
280229 periodic_executor ._EXECUTORS .clear ()
0 commit comments