test(core): wait for cron lock probe takeover (#5535)

This commit is contained in:
tt-a1i 2026-06-21 06:40:42 +08:00 committed by GitHub
parent 8be8ef3e27
commit 8553013ee8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1056,14 +1056,16 @@ describe('CronScheduler', () => {
vi.useRealTimers();
usingFakeTimers = false;
// The probe acquired the lock and flipped this session to owner.
// The probe acquired the lock.
await vi.waitFor(async () => {
const raw = await fs.readFile(getLockFilePath(tmpDir), 'utf-8');
expect(JSON.parse(raw).sessionId).toBe('session-1');
});
// Now an owner, the durable job fires.
scheduler.tick(new Date(2025, 0, 15, 10, 31, 59));
expect(fired.map((j) => j.id)).toContain('probe-job');
// The lock write can be visible before the probe's .then flips isOwner.
await vi.waitFor(() => {
scheduler.tick(new Date(2025, 0, 15, 10, 31, 59));
expect(fired.map((j) => j.id)).toEqual(['probe-job']);
});
} finally {
if (usingFakeTimers) vi.useRealTimers();
}