mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:51:24 +00:00
fix(test): avoid fake-timers hang in gateway lock
This commit is contained in:
@@ -83,45 +83,32 @@ describe("gateway lock", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("blocks concurrent acquisition until release", async () => {
|
it("blocks concurrent acquisition until release", async () => {
|
||||||
vi.useFakeTimers();
|
// Fake timers can hang on Windows CI when combined with fs open loops.
|
||||||
vi.setSystemTime(new Date("2026-02-06T10:05:00.000Z"));
|
// Keep this test on real timers and use small timeouts.
|
||||||
|
vi.useRealTimers();
|
||||||
const { env, cleanup } = await makeEnv();
|
const { env, cleanup } = await makeEnv();
|
||||||
const lock = await acquireGatewayLock({
|
const lock = await acquireGatewayLock({
|
||||||
env,
|
env,
|
||||||
allowInTests: true,
|
allowInTests: true,
|
||||||
timeoutMs: 20,
|
timeoutMs: 100,
|
||||||
pollIntervalMs: 1,
|
pollIntervalMs: 5,
|
||||||
});
|
});
|
||||||
expect(lock).not.toBeNull();
|
expect(lock).not.toBeNull();
|
||||||
|
|
||||||
let settled = false;
|
|
||||||
const pending = acquireGatewayLock({
|
const pending = acquireGatewayLock({
|
||||||
env,
|
env,
|
||||||
allowInTests: true,
|
allowInTests: true,
|
||||||
timeoutMs: 20,
|
timeoutMs: 100,
|
||||||
pollIntervalMs: 1,
|
pollIntervalMs: 5,
|
||||||
});
|
});
|
||||||
void pending.then(
|
|
||||||
() => {
|
|
||||||
settled = true;
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
settled = true;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// Drive the retry loop without real sleeping.
|
|
||||||
for (let i = 0; i < 20 && !settled; i += 1) {
|
|
||||||
await vi.advanceTimersByTimeAsync(5);
|
|
||||||
await Promise.resolve();
|
|
||||||
}
|
|
||||||
await expect(pending).rejects.toBeInstanceOf(GatewayLockError);
|
await expect(pending).rejects.toBeInstanceOf(GatewayLockError);
|
||||||
|
|
||||||
await lock?.release();
|
await lock?.release();
|
||||||
const lock2 = await acquireGatewayLock({
|
const lock2 = await acquireGatewayLock({
|
||||||
env,
|
env,
|
||||||
allowInTests: true,
|
allowInTests: true,
|
||||||
timeoutMs: 20,
|
timeoutMs: 100,
|
||||||
pollIntervalMs: 1,
|
pollIntervalMs: 5,
|
||||||
});
|
});
|
||||||
await lock2?.release();
|
await lock2?.release();
|
||||||
await cleanup();
|
await cleanup();
|
||||||
|
|||||||
Reference in New Issue
Block a user