Skip to content

Commit c920228

Browse files
committed
backend/execute-code: add test for the killing process issue
1 parent 2edcedf commit c920228

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/packages/backend/execute-code.test.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,42 @@ describe("await", () => {
405405
async_get: job_id,
406406
async_stats: true,
407407
});
408-
expect((Date.now() - t0) / 1000).toBeGreaterThan(.05);
408+
expect((Date.now() - t0) / 1000).toBeGreaterThan(0.05);
409409
expect(s.type).toEqual("async");
410410
if (s.type !== "async") return;
411411
expect(s.stderr).toEqual("baz\n");
412412
expect(s.exit_code).toEqual(3);
413413
expect(s.status).toEqual("completed");
414414
});
415+
416+
it("react to a killed process", async () => {
417+
const c = await executeCode({
418+
command: "sh",
419+
args: ["-c", `echo foo; sleep 1; echo bar;`],
420+
bash: false,
421+
err_on_exit: false,
422+
async_call: true,
423+
});
424+
expect(c.type).toEqual("async");
425+
if (c.type !== "async") return;
426+
const { job_id, pid } = c;
427+
await new Promise((done) => setTimeout(done, 100));
428+
await executeCode({
429+
command: `kill -9 -${pid}`,
430+
bash: true,
431+
});
432+
const s = await executeCode({
433+
async_await: true,
434+
async_get: job_id,
435+
async_stats: true,
436+
});
437+
expect(s.type).toEqual("async");
438+
if (s.type !== "async") return;
439+
expect(s.stderr).toEqual("");
440+
expect(s.stdout).toEqual("foo\n");
441+
expect(s.exit_code).toEqual(0);
442+
expect(s.status).toEqual("completed");
443+
});
415444
});
416445

417446
// we burn a bit of CPU to get the cpu_pct and cpu_secs up

0 commit comments

Comments
 (0)