Merge pull request #921 from SAP/combined-prs-branch
[e-mobility-charging-stations-simulator.git] / src / charging-station / Bootstrap.ts
index 5b23676f24e39049cedf24f7581132f5b265a925..22b3207b57e5a03fbe09e3d250d8405486ba22ec 100644 (file)
@@ -129,7 +129,7 @@ export class Bootstrap extends EventEmitter {
         // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) {
           try {
-            const nbStations = stationTemplateUrl.numberOfStations ?? 0
+            const nbStations = stationTemplateUrl.numberOfStations
             for (let index = 1; index <= nbStations; index++) {
               await this.startChargingStation(index, stationTemplateUrl)
             }
@@ -156,7 +156,7 @@ export class Bootstrap extends EventEmitter {
                 : ''
             } worker(s) concurrently running in '${workerConfiguration.processType}' mode${
               this.workerImplementation?.maxElementsPerWorker != null
-                ? ` (${this.workerImplementation?.maxElementsPerWorker} charging station(s) per worker)`
+                ? ` (${this.workerImplementation.maxElementsPerWorker} charging station(s) per worker)`
                 : ''
             }`
           )
@@ -223,16 +223,16 @@ export class Bootstrap extends EventEmitter {
   private async waitChargingStationsStopped (): Promise<string> {
     return await new Promise<string>((resolve, reject) => {
       const waitTimeout = setTimeout(() => {
-        const message = `Timeout ${formatDurationMilliSeconds(
+        const timeoutMessage = `Timeout ${formatDurationMilliSeconds(
           Constants.STOP_CHARGING_STATIONS_TIMEOUT
         )} reached at stopping charging stations`
-        console.warn(chalk.yellow(message))
-        reject(new Error(message))
+        console.warn(chalk.yellow(timeoutMessage))
+        reject(new Error(timeoutMessage))
       }, Constants.STOP_CHARGING_STATIONS_TIMEOUT)
       waitChargingStationEvents(
         this,
         ChargingStationWorkerMessageEvents.stopped,
-        this.numberOfChargingStations
+        this.numberOfStartedChargingStations
       )
         .then(() => {
           resolve('Charging stations stopped')
@@ -246,7 +246,7 @@ export class Bootstrap extends EventEmitter {
 
   private initializeWorkerImplementation (workerConfiguration: WorkerConfiguration): void {
     let elementsPerWorker: number | undefined
-    switch (workerConfiguration?.elementsPerWorker) {
+    switch (workerConfiguration.elementsPerWorker) {
       case 'auto':
         elementsPerWorker =
           this.numberOfChargingStations > availableParallelism()
@@ -373,7 +373,7 @@ export class Bootstrap extends EventEmitter {
       if (isNotEmptyArray(stationTemplateUrls)) {
         this.numberOfChargingStationTemplates = stationTemplateUrls.length
         for (const stationTemplateUrl of stationTemplateUrls) {
-          this.numberOfChargingStations += stationTemplateUrl.numberOfStations ?? 0
+          this.numberOfChargingStations += stationTemplateUrl.numberOfStations
         }
       } else {
         console.warn(
@@ -413,7 +413,7 @@ export class Bootstrap extends EventEmitter {
   private gracefulShutdown (): void {
     this.stop()
       .then(() => {
-        console.info(`${chalk.green('Graceful shutdown')}`)
+        console.info(chalk.green('Graceful shutdown'))
         this.uiServer?.stop()
         // stop() asks for charging stations to stop by default
         this.waitChargingStationsStopped()