]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test: align sleep related tests
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 24 Oct 2025 13:04:07 +0000 (15:04 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 24 Oct 2025 13:04:07 +0000 (15:04 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
tests/utils/Utils.test.ts
tests/worker/WorkerUtils.test.ts

index ec46791279ba79568bc2c029292cdfa35638bc52..4a60ba731a56cd9126a1afb87bae611d6c5cc18b 100644 (file)
@@ -53,9 +53,15 @@ await describe('Utils test suite', async () => {
 
   await it('Verify sleep()', async () => {
     const start = performance.now()
-    await sleep(1000)
+    const delay = 1000
+    const timeout = await sleep(delay)
     const stop = performance.now()
-    expect(stop - start).toBeGreaterThanOrEqual(1000)
+    const actualDelay = stop - start
+    expect(timeout).toBeDefined()
+    expect(typeof timeout).toBe('object')
+    expect(actualDelay).toBeGreaterThanOrEqual(delay)
+    expect(actualDelay).toBeLessThan(delay + 50) // Allow 50ms tolerance
+    clearTimeout(timeout)
   })
 
   await it('Verify formatDurationMilliSeconds()', () => {
index 28166ad0267524cc8a4f24526d3579c4dad4af5f..a40ee576587d10b57b2a8af079eba5c143aebb76 100644 (file)
@@ -30,11 +30,11 @@ await describe('WorkerUtils test suite', async () => {
   })
 
   await it('Verify sleep()', async () => {
-    const startTime = Date.now()
+    const startTime = performance.now()
     const delay = 10 // 10ms for fast test execution
 
     const timeout = await sleep(delay)
-    const endTime = Date.now()
+    const endTime = performance.now()
     const actualDelay = endTime - startTime
 
     // Verify timeout object is returned