fix: stabilize flaky ChangeExtractorService invalidation test

The test races stale and fresh worker calls to verify that invalidation
prevents stale results from populating the cache. On slow CI, the
fresh worker mock could be reached before the stale deferred was
resolved, causing the version guard to mismatch.

Flush microtasks after starting freshPromise so it advances past
internal awaits and reaches the worker mock before we resolve the
stale deferred.
This commit is contained in:
Artem Rootman 2026-04-05 18:25:43 +00:00
parent 5efc3dd63f
commit 8570ed13fd
No known key found for this signature in database
GPG key ID: B7C30676209A822C

View file

@ -651,6 +651,14 @@ describe('ChangeExtractorService', () => {
const stalePromise = service.getTaskChanges(TEAM_NAME, TASK_ID, SUMMARY_OPTIONS);
await service.invalidateTaskChangeSummaries(TEAM_NAME, [TASK_ID], { deletePersisted: true });
const freshPromise = service.getTaskChanges(TEAM_NAME, TASK_ID, SUMMARY_OPTIONS);
// Flush microtasks so freshPromise advances past its internal awaits
// and reaches the worker mock before we resolve the stale deferred.
// Without this, CI timing can cause the stale resolution to race with
// the fresh worker call, making the test flaky.
await vi.advanceTimersByTimeAsync?.(0).catch(() => undefined);
await Promise.resolve();
await Promise.resolve();
await Promise.resolve();
first.resolve(makeTaskChangeResult());
const stale = await stalePromise;
const fresh = await freshPromise;