Skip to content

Commit 3688ca1

Browse files
committed
Fix flakey test
1 parent c3414d8 commit 3688ca1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

test/unit/core/cliManager.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,11 @@ describe("CliManager", () => {
730730
content: string,
731731
options: { chunkSize?: number; delay?: number } = {},
732732
): IncomingMessage {
733-
const { chunkSize = 8, delay = 0 } = options;
733+
const { chunkSize = 8, delay = 1 } = options;
734734

735735
const buffer = Buffer.from(content);
736736
let position = 0;
737+
let closeCallback: ((...args: unknown[]) => void) | null = null;
737738

738739
return {
739740
on: vi.fn((event: string, callback: (...args: unknown[]) => void) => {
@@ -749,13 +750,20 @@ describe("CliManager", () => {
749750
callback(chunk);
750751
if (position < buffer.length) {
751752
setTimeout(sendChunk, delay);
753+
} else {
754+
// All chunks sent - use setImmediate to ensure close happens
755+
// after all synchronous operations and I/O callbacks complete
756+
setImmediate(() => {
757+
if (closeCallback) {
758+
closeCallback();
759+
}
760+
});
752761
}
753762
}
754763
};
755764
setTimeout(sendChunk, delay);
756765
} else if (event === "close") {
757-
// Just close after a delay
758-
setTimeout(() => callback(), 10);
766+
closeCallback = callback;
759767
}
760768
}),
761769
destroy: vi.fn(),

0 commit comments

Comments
 (0)