mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-09 00:24:08 +00:00
test(js): false negative in sleep test
It is entirely possible that the difference between the specified
sleep time and the actual sleep time is greater than 15 seconds.
https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#Notes
> Note that in either case, the actual delay may be longer than
> intended; see Reasons for delays longer than specified below.
It is however an error for the delay to be shorter.
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
FAIL web_src/js/utils.test.js > sleep
AssertionError: expected false to be truthy
❯ testSleep web_src/js/utils.test.js:192:48
190| const endTime = Date.now(); // Record the end time
191| const actualSleepTime = endTime - startTime;
192| expect(Math.abs(actualSleepTime - ms) <= 15).toBeTruthy();
| ^
193| }
194|
❯ web_src/js/utils.test.js:184:3
(cherry picked from commit a0d9d8d576
)
This commit is contained in:
parent
8fec0822e4
commit
9230d787ff
|
@ -177,10 +177,6 @@ test('serializeXml', () => {
|
|||
});
|
||||
|
||||
test('sleep', async () => {
|
||||
// Test 500 ms sleep
|
||||
await testSleep(500);
|
||||
|
||||
// Test 2000 ms sleep
|
||||
await testSleep(2000);
|
||||
});
|
||||
|
||||
|
@ -189,5 +185,5 @@ async function testSleep(ms) {
|
|||
await sleep(ms);
|
||||
const endTime = Date.now(); // Record the end time
|
||||
const actualSleepTime = endTime - startTime;
|
||||
expect(Math.abs(actualSleepTime - ms) <= 15).toBeTruthy();
|
||||
expect(actualSleepTime >= ms).toBeTruthy();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue