feat: implement fail-fast monitoring to stop as soon as error/traceback is detected
This commit is contained in:
@@ -455,4 +455,31 @@ describe("monitorConsole", () => {
|
||||
);
|
||||
expect(api.socket.disconnect).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("exits early if a traceback occurs and onTraceback='fail'", async () => {
|
||||
// startTick=100, monitor=10 ticks.
|
||||
// If it didn't exit early, it would call api.time() many times.
|
||||
const api = buildMockApi({
|
||||
ticks: [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110],
|
||||
});
|
||||
|
||||
// Fire a traceback event after the first poll
|
||||
setTimeout(() => {
|
||||
api._fireConsole({
|
||||
messages: { log: [], results: [] },
|
||||
error:
|
||||
"TypeError: fail-fast test\n at Object.<anonymous> (main:1:1)",
|
||||
});
|
||||
}, 100);
|
||||
|
||||
const result = await monitorConsole(api, {
|
||||
...BASE_OPTS,
|
||||
monitor: 10,
|
||||
onTraceback: "fail",
|
||||
});
|
||||
|
||||
expect(result.sawTraceback).toBe(true);
|
||||
// We expect it to have called api.time fewer than 10 times (excluding the startTick call)
|
||||
expect(api.time.mock.calls.length).toBeLessThan(10);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user