fix: ensure simulator stop wait for started CS only stop
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 26 May 2023 11:20:55 +0000 (13:20 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 26 May 2023 11:20:55 +0000 (13:20 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts

index db884ed874285adae8c532ff6b3fccb175ec5fbb..96a498f601a626c2f640637fe8184446fe646085 100644 (file)
@@ -304,13 +304,18 @@ export class Bootstrap extends EventEmitter {
       });
   };
 
-  private waitForChargingStationsStopped = async (): Promise<void> => {
+  private waitForChargingStationsStopped = async (
+    stoppedEventsToWait = this.numberOfStartedChargingStations
+  ): Promise<number> => {
     return new Promise((resolve) => {
       let stoppedEvents = 0;
+      if (stoppedEventsToWait === 0) {
+        resolve(stoppedEvents);
+      }
       this.on(ChargingStationWorkerMessageEvents.stopped, () => {
         ++stoppedEvents;
-        if (stoppedEvents === this.numberOfChargingStations) {
-          resolve();
+        if (stoppedEvents === stoppedEventsToWait) {
+          resolve(stoppedEvents);
         }
       });
     });