|
11 | 11 | from distributed.metrics import time |
12 | 12 | from distributed.protocol import Serialized |
13 | 13 | from distributed.utils_test import gen_cluster, inc |
| 14 | +from distributed.worker import get_worker |
14 | 15 |
|
15 | 16 |
|
16 | 17 | @gen_cluster() |
@@ -301,3 +302,30 @@ async def test_deserialize_client(c, s, a, b): |
301 | 302 | from distributed.client import _current_client |
302 | 303 |
|
303 | 304 | assert _current_client.get() is c |
| 305 | + |
| 306 | + |
| 307 | +@gen_cluster(client=True, worker_kwargs={"resources": {"A": 1}}) |
| 308 | +async def test_publish_submit_ordering(c, s, a, b): |
| 309 | + RESOURCES = {"A": 1} |
| 310 | + |
| 311 | + def _retrieve_annotations(): |
| 312 | + worker = get_worker() |
| 313 | + task = worker.state.tasks.get(worker.get_current_task()) |
| 314 | + return task.annotations |
| 315 | + |
| 316 | + # If publish does not take the same comm channel as the submit, it can |
| 317 | + # happen that the publish message reaches the scheduler before the submit |
| 318 | + # such that the state of the published future is not the one that has been |
| 319 | + # requested from the submit. Particularly, this lets us drop annotations |
| 320 | + # The current implementation does in fact not use the same channel due to |
| 321 | + # serialization issue (including Futures in BatchedSend appends them to the |
| 322 | + # "recent messages" log which screws with the refcounting) but ensure that |
| 323 | + # all queued up messages are flushed and received by the schduler befure |
| 324 | + # publishing |
| 325 | + future = c.submit(_retrieve_annotations, resources=RESOURCES, pure=False) |
| 326 | + |
| 327 | + await c.publish_dataset(future, name="foo") |
| 328 | + assert await c.list_datasets() == ("foo",) |
| 329 | + |
| 330 | + result = await future.result() |
| 331 | + assert result == {"resources": RESOURCES} |
0 commit comments