]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix(test): use fake timers to prevent Reset test hangs on Windows
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 26 Feb 2026 23:16:08 +0000 (00:16 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 26 Feb 2026 23:16:08 +0000 (00:16 +0100)
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.

tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-Reset.test.ts

index e6c3f0b95d0cebcecd1a35c205cd46da1da18b1e..069ec34f72b68d25031dc2f45d04b5c9206cf51d 100644 (file)
@@ -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,