|
3 | 3 | import pytest |
4 | 4 | import queue |
5 | 5 | from unittest import mock |
| 6 | +import time |
6 | 7 |
|
7 | 8 | from libertem.executor.base import AsyncAdapter |
8 | 9 | from libertem.executor.dask import DaskJobExecutor |
@@ -144,6 +145,18 @@ async def test_get_executor_unsnooze(): |
144 | 145 | executor_state.executor.snooze_manager.snooze() |
145 | 146 | assert executor_state.executor.snooze_manager.is_snoozing |
146 | 147 |
|
| 148 | + # workaround: cannot call `executor.close` before the `snooze` |
| 149 | + # operation has completely finished, so we need to wait here. |
| 150 | + # NOTE: once this is fixed upstream in distributed, this should be |
| 151 | + # removed, as it also means we are not testing the real sequence here, |
| 152 | + # which doesn't wait! |
| 153 | + t0 = time.monotonic() |
| 154 | + while ( |
| 155 | + len(executor_state.executor._wrapped.client.cluster.workers) > 1 |
| 156 | + and time.monotonic() < t0 + 3 |
| 157 | + ): |
| 158 | + time.sleep(0.1) |
| 159 | + |
147 | 160 | # Getting the executor brings it out of snooze |
148 | 161 | await executor_state.get_executor() |
149 | 162 | assert not executor_state.executor.snooze_manager.is_snoozing |
@@ -189,6 +202,18 @@ async def test_snooze_explicit_keep_alive(): |
189 | 202 | snoozer.snooze() |
190 | 203 | assert snoozer.is_snoozing |
191 | 204 |
|
| 205 | + # workaround: cannot call `executor.close` before the `snooze` |
| 206 | + # operation has completely finished, so we need to wait here. |
| 207 | + # NOTE: once this is fixed upstream in distributed, this should be |
| 208 | + # removed, as it also means we are not testing the real sequence here, |
| 209 | + # which doesn't wait! |
| 210 | + t0 = time.monotonic() |
| 211 | + while ( |
| 212 | + len(executor_state.executor._wrapped.client.cluster.workers) > 1 |
| 213 | + and time.monotonic() < t0 + 3 |
| 214 | + ): |
| 215 | + time.sleep(0.1) |
| 216 | + |
192 | 217 | snoozer.unsnooze() |
193 | 218 | assert not snoozer.is_snoozing |
194 | 219 | # these two work without raising an exception: |
@@ -225,6 +250,18 @@ async def test_snooze_by_activity(local_cluster_url): |
225 | 250 | # opportunities to snooze in between: |
226 | 251 | assert snoozer.is_snoozing |
227 | 252 |
|
| 253 | + # workaround: cannot call `executor.close` before the `snooze` |
| 254 | + # operation has completely finished, so we need to wait here. |
| 255 | + # NOTE: once this is fixed upstream in distributed, this should be |
| 256 | + # removed, as it also means we are not testing the real sequence here, |
| 257 | + # which doesn't wait! |
| 258 | + t0 = time.monotonic() |
| 259 | + while ( |
| 260 | + len(executor_state.executor._wrapped.client.cluster.workers) > 1 |
| 261 | + and time.monotonic() < t0 + 3 |
| 262 | + ): |
| 263 | + time.sleep(0.1) |
| 264 | + |
228 | 265 | # and this should directly unsnooze the executor |
229 | 266 | # (we need to change the timeout etc. here, before we trigger the unsnooze, |
230 | 267 | # to make sure we don't directly snooze again): |
@@ -260,6 +297,19 @@ async def test_messages(): |
260 | 297 | await executor_state.set_executor(executor, params) |
261 | 298 |
|
262 | 299 | await asyncio.sleep(0.1) |
| 300 | + |
| 301 | + # workaround: cannot call `executor.close` before the `snooze` operation has |
| 302 | + # completely finished, so we need to wait here |
| 303 | + # NOTE: once this is fixed upstream in distributed, this should be |
| 304 | + # removed, as it also means we are not testing the real sequence here, |
| 305 | + # which doesn't wait! |
| 306 | + t0 = time.monotonic() |
| 307 | + while ( |
| 308 | + len(executor_state.executor._wrapped.client.cluster.workers) > 1 |
| 309 | + and time.monotonic() < t0 + 3 |
| 310 | + ): |
| 311 | + await asyncio.sleep(0.1) |
| 312 | + |
263 | 313 | # these two work without raising an exception: |
264 | 314 | await executor_state.get_executor() |
265 | 315 | messages = [] |
|
0 commit comments