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
This commit is contained in:
		
					parent
					
						
							
								9524361bb4
							
						
					
				
			
			
				commit
				
					
						a0d9d8d576
					
				
			
		
					 1 changed files with 1 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue