From 3fc305c27751273a8021e626cacdaaacd4798f66 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Thu, 29 Oct 2026 14:38:51 -0700 Subject: [PATCH] test(thumbnails): store the job id before the cancel test's first write cancels (#504) The patched writer cancelled job_ids[0] after the first preview, but the id was stored only after the POST response was read. A fast worker wrote first, hit IndexError, cancelled nothing and the job finished. The first write now waits for the id on an Event the test sets after storing it. --- tests/test_thumbnail_jobs.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_thumbnail_jobs.py b/tests/test_thumbnail_jobs.py index 3daed5b8..cda1832f 100644 --- a/tests/test_thumbnail_jobs.py +++ b/tests/test_thumbnail_jobs.py @@ -490,16 +490,25 @@ class TestThumbnailJob(ThumbnailJobCase): real_write = images_module._write_image_thumbnail job_ids = [] written = [] + # #504: the worker can write its first preview before the response + # carrying the job id is read. The first write waits until the test + # has stored the id, so the cancel always lands after exactly one write. + first_written, id_stored = threading.Event(), threading.Event() + self.addCleanup(id_stored.set) def counting(src, dst, *args, **kwargs): real_write(src, dst, *args, **kwargs) written.append(dst) if len(written) == 1: + first_written.set() + id_stored.wait(10) self.api._jobs.cancel(job_ids[0]) with patch.object(images_module, "_write_image_thumbnail", counting): _, body = await self._start() + await self._wait(first_written) job_ids.append(body["job"]["id"]) + id_stored.set() job = await self._finished(body["job"]["id"]) self.assertEqual(job.state, "cancelled") self.assertEqual(job.status_line, "Cancelled ยท 1 preview written")