mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-09-12 19:51:00 +05:00
test: restore setTimeout spy after use to prevent test leakage
This commit is contained in:
parent
ea5d046bad
commit
997725c64e
@ -121,18 +121,22 @@ describe("execAsyncRemote", () => {
|
||||
mocks.findServerById.mockResolvedValue(makeServer());
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
|
||||
const promise = execAsyncRemote("s1", "echo hi");
|
||||
await flushMicrotasks();
|
||||
try {
|
||||
const promise = execAsyncRemote("s1", "echo hi");
|
||||
await flushMicrotasks();
|
||||
|
||||
const client = getLastClient();
|
||||
expect(client.connect).toHaveBeenCalledTimes(1);
|
||||
const client = getLastClient();
|
||||
expect(client.connect).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(setTimeoutSpy.mock.calls.filter((call) => call[1] === 1000)).toEqual(
|
||||
[],
|
||||
);
|
||||
expect(
|
||||
setTimeoutSpy.mock.calls.filter((call) => call[1] === 1000),
|
||||
).toEqual([]);
|
||||
|
||||
// Settle the pending connection so the test does not hang.
|
||||
client.emit("error", new Error("aborted"));
|
||||
await expect(promise).rejects.toThrow("SSH connection error: aborted");
|
||||
// Settle the pending connection so the test does not hang.
|
||||
client.emit("error", new Error("aborted"));
|
||||
await expect(promise).rejects.toThrow("SSH connection error: aborted");
|
||||
} finally {
|
||||
setTimeoutSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user