]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor(bootstrap): remove redundant stopping flag main
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 17 Jun 2026 00:44:49 +0000 (02:44 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 17 Jun 2026 00:44:49 +0000 (02:44 +0200)
src/charging-station/Bootstrap.ts
tests/charging-station/Bootstrap.test.ts

index cbdb56561854f5b73f02996f15824336d5236656..76141b9842026dd73502c03434b43d59794e2354 100644 (file)
@@ -109,7 +109,6 @@ export class Bootstrap extends EventEmitter implements IBootstrap {
   private starting: boolean
   private startPromise?: Promise<void>
   private readonly stateFilePath: string
-  private stopping: boolean
   private stopPromise?: Promise<void>
   private storage?: Storage
   private readonly templateStatistics: Map<string, TemplateStatistics>
@@ -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<string, TemplateStatistics>()
@@ -432,27 +430,22 @@ export class Bootstrap extends EventEmitter implements IBootstrap {
   }
 
   private async doStop (reason: StopReason): Promise<void> {
-    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)
     }
   }
 
index 7930228fd640e10a7529e2907b94ee4746a46a16..1f22cbe8d3a9ce0bb592473ed0b44673749ecdbc 100644 (file)
@@ -31,7 +31,6 @@ interface BootstrapInternal {
   starting: boolean
   startPromise?: Promise<void>
   stateFilePath: string
-  stopping: boolean
   stopPromise?: Promise<void>
   storage?: { close: () => Promise<void> }
   templateStatistics: Map<string, unknown>
@@ -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)