mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 10:41:30 +00:00
LibJS: Use Date for timing test-js tests
Stop relying on Temporal, at least temporarily. The classes used here will soon be removed (until they are implemented again from scratch).
This commit is contained in:
parent
dd6acfecd4
commit
ed76e1ed4b
Notes:
github-actions[bot]
2024-11-18 22:47:47 +00:00
Author: https://github.com/trflynn89
Commit: ed76e1ed4b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2387
1 changed files with 17 additions and 17 deletions
|
@ -599,20 +599,20 @@ class ExpectationError extends Error {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = () => Temporal.Now.instant().epochNanoseconds;
|
const start = Date.now();
|
||||||
const start = now();
|
const time_ms = () => Date.now() - start;
|
||||||
const time_us = () => Number(BigInt.asIntN(53, (now() - start) / 1000n));
|
|
||||||
try {
|
try {
|
||||||
callback();
|
callback();
|
||||||
suite[message] = {
|
suite[message] = {
|
||||||
result: "pass",
|
result: "pass",
|
||||||
duration: time_us(),
|
duration: time_ms(),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
suite[message] = {
|
suite[message] = {
|
||||||
result: "fail",
|
result: "fail",
|
||||||
details: String(e),
|
details: String(e),
|
||||||
duration: time_us(),
|
duration: time_ms(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -652,20 +652,20 @@ class ExpectationError extends Error {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = () => Temporal.Now.instant().epochNanoseconds;
|
const start = Date.now();
|
||||||
const start = now();
|
const time_ms = () => Date.now() - start;
|
||||||
const time_us = () => Number(BigInt.asIntN(53, (now() - start) / 1000n));
|
|
||||||
try {
|
try {
|
||||||
callback();
|
callback();
|
||||||
suite[message] = {
|
suite[message] = {
|
||||||
result: "fail",
|
result: "fail",
|
||||||
details: "Expected test to fail, but it passed",
|
details: "Expected test to fail, but it passed",
|
||||||
duration: time_us(),
|
duration: time_ms(),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
suite[message] = {
|
suite[message] = {
|
||||||
result: "xfail",
|
result: "xfail",
|
||||||
duration: time_us(),
|
duration: time_ms(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -677,21 +677,21 @@ class ExpectationError extends Error {
|
||||||
withinSameSecond = callback => {
|
withinSameSecond = callback => {
|
||||||
let callbackDuration;
|
let callbackDuration;
|
||||||
for (let tries = 0; tries < 5; tries++) {
|
for (let tries = 0; tries < 5; tries++) {
|
||||||
const start = Temporal.Now.instant();
|
const start = Date.now();
|
||||||
const result = callback();
|
const result = callback();
|
||||||
const end = Temporal.Now.instant();
|
const end = Date.now();
|
||||||
if (start.epochSeconds !== end.epochSeconds) {
|
|
||||||
callbackDuration = start.until(end);
|
if (start / 1000 != end / 1000) {
|
||||||
|
callbackDuration = end - start;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
throw new ExpectationError(
|
throw new ExpectationError(
|
||||||
`Tried to execute callback '${callback}' 5 times within the same second but ` +
|
`Tried to execute callback '${callback}' 5 times within the same second but ` +
|
||||||
`failed. Make sure the callback does as little work as possible (the last run ` +
|
`failed. Make sure the callback does as little work as possible (the last run ` +
|
||||||
`took ${callbackDuration.total(
|
`took ${callbackDuration}ms) and the machine is not overloaded. If you see this ` +
|
||||||
"milliseconds"
|
|
||||||
)} ms) and the machine is not overloaded. If you see this ` +
|
|
||||||
`error appearing in the CI it is most likely a flaky failure!`
|
`error appearing in the CI it is most likely a flaky failure!`
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue