@nsshunt/ststestrunner 1.1.71 → 1.1.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,6 +54,7 @@ var TestCaseFhirBase = class {
54
54
  #resetSocketClientTrigger = 50;
55
55
  #clientSocketFetchCount = 0;
56
56
  #authAgentManager;
57
+ _authMaxTimeout = 5e3;
57
58
  accessTokenTime = performance.now();
58
59
  newTokenLimitTime = 30;
59
60
  restFhirClient = null;
@@ -155,10 +156,7 @@ var TestCaseFhirBase = class {
155
156
  try {
156
157
  this.#clientSocketFetchCount++;
157
158
  let fhirClient = this.runnerExecutionWorker.GetFhirClient();
158
- if (fhirClient) {
159
- this.Debug(chalk.default.green(`[${this.runnerExecutionWorker.id}] Getting existing fhir client`));
160
- return fhirClient;
161
- }
159
+ if (fhirClient) return fhirClient;
162
160
  if (this.runnerExecutionWorker.GetOnHold("fhirclient") === true) {
163
161
  this.Debug(chalk.default.magenta(`[${this.runnerExecutionWorker.id}] fhir client does not exist - some other client setting up the new client (on hold/lock) - waiting ...`));
164
162
  try {
@@ -206,20 +204,17 @@ var TestCaseFhirBase = class {
206
204
  this.Debug(chalk.default.yellow(`[${this.runnerExecutionWorker.id}] release hold (lock) Time taken for socket connection and set object: [${performance.now() - start}ms]`));
207
205
  return fhirClient;
208
206
  } catch (error) {
209
- this.LogErrorMessage(error);
207
+ this.Error(error);
210
208
  throw error;
211
209
  }
212
210
  };
213
211
  #LogMessage = (message) => {};
214
- LogErrorMessage = (message) => {
215
- this.#runner.instrumentData.message.push(chalk.default.red(`${message}`));
216
- };
217
212
  Debug = (message) => {
218
213
  this.#runnerExecutionWorker.logger.debug(message);
219
214
  };
220
215
  Error = (message) => {
221
- this.LogErrorMessage(message);
222
216
  this.#runnerExecutionWorker.logger.error(message);
217
+ this.#runner.instrumentData.message.push(chalk.default.red(`${message}`));
223
218
  };
224
219
  Warning = (message) => {
225
220
  this.#runnerExecutionWorker.logger.warn(message);
@@ -261,13 +256,9 @@ var TestCaseFhirBase = class {
261
256
  const match = uri.match(this.#originRegex);
262
257
  return match ? match[1] : null;
263
258
  };
264
- GetAPITokenFromAuthServerUsingScope = async (options, errorCb) => {
259
+ GetAPITokenFromAuthServerUsingScope = async (options) => {
265
260
  const { scope, clientId, authClientSecret, endPoint } = options;
266
261
  let stage = "1";
267
- const invokeErrorCb = (error) => {
268
- this.Debug(error);
269
- errorCb(error);
270
- };
271
262
  try {
272
263
  stage = "2";
273
264
  const scopes = scope.split(" ");
@@ -294,10 +285,7 @@ var TestCaseFhirBase = class {
294
285
  }
295
286
  }
296
287
  stage = "4";
297
- if (error) {
298
- invokeErrorCb(error);
299
- return "";
300
- }
288
+ if (error) throw error;
301
289
  stage = "5";
302
290
  const payload = {
303
291
  client_id: clientId,
@@ -326,11 +314,8 @@ var TestCaseFhirBase = class {
326
314
  this.#runner.instrumentData.authenticationCount++;
327
315
  stage = "7";
328
316
  if (retVal.status) {
329
- if (retVal.status !== 200) this.Debug(chalk.default.magenta(`Error (AuthUtilsNode:GetAPITokenFromServer): Invalid response from server: [${retVal.status}]`));
330
- } else {
331
- invokeErrorCb(new Error(chalk.default.red(`Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.status)`)));
332
- return "";
333
- }
317
+ if (retVal.status !== 200) this.Warning(chalk.default.magenta(`TestCaseFhirBase:GetAPITokenFromAuthServerUsingScope(): Invalid response from server: [${retVal.status}]`));
318
+ } else throw new Error(chalk.default.red(`No retVal.status)`));
334
319
  stage = "8";
335
320
  if (retVal.data) {
336
321
  stage = "9";
@@ -339,13 +324,11 @@ var TestCaseFhirBase = class {
339
324
  return retVal.data.access_token;
340
325
  } else {
341
326
  stage = "13";
342
- invokeErrorCb(/* @__PURE__ */ new Error(`Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.data.access_token)`));
343
- return "";
327
+ throw new Error(`No retVal.data.access_token)`);
344
328
  }
345
329
  } else {
346
330
  stage = "14";
347
- invokeErrorCb(/* @__PURE__ */ new Error(`Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.data)`));
348
- return "";
331
+ throw new Error(`No retVal.data)`);
349
332
  }
350
333
  } catch (error) {
351
334
  this.Error(error);
@@ -355,34 +338,64 @@ var TestCaseFhirBase = class {
355
338
  } catch (error) {
356
339
  details = `Could not JSON.stringify(error.response.data)`;
357
340
  }
358
- invokeErrorCb(/* @__PURE__ */ new Error(`Error (AuthUtilsNode:GetAPITokenFromServer:catch): [${error}], Stage: [${stage}], Details: [${details}]`));
359
- return "";
341
+ error.message = `TestCaseFhirBase:GetAPITokenFromAuthServerUsingScope(): Error: [${error}], Stage: [${stage}], Details: [${details}]`;
342
+ throw error;
360
343
  }
361
344
  };
362
- GetAccessTokenForSocketClientAccess = () => {
363
- const scopes = `api://fb6513e4-16fe-4931-bed8-33b82b404a14/_.stsfhir5:SocketConnection`.split(" ").sort().join(" ");
364
- const authendpointUrl = `${this.#options.authOptions.asendpoint}:${this.#options.authOptions.asport}`;
365
- return this.GetAPITokenFromAuthServerUsingScope({
366
- clientId: "d8277fce-bb48-44c2-bbf1-257fe13a444b",
367
- authClientSecret: "64e3ef37-c7b8-4cb1-880a-e6ad3ab36e3c",
368
- scope: scopes,
369
- endPoint: authendpointUrl
370
- }, (error) => this.LogErrorMessage(error));
345
+ GetAccessTokenForSocketClientAccess = async () => {
346
+ const timeout = setTimeout(() => {
347
+ this.Warning(`TestCaseFhirBase:GetAccessTokenForSocketClientAccess(): Timeout: [${this._authMaxTimeout}] exceeded for getting access token ...`);
348
+ }, this._authMaxTimeout);
349
+ const start = performance.now();
350
+ try {
351
+ const scopes = `api://fb6513e4-16fe-4931-bed8-33b82b404a14/_.stsfhir5:SocketConnection`.split(" ").sort().join(" ");
352
+ const authendpointUrl = `${this.#options.authOptions.asendpoint}:${this.#options.authOptions.asport}`;
353
+ const retVal = await this.GetAPITokenFromAuthServerUsingScope({
354
+ clientId: "d8277fce-bb48-44c2-bbf1-257fe13a444b",
355
+ authClientSecret: "64e3ef37-c7b8-4cb1-880a-e6ad3ab36e3c",
356
+ scope: scopes,
357
+ endPoint: authendpointUrl
358
+ });
359
+ clearTimeout(timeout);
360
+ const totalTime = performance.now() - start;
361
+ if (totalTime > this._authMaxTimeout) this.Warning(chalk.default.magenta(`TestCaseFhirBase:GetAccessTokenForSocketClientAccess(): The total time for getting the access token: [${totalTime}]`));
362
+ return retVal;
363
+ } catch (error) {
364
+ clearTimeout(timeout);
365
+ error.message = `TestCaseFhirBase:GetAccessTokenForSocketClientAccess(): Error: [${error}], Duration until error: [${performance.now() - start}]`;
366
+ this.Error(error);
367
+ return "";
368
+ }
371
369
  };
372
370
  GetAccessToken = async () => {
373
- if (performance.now() - this.accessTokenTime > this.newTokenLimitTime * 1e3) this.#accesssToken = null;
374
- if (this.#accesssToken) return this.#accesssToken;
375
- const scopes = `api://fb6513e4-16fe-4931-bed8-33b82b404a14/_.stsfhir5:All`.split(" ").sort().join(" ");
376
- const authendpointUrl = `${this.#options.authOptions.asendpoint}:${this.#options.authOptions.asport}`;
377
- const retVal = await this.GetAPITokenFromAuthServerUsingScope({
378
- clientId: "d8277fce-bb48-44c2-bbf1-257fe13a444b",
379
- authClientSecret: "64e3ef37-c7b8-4cb1-880a-e6ad3ab36e3c",
380
- scope: scopes,
381
- endPoint: authendpointUrl
382
- }, (error) => this.LogErrorMessage(error));
383
- this.accessTokenTime = performance.now();
384
- this.#accesssToken = retVal;
385
- return retVal;
371
+ let timeout = void 0;
372
+ let start = performance.now();
373
+ try {
374
+ if (start - this.accessTokenTime > this.newTokenLimitTime * 1e3) this.#accesssToken = null;
375
+ if (this.#accesssToken) return this.#accesssToken;
376
+ timeout = setTimeout(() => {
377
+ this.Warning(chalk.default.magenta(`TestCaseFhirBase:GetAccessToken(): Timeout: [${this._authMaxTimeout}] exceeded for getting access token ...`));
378
+ }, this._authMaxTimeout);
379
+ const scopes = `api://fb6513e4-16fe-4931-bed8-33b82b404a14/_.stsfhir5:All`.split(" ").sort().join(" ");
380
+ const authendpointUrl = `${this.#options.authOptions.asendpoint}:${this.#options.authOptions.asport}`;
381
+ const retVal = await this.GetAPITokenFromAuthServerUsingScope({
382
+ clientId: "d8277fce-bb48-44c2-bbf1-257fe13a444b",
383
+ authClientSecret: "64e3ef37-c7b8-4cb1-880a-e6ad3ab36e3c",
384
+ scope: scopes,
385
+ endPoint: authendpointUrl
386
+ });
387
+ this.accessTokenTime = performance.now();
388
+ this.#accesssToken = retVal;
389
+ if (timeout) clearTimeout(timeout);
390
+ const totalTime = performance.now() - start;
391
+ if (totalTime > this._authMaxTimeout) this.Warning(chalk.default.magenta(`TestCaseFhirBase:GetAccessToken(): The total time for getting the access token: [${totalTime}]`));
392
+ return retVal;
393
+ } catch (error) {
394
+ if (timeout) clearTimeout(timeout);
395
+ error.message = `TestCaseFhirBase:GetAccessToken(): Error: [${error}], Duration until error: [${performance.now() - start}]`;
396
+ this.Error(error);
397
+ return "";
398
+ }
386
399
  };
387
400
  GetPersonRecord = async (prefix, index, version) => {
388
401
  const { workerIndex, runnerIndex, runId } = this.#options;
@@ -514,6 +527,7 @@ var TestCaseFhirBase = class {
514
527
  //#endregion
515
528
  //#region src/libmodule/testCaseFhirQueryBase.ts
516
529
  var TestCaseFhirQueryBase = class extends TestCaseFhirBase {
530
+ _longExecTimeoutVal = 5e3;
517
531
  constructor(workerInstance, runner) {
518
532
  super(workerInstance, runner);
519
533
  }
@@ -534,17 +548,26 @@ var TestCaseFhirQueryBase = class extends TestCaseFhirBase {
534
548
  if (this.runner.instrumentData.requestCount % this.runner.options.clientResetMod === 0) this.#ResetClient("#ResetClient triggered");
535
549
  }
536
550
  };
551
+ _GetDetail = () => {
552
+ return `testType: [${this.runner.options.testType}], description: [${this.runner.options.description}], workerManagerId: [${this.runner.workerManagerId}], Iteration: [${this.runner.iteration}]`;
553
+ };
537
554
  ExecuteRunner = async () => {
538
- if (this.runner.iteration % 100 === 0) this.Debug(`TestCaseFhirQueryBase:ExecuteRunner(): ${this.runner.options.testType}:${this.runner.workerManagerId} -->> Iteration: ${this.runner.options.description} ${this.runner.iteration}`);
555
+ if (this.runner.iteration % 100 === 0) this.Debug(`TestCaseFhirQueryBase:ExecuteRunner(): ${this._GetDetail()}`);
539
556
  const start = performance.now();
540
557
  this.runner.instrumentData.activeRequestCount++;
541
558
  this.#CheckResetClient();
559
+ const longExecTimeout = setTimeout(() => {
560
+ this.Debug(chalk.default.magenta(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${this._longExecTimeoutVal}] exceeded - still waiting ...`));
561
+ this.Debug(chalk.default.magenta(`TestCaseFhirQueryBase:ExecuteRunner(): ==> ${this._GetDetail()}`));
562
+ }, this._longExecTimeoutVal);
542
563
  try {
543
564
  await this.ExecuteQuery();
565
+ clearInterval(longExecTimeout);
544
566
  } catch (error) {
567
+ clearInterval(longExecTimeout);
545
568
  this.runner.instrumentData.errorCount++;
546
- const message = `TestCaseFhirQueryBase:ExecuteRunner(): TestType: [${this.runner.options.testType}], Error: [${error}]`;
547
- this.LogErrorMessage(message);
569
+ const message = `TestCaseFhirQueryBase:ExecuteRunner(): Error: [${error}], Error Count: [${this.runner.instrumentData.errorCount}], ${this._GetDetail()}`;
570
+ this.Error(message);
548
571
  this.#ResetClient(message);
549
572
  }
550
573
  this.runner.instrumentData.coreCount = 1;
@@ -553,8 +576,21 @@ var TestCaseFhirQueryBase = class extends TestCaseFhirBase {
553
576
  this.runner.instrumentData.activeRequestCount--;
554
577
  const diff = performance.now() - start;
555
578
  this.runner.instrumentData.duration = diff;
556
- if (diff > 150) this.Debug(chalk.default.magenta(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${diff}]`));
579
+ if (diff > this._longExecTimeoutVal) {
580
+ this.Error(chalk.default.red(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${diff}] Completed`));
581
+ this.Error(chalk.default.red(`TestCaseFhirQueryBase:ExecuteRunner(): ==> ${this._GetDetail()}`));
582
+ this.Error(chalk.default.red(`TestCaseFhirQueryBase:ExecuteRunner(): ==> Note: While not specifically an error, this is logged as an error.`));
583
+ } else if (diff > 150) {
584
+ this.Debug(chalk.default.rgb(255, 0, 255)(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${diff}] Completed`));
585
+ this.Debug(chalk.default.rgb(255, 0, 255)(`TestCaseFhirQueryBase:ExecuteRunner(): -->> ${this._GetDetail()}`));
586
+ }
587
+ const longExecTimeoutpublishTelemetry = setTimeout(() => {
588
+ this.Error(chalk.default.red(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${this._longExecTimeoutVal}] for PublishTelemetry()`));
589
+ this.Error(chalk.default.red(`TestCaseFhirQueryBase:ExecuteRunner(): ==> ${this._GetDetail()}`));
590
+ this.Error(chalk.default.red(`TestCaseFhirQueryBase:ExecuteRunner(): ==> Note: While not specifically an error, this is logged as an error.`));
591
+ }, this._longExecTimeoutVal);
557
592
  await this.PublishTelemetry();
593
+ clearInterval(longExecTimeoutpublishTelemetry);
558
594
  return true;
559
595
  };
560
596
  };