Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/worker/runner/test-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const { filterExtraStackFrames } = require("../../../browser/stacktrace/utils");
const { extendWithCodeSnippet } = require("../../../error-snippets");
const { startSelectivity } = require("../../../browser/cdp/selectivity");

const SNAPSHOTS_TIMEOUT_MS = 5000;
const SNAPSHOTS_WARNING_TIMEOUT_MS = 2000;

module.exports = class TestRunner {
static create(...args) {
return new this(...args);
Expand Down Expand Up @@ -229,13 +232,23 @@ module.exports = class TestRunner {
attempt: this._attempt,
});

const snapshotsTimeout = new Promise((_, reject) =>
setTimeout(
() =>
reject(new Error(`Collecting Time Travel snapshots timed out after ${SNAPSHOTS_TIMEOUT_MS}ms`)),
SNAPSHOTS_TIMEOUT_MS,
),
);

// If collecting time travel snapshots takes a lot of time, make it obvious by writing a message
const collectingSnapshotsMessageTimeout = setTimeout(() => {
console.log("Collecting Time Travel snapshots takes longer than expected. Waiting...");
}, 2000);
}, SNAPSHOTS_WARNING_TIMEOUT_MS);

try {
await this._browser.snapshotsPromiseRef.current;
await Promise.race([this._browser.snapshotsPromiseRef.current, snapshotsTimeout]);
} catch (e) {
console.error(e.message);
} finally {
clearTimeout(collectingSnapshotsMessageTimeout);
await history.cleanupDomSnapshots({
Expand Down
55 changes: 55 additions & 0 deletions test/src/worker/runner/test-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1079,4 +1079,59 @@ describe("worker/runner/test-runner", () => {
assert.strictEqual(browser.state.isLastTestFailed, false);
});
});

describe("snapshots collection timeout", () => {
let clock;
let TimeTravelTestRunner;

const run_ = async () => {
const browser = mkBrowser_();
browser.snapshotsPromiseRef = { current: new Promise(() => {}) };
BrowserAgent.prototype.getBrowser.resolves(browser);

const runner = TimeTravelTestRunner.create({
test: mkTest_(),
file: "/default/file/path",
config: makeConfigStub(),
browserAgent: Object.create(BrowserAgent.prototype),
});

await runner.prepareBrowser({ sessionId: "session-id", sessionCaps: {}, sessionOpts: {}, state: {} });
return runner.run();
};

beforeEach(() => {
clock = sinon.useFakeTimers();

TimeTravelTestRunner = proxyquire("src/worker/runner/test-runner", {
"../../../browser/history": {
runGroup: historyRunGroupStub,
requestDomSnapshots: sandbox.stub(),
cleanupDomSnapshots: sandbox.stub().resolves(),
},
"../../../browser/cdp/selectivity": {
startSelectivity: sandbox.stub().resolves(() => Promise.resolve()),
},
"./capture-fail-screenshot": {
captureFailScreenshot: captureFailScreenshotStub,
},
});
});

afterEach(() => {
clock.restore();
});

it("should log warning after 2 seconds if snapshots collection is slow and log error after 5 seconds timeout ", async () => {
sandbox.stub(console, "error");
sandbox.stub(console, "log");

const runPromise = run_();
await clock.tickAsync(5000);
await runPromise;

assert.calledWith(console.log, "Collecting Time Travel snapshots takes longer than expected. Waiting...");
assert.calledWith(console.error, "Collecting Time Travel snapshots timed out after 5000ms");
});
});
});
Loading