ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / worker / timeoutManager.js
Source Blame History 174 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __defProp = Object.defineProperty;
f7eb47b… lmata 3 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 4 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 5 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 6 var __export = (target, all) => {
f7eb47b… lmata 7 for (var name in all)
f7eb47b… lmata 8 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 9 };
f7eb47b… lmata 10 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 11 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 12 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 13 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 15 }
f7eb47b… lmata 16 return to;
f7eb47b… lmata 17 };
f7eb47b… lmata 18 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 19 var timeoutManager_exports = {};
f7eb47b… lmata 20 __export(timeoutManager_exports, {
f7eb47b… lmata 21 TimeoutManager: () => TimeoutManager,
f7eb47b… lmata 22 TimeoutManagerError: () => TimeoutManagerError,
f7eb47b… lmata 23 kMaxDeadline: () => kMaxDeadline
f7eb47b… lmata 24 });
f7eb47b… lmata 25 module.exports = __toCommonJS(timeoutManager_exports);
f7eb47b… lmata 26 var import_utils = require("playwright-core/lib/utils");
f7eb47b… lmata 27 var import_utils2 = require("playwright-core/lib/utils");
f7eb47b… lmata 28 var import_util = require("../util");
f7eb47b… lmata 29 const kMaxDeadline = 2147483647;
f7eb47b… lmata 30 class TimeoutManager {
f7eb47b… lmata 31 constructor(timeout) {
f7eb47b… lmata 32 this._ignoreTimeouts = false;
f7eb47b… lmata 33 this._defaultSlot = { timeout, elapsed: 0 };
f7eb47b… lmata 34 }
f7eb47b… lmata 35 setIgnoreTimeouts() {
f7eb47b… lmata 36 this._ignoreTimeouts = true;
f7eb47b… lmata 37 if (this._running)
f7eb47b… lmata 38 this._updateTimeout(this._running);
f7eb47b… lmata 39 }
f7eb47b… lmata 40 interrupt() {
f7eb47b… lmata 41 if (this._running)
f7eb47b… lmata 42 this._running.timeoutPromise.reject(this._createTimeoutError(this._running));
f7eb47b… lmata 43 }
f7eb47b… lmata 44 isTimeExhaustedFor(runnable) {
f7eb47b… lmata 45 const slot = runnable.fixture?.slot || runnable.slot || this._defaultSlot;
f7eb47b… lmata 46 return slot.timeout > 0 && slot.elapsed >= slot.timeout - 1;
f7eb47b… lmata 47 }
f7eb47b… lmata 48 async withRunnable(runnable, cb) {
f7eb47b… lmata 49 if (this._running)
f7eb47b… lmata 50 throw new Error(`Internal error: duplicate runnable`);
f7eb47b… lmata 51 const running = this._running = {
f7eb47b… lmata 52 runnable,
f7eb47b… lmata 53 slot: runnable.fixture?.slot || runnable.slot || this._defaultSlot,
f7eb47b… lmata 54 start: (0, import_utils.monotonicTime)(),
f7eb47b… lmata 55 deadline: kMaxDeadline,
f7eb47b… lmata 56 timer: void 0,
f7eb47b… lmata 57 timeoutPromise: new import_utils.ManualPromise()
f7eb47b… lmata 58 };
f7eb47b… lmata 59 let debugTitle = "";
f7eb47b… lmata 60 try {
f7eb47b… lmata 61 if (import_util.debugTest.enabled) {
f7eb47b… lmata 62 debugTitle = runnable.fixture ? `${runnable.fixture.phase} "${runnable.fixture.title}"` : runnable.type;
f7eb47b… lmata 63 const location = runnable.location ? ` at "${(0, import_util.formatLocation)(runnable.location)}"` : ``;
f7eb47b… lmata 64 (0, import_util.debugTest)(`started ${debugTitle}${location}`);
f7eb47b… lmata 65 }
f7eb47b… lmata 66 this._updateTimeout(running);
f7eb47b… lmata 67 return await Promise.race([
f7eb47b… lmata 68 cb(),
f7eb47b… lmata 69 running.timeoutPromise
f7eb47b… lmata 70 ]);
f7eb47b… lmata 71 } finally {
f7eb47b… lmata 72 if (running.timer)
f7eb47b… lmata 73 clearTimeout(running.timer);
f7eb47b… lmata 74 running.timer = void 0;
f7eb47b… lmata 75 running.slot.elapsed += (0, import_utils.monotonicTime)() - running.start;
f7eb47b… lmata 76 this._running = void 0;
f7eb47b… lmata 77 if (import_util.debugTest.enabled)
f7eb47b… lmata 78 (0, import_util.debugTest)(`finished ${debugTitle}`);
f7eb47b… lmata 79 }
f7eb47b… lmata 80 }
f7eb47b… lmata 81 _updateTimeout(running) {
f7eb47b… lmata 82 if (running.timer)
f7eb47b… lmata 83 clearTimeout(running.timer);
f7eb47b… lmata 84 running.timer = void 0;
f7eb47b… lmata 85 if (this._ignoreTimeouts || !running.slot.timeout) {
f7eb47b… lmata 86 running.deadline = kMaxDeadline;
f7eb47b… lmata 87 return;
f7eb47b… lmata 88 }
f7eb47b… lmata 89 running.deadline = running.start + (running.slot.timeout - running.slot.elapsed);
f7eb47b… lmata 90 const timeout = running.deadline - (0, import_utils.monotonicTime)() + 1;
f7eb47b… lmata 91 if (timeout <= 0)
f7eb47b… lmata 92 running.timeoutPromise.reject(this._createTimeoutError(running));
f7eb47b… lmata 93 else
f7eb47b… lmata 94 running.timer = setTimeout(() => running.timeoutPromise.reject(this._createTimeoutError(running)), timeout);
f7eb47b… lmata 95 }
f7eb47b… lmata 96 defaultSlot() {
f7eb47b… lmata 97 return this._defaultSlot;
f7eb47b… lmata 98 }
f7eb47b… lmata 99 slow() {
f7eb47b… lmata 100 const slot = this._running ? this._running.slot : this._defaultSlot;
f7eb47b… lmata 101 slot.timeout = slot.timeout * 3;
f7eb47b… lmata 102 if (this._running)
f7eb47b… lmata 103 this._updateTimeout(this._running);
f7eb47b… lmata 104 }
f7eb47b… lmata 105 setTimeout(timeout) {
f7eb47b… lmata 106 const slot = this._running ? this._running.slot : this._defaultSlot;
f7eb47b… lmata 107 slot.timeout = timeout;
f7eb47b… lmata 108 if (this._running)
f7eb47b… lmata 109 this._updateTimeout(this._running);
f7eb47b… lmata 110 }
f7eb47b… lmata 111 currentSlotDeadline() {
f7eb47b… lmata 112 return this._running ? this._running.deadline : kMaxDeadline;
f7eb47b… lmata 113 }
f7eb47b… lmata 114 currentSlotType() {
f7eb47b… lmata 115 return this._running ? this._running.runnable.type : "test";
f7eb47b… lmata 116 }
f7eb47b… lmata 117 _createTimeoutError(running) {
f7eb47b… lmata 118 let message = "";
f7eb47b… lmata 119 const timeout = running.slot.timeout;
f7eb47b… lmata 120 const runnable = running.runnable;
f7eb47b… lmata 121 switch (runnable.type) {
f7eb47b… lmata 122 case "test": {
f7eb47b… lmata 123 if (runnable.fixture) {
f7eb47b… lmata 124 if (runnable.fixture.phase === "setup")
f7eb47b… lmata 125 message = `Test timeout of ${timeout}ms exceeded while setting up "${runnable.fixture.title}".`;
f7eb47b… lmata 126 else
f7eb47b… lmata 127 message = `Tearing down "${runnable.fixture.title}" exceeded the test timeout of ${timeout}ms.`;
f7eb47b… lmata 128 } else {
f7eb47b… lmata 129 message = `Test timeout of ${timeout}ms exceeded.`;
f7eb47b… lmata 130 }
f7eb47b… lmata 131 break;
f7eb47b… lmata 132 }
f7eb47b… lmata 133 case "afterEach":
f7eb47b… lmata 134 case "beforeEach":
f7eb47b… lmata 135 message = `Test timeout of ${timeout}ms exceeded while running "${runnable.type}" hook.`;
f7eb47b… lmata 136 break;
f7eb47b… lmata 137 case "beforeAll":
f7eb47b… lmata 138 case "afterAll":
f7eb47b… lmata 139 message = `"${runnable.type}" hook timeout of ${timeout}ms exceeded.`;
f7eb47b… lmata 140 break;
f7eb47b… lmata 141 case "teardown": {
f7eb47b… lmata 142 if (runnable.fixture)
f7eb47b… lmata 143 message = `Worker teardown timeout of ${timeout}ms exceeded while ${runnable.fixture.phase === "setup" ? "setting up" : "tearing down"} "${runnable.fixture.title}".`;
f7eb47b… lmata 144 else
f7eb47b… lmata 145 message = `Worker teardown timeout of ${timeout}ms exceeded.`;
f7eb47b… lmata 146 break;
f7eb47b… lmata 147 }
f7eb47b… lmata 148 case "skip":
f7eb47b… lmata 149 case "slow":
f7eb47b… lmata 150 case "fixme":
f7eb47b… lmata 151 case "fail":
f7eb47b… lmata 152 message = `"${runnable.type}" modifier timeout of ${timeout}ms exceeded.`;
f7eb47b… lmata 153 break;
f7eb47b… lmata 154 }
f7eb47b… lmata 155 const fixtureWithSlot = runnable.fixture?.slot ? runnable.fixture : void 0;
f7eb47b… lmata 156 if (fixtureWithSlot)
f7eb47b… lmata 157 message = `Fixture "${fixtureWithSlot.title}" timeout of ${timeout}ms exceeded during ${fixtureWithSlot.phase}.`;
f7eb47b… lmata 158 message = import_utils2.colors.red(message);
f7eb47b… lmata 159 const location = (fixtureWithSlot || runnable).location;
f7eb47b… lmata 160 const error = new TimeoutManagerError(message);
f7eb47b… lmata 161 error.name = "";
f7eb47b… lmata 162 error.stack = message + (location ? `
f7eb47b… lmata 163 at ${location.file}:${location.line}:${location.column}` : "");
f7eb47b… lmata 164 return error;
f7eb47b… lmata 165 }
f7eb47b… lmata 166 }
f7eb47b… lmata 167 class TimeoutManagerError extends Error {
f7eb47b… lmata 168 }
f7eb47b… lmata 169 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 170 0 && (module.exports = {
f7eb47b… lmata 171 TimeoutManager,
f7eb47b… lmata 172 TimeoutManagerError,
f7eb47b… lmata 173 kMaxDeadline
f7eb47b… lmata 174 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button