Skip to content

Commit 0551e13

Browse files
committed
test: replace setTimeout with promise handling for stream completion
Previously, the test used a fixed 1000ms timeout to call `done()` after handling the stream response. This approach was error-prone as the stream processing time might vary, potentially causing flaky tests or unnecessary delays. Now, the test awaits the promise returned by `handle` (which resolves when stream processing completes) before calling `done()`. This ensures the test only finishes when the stream processing is actually complete, making the test more reliable and responsive to actual processing time.
1 parent dd12a81 commit 0551e13

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/grpc-clients.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,10 @@ describe("clients test", () => {
170170
},
171171
});
172172

173-
// Handle the stream response
174-
handle(response2_3, ["1", "3", "4"]);
175-
176-
// Wait for the stream to complete
177-
setTimeout(() => {
173+
// Handle the stream response and wait for completion
174+
handle(response2_3, ["1", "3", "4"]).then(() => {
178175
done();
179-
}, 1000);
176+
});
180177
});
181178
});
182179
});

0 commit comments

Comments
 (0)