From: Jérôme Benoit Date: Mon, 29 May 2023 10:58:57 +0000 (+0200) Subject: fix: ensure internal counters are zeroed at simulator stop X-Git-Tag: v1.2.15~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0f040ac07b841b0eb9ed5e65d76c85adbb084aa2;p=e-mobility-charging-stations-simulator.git fix: ensure internal counters are zeroed at simulator stop Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 35f67a95..cebd8c8f 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -60,8 +60,8 @@ export class Bootstrap extends EventEmitter { // Enable unconditionally for now handleUnhandledRejection(); handleUncaughtException(); - this.initializedCounters = false; this.started = false; + this.initializedCounters = false; this.initializeCounters(); this.workerImplementation = null; this.workerScript = path.join( @@ -148,6 +148,7 @@ export class Bootstrap extends EventEmitter { this.workerImplementation = null; this.uiServer?.stop(); await this.storage?.close(); + this.resetCounters(); this.initializedCounters = false; this.started = false; } else { @@ -259,8 +260,7 @@ export class Bootstrap extends EventEmitter { private initializeCounters() { if (this.initializedCounters === false) { - this.numberOfChargingStationTemplates = 0; - this.numberOfChargingStations = 0; + this.resetCounters(); const stationTemplateUrls = Configuration.getStationTemplateUrls(); if (Utils.isNotEmptyArray(stationTemplateUrls)) { this.numberOfChargingStationTemplates = stationTemplateUrls.length; @@ -279,11 +279,16 @@ export class Bootstrap extends EventEmitter { ); process.exit(exitCodes.noChargingStationTemplates); } - this.numberOfStartedChargingStations = 0; this.initializedCounters = true; } } + private resetCounters(): void { + this.numberOfChargingStationTemplates = 0; + this.numberOfChargingStations = 0; + this.numberOfStartedChargingStations = 0; + } + private async startChargingStation( index: number, stationTemplateUrl: StationTemplateUrl