mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 12:07:14 +02:00
LibJS: Add a function to ensure calls are made within the same second
Before these tests could be flaky if they happened to be called around the edge of a second. Now we try up to 5 times to execute the tests while staying within the same second.
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 03:45:41 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/cf0d30add6 Pull-request: https://github.com/SerenityOS/serenity/pull/16287 Reviewed-by: https://github.com/linusg ✅
@@ -37,12 +37,15 @@ describe("correct behavior", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const plainDateTime = Temporal.Now.plainDateTime(calendar, "UTC");
|
||||
const plainDateTimeWithOffset = Temporal.Now.plainDateTime(calendar, timeZone);
|
||||
const [plainDateTime, plainDateTimeWithOffset] = withinSameSecond(() => {
|
||||
return [
|
||||
Temporal.Now.plainDateTime(calendar, "UTC"),
|
||||
Temporal.Now.plainDateTime(calendar, timeZone),
|
||||
];
|
||||
});
|
||||
|
||||
if (plainDateTime.year !== plainDateTimeWithOffset.year) return;
|
||||
|
||||
// Let's hope the duration between the above two lines is less than a second :^)
|
||||
const differenceSeconds =
|
||||
plainDateTimeToEpochSeconds(plainDateTimeWithOffset) -
|
||||
plainDateTimeToEpochSeconds(plainDateTime);
|
||||
@@ -58,12 +61,15 @@ describe("correct behavior", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const plainDateTime = Temporal.Now.plainDateTime(calendar, "UTC");
|
||||
const plainDateTimeWithOffset = Temporal.Now.plainDateTime(calendar, timeZone);
|
||||
const [plainDateTime, plainDateTimeWithOffset] = withinSameSecond(() => {
|
||||
return [
|
||||
Temporal.Now.plainDateTime(calendar, "UTC"),
|
||||
Temporal.Now.plainDateTime(calendar, timeZone),
|
||||
];
|
||||
});
|
||||
|
||||
if (plainDateTime.year !== plainDateTimeWithOffset.year) return;
|
||||
|
||||
// Let's hope the duration between the above two lines is less than a second :^)
|
||||
const differenceSeconds =
|
||||
plainDateTimeToEpochSeconds(plainDateTimeWithOffset) -
|
||||
plainDateTimeToEpochSeconds(plainDateTime);
|
||||
|
||||
Reference in New Issue
Block a user