Skip to content

Commit

Permalink
make intervals test less flaky in CI... hopefully
Browse files Browse the repository at this point in the history
  • Loading branch information
suchipi committed Sep 4, 2024
1 parent 4cf4580 commit 526e8eb
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions tests/intervals.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { spawn } from "first-base";
import { binDir } from "./_utils";

// GitHub actions CPU is slow enough that these aren't deterministic unless we
// make all the timings longer
const WAIT_TIME_MULTIPLIER = process.env.CI ? 10 : 1;

test("setInterval and clearInterval are present", async () => {
const run = spawn(
binDir("qjs"),
Expand Down Expand Up @@ -37,12 +41,12 @@ test("setTimeout and setInterval work", async () => {
let i = 0;
setInterval(() => {
console.log("hello!", i++);
}, 40);
}, ${40 * WAIT_TIME_MULTIPLIER});
setTimeout(() => {
console.log("exiting");
require("quickjs:std").exit(0);
}, 150);
}, ${150 * WAIT_TIME_MULTIPLIER});
`,
],
{ cwd: __dirname }
Expand Down Expand Up @@ -70,12 +74,12 @@ test("setInterval callback continues to re-run even if it errors", async () => {
`
setInterval(() => {
throw new Error("uh oh! an error!");
}, 40);
}, ${40 * WAIT_TIME_MULTIPLIER});
setTimeout(() => {
console.log("exiting");
require("quickjs:std").exit(0);
}, 150);
}, ${150 * WAIT_TIME_MULTIPLIER});
`,
],
{ cwd: __dirname }
Expand Down Expand Up @@ -108,13 +112,13 @@ test("failure in setInterval callback uses console.error", async () => {
setInterval(() => {
throw new Error("uh oh! an error!");
}, 40);
}, ${40 * WAIT_TIME_MULTIPLIER});
setTimeout(() => {
console.log("receivedArgs.length:", receivedArgs.length);
console.log("exiting");
require("quickjs:std").exit(0);
}, 150);
}, ${150 * WAIT_TIME_MULTIPLIER});
`,
],
{ cwd: __dirname }
Expand Down Expand Up @@ -151,14 +155,14 @@ test("setInterval callback falls back to print if console.error isn't present",
setInterval(() => {
timesIntervalCallbackRan++;
throw new Error("uh oh! an error!");
}, 40);
}, ${40 * WAIT_TIME_MULTIPLIER});
setTimeout(() => {
console.log("times print called:", timesPrintCalled);
console.log("times interval callback ran:", timesIntervalCallbackRan);
console.log("exiting");
require("quickjs:std").exit(0);
}, 150);
}, ${150 * WAIT_TIME_MULTIPLIER});
`,
],
{ cwd: __dirname }
Expand Down Expand Up @@ -201,14 +205,14 @@ test("setInterval callback falls back to print if console.error errors", async (
setInterval(() => {
timesIntervalCallbackRan++;
throw new Error("uh oh! an error!");
}, 40);
}, ${40 * WAIT_TIME_MULTIPLIER});
setTimeout(() => {
console.log("times print called:", timesPrintCalled);
console.log("times interval callback ran:", timesIntervalCallbackRan);
console.log("exiting");
require("quickjs:std").exit(0);
}, 150);
}, ${150 * WAIT_TIME_MULTIPLIER});
`,
],
{ cwd: __dirname }
Expand Down Expand Up @@ -243,13 +247,13 @@ test("setInterval callback still runs even if console.error and print aren't ava
setInterval(() => {
timesIntervalCallbackRan++;
throw new Error("uh oh! an error!");
}, 40);
}, ${40 * WAIT_TIME_MULTIPLIER});
setTimeout(() => {
console.log("times interval callback ran:", timesIntervalCallbackRan);
console.log("exiting");
require("quickjs:std").exit(0);
}, 150);
}, ${150 * WAIT_TIME_MULTIPLIER});
`,
],
{ cwd: __dirname }
Expand Down Expand Up @@ -284,13 +288,13 @@ test("setInterval callback still runs even if console.error and print both fail"
setInterval(() => {
timesIntervalCallbackRan++;
throw new Error("uh oh! an error!");
}, 40);
}, ${40 * WAIT_TIME_MULTIPLIER});
setTimeout(() => {
console.log("times interval callback ran:", timesIntervalCallbackRan);
console.log("exiting");
require("quickjs:std").exit(0);
}, 150);
}, ${150 * WAIT_TIME_MULTIPLIER});
`,
],
{ cwd: __dirname }
Expand Down

0 comments on commit 526e8eb

Please sign in to comment.