From: Jérôme Benoit Date: Thu, 26 Feb 2026 23:16:08 +0000 (+0100) Subject: fix(test): use fake timers to prevent Reset test hangs on Windows X-Git-Tag: v3~143 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3cc32802bd72dcba223af40d88e8f528cb07c31c;p=e-mobility-charging-stations-simulator.git fix(test): use fake timers to prevent Reset test hangs on Windows Reset handlers (scheduleResetOnIdle, scheduleEvseResetOnIdle, scheduleEvseReset) create setInterval/setTimeout/setImmediate timers that are never cleaned up. Node.js test runner on Windows waits for all timers before loading next test file, causing indefinite hangs. Solution: Use Node.js mock.timers API with beforeEach(enable) + afterEach(reset) pattern, validated against GitHub Desktop, AFFiNE, and official Node.js docs. --- diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-Reset.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-Reset.test.ts index e6c3f0b9..069ec34f 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-Reset.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-Reset.test.ts @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { expect } from '@std/expect' -import { describe, it } from 'node:test' +import { afterEach, beforeEach, describe, it, mock } from 'node:test' import { OCPP20IncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.js' import { @@ -20,8 +20,18 @@ import { Constants } from '../../../../src/utils/index.js' import { createChargingStation } from '../../../ChargingStationFactory.js' import { TEST_CHARGING_STATION_BASE_NAME } from './OCPP20TestConstants.js' -// FIXME: tests hang on Windows - root cause unknown (dichotomous search: Reset was last test before hang) -await describe('B11 & B12 - Reset', { skip: process.platform === 'win32' }, async () => { +// Reset tests use fake timers to prevent real setInterval/setTimeout from blocking test runner +// This fixes Windows CI hangs where Node.js test runner waits for all timers to complete +await describe('B11 & B12 - Reset', async () => { + // Enable fake timers for all timer APIs used by Reset handlers + beforeEach(() => { + mock.timers.enable({ apis: ['setInterval', 'setTimeout', 'setImmediate'] }) + }) + + afterEach(() => { + mock.timers.reset() + }) + const mockChargingStation = createChargingStation({ baseName: TEST_CHARGING_STATION_BASE_NAME, connectorsCount: 3,