From aad09e43ae69971fd680783bbaad07bca7c65147 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 17 Jun 2026 02:44:49 +0200 Subject: [PATCH] refactor(bootstrap): remove redundant stopping flag --- src/charging-station/Bootstrap.ts | 37 ++++++++++-------------- tests/charging-station/Bootstrap.test.ts | 4 +-- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index cbdb5656..76141b98 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -109,7 +109,6 @@ export class Bootstrap extends EventEmitter implements IBootstrap { private starting: boolean private startPromise?: Promise private readonly stateFilePath: string - private stopping: boolean private stopPromise?: Promise private storage?: Storage private readonly templateStatistics: Map @@ -160,7 +159,6 @@ export class Bootstrap extends EventEmitter implements IBootstrap { handleUncaughtException() this.started = false this.starting = false - this.stopping = false this.shuttingDown = false this.uiServerStarted = false this.templateStatistics = new Map() @@ -432,27 +430,22 @@ export class Bootstrap extends EventEmitter implements IBootstrap { } private async doStop (reason: StopReason): Promise { - this.stopping = true - try { - await this.uiServer.sendInternalRequest( - this.uiServer.buildProtocolRequest( - generateUUID(), - ProcedureName.STOP_CHARGING_STATION, - Constants.EMPTY_FROZEN_OBJECT - ) + await this.uiServer.sendInternalRequest( + this.uiServer.buildProtocolRequest( + generateUUID(), + ProcedureName.STOP_CHARGING_STATION, + Constants.EMPTY_FROZEN_OBJECT ) - await this.waitChargingStationsStopped() - await this.workerImplementation?.stop() - this.removeAllListeners() - this.uiServer.clearCaches() - await this.storage?.close() - delete this.storage - this.started = false - if (this.persistStateEnabled && reason === StopReason.user) { - await writeStateFile(this.stateFilePath, false, this.logPrefix) - } - } finally { - this.stopping = false + ) + await this.waitChargingStationsStopped() + await this.workerImplementation?.stop() + this.removeAllListeners() + this.uiServer.clearCaches() + await this.storage?.close() + delete this.storage + this.started = false + if (this.persistStateEnabled && reason === StopReason.user) { + await writeStateFile(this.stateFilePath, false, this.logPrefix) } } diff --git a/tests/charging-station/Bootstrap.test.ts b/tests/charging-station/Bootstrap.test.ts index 7930228f..1f22cbe8 100644 --- a/tests/charging-station/Bootstrap.test.ts +++ b/tests/charging-station/Bootstrap.test.ts @@ -31,7 +31,6 @@ interface BootstrapInternal { starting: boolean startPromise?: Promise stateFilePath: string - stopping: boolean stopPromise?: Promise storage?: { close: () => Promise } templateStatistics: Map @@ -66,7 +65,6 @@ const buildLifecycleTestInstance = (stateFilePath: string): BootstrapInternal => EventEmitter.call(instance as unknown as EventEmitter) instance.started = false instance.starting = false - instance.stopping = false instance.startPromise = undefined instance.stopPromise = undefined instance.shuttingDown = false @@ -338,7 +336,7 @@ await describe('Bootstrap lifecycle state machine', async () => { assert.ok(warnMock.mock.calls.length >= 1, 'idempotent stop guard must log at warn level') }) - await it('Bootstrap.stop while stopping logs at debug', async () => { + await it('Bootstrap.stop while stop is in flight logs at debug', async () => { const errorMock = mock.method(logger, 'error', () => undefined) const debugMock = mock.method(logger, 'debug', () => undefined) const bootstrap = buildLifecycleTestInstance(stateFilePath) -- 2.53.0