From: Jérôme Benoit Date: Fri, 24 Oct 2025 13:04:07 +0000 (+0200) Subject: test: align sleep related tests X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9ddd44097d65cdcf72bb1c50ec701294898eda2e;p=e-mobility-charging-stations-simulator.git test: align sleep related tests Signed-off-by: Jérôme Benoit --- diff --git a/tests/utils/Utils.test.ts b/tests/utils/Utils.test.ts index ec467912..4a60ba73 100644 --- a/tests/utils/Utils.test.ts +++ b/tests/utils/Utils.test.ts @@ -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()', () => { diff --git a/tests/worker/WorkerUtils.test.ts b/tests/worker/WorkerUtils.test.ts index 28166ad0..a40ee576 100644 --- a/tests/worker/WorkerUtils.test.ts +++ b/tests/worker/WorkerUtils.test.ts @@ -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