@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.
@@ -31,6 +31,7 @@ var TestCaseFhirBase = class {
31
31
  #resetSocketClientTrigger = 50;
32
32
  #clientSocketFetchCount = 0;
33
33
  #authAgentManager;
34
+ _authMaxTimeout = 5e3;
34
35
  accessTokenTime = performance.now();
35
36
  newTokenLimitTime = 30;
36
37
  restFhirClient = null;
@@ -132,10 +133,7 @@ var TestCaseFhirBase = class {
132
133
  try {
133
134
  this.#clientSocketFetchCount++;
134
135
  let fhirClient = this.runnerExecutionWorker.GetFhirClient();
135
- if (fhirClient) {
136
- this.Debug(chalk.green(`[${this.runnerExecutionWorker.id}] Getting existing fhir client`));
137
- return fhirClient;
138
- }
136
+ if (fhirClient) return fhirClient;
139
137
  if (this.runnerExecutionWorker.GetOnHold("fhirclient") === true) {
140
138
  this.Debug(chalk.magenta(`[${this.runnerExecutionWorker.id}] fhir client does not exist - some other client setting up the new client (on hold/lock) - waiting ...`));
141
139
  try {
@@ -183,20 +181,17 @@ var TestCaseFhirBase = class {
183
181
  this.Debug(chalk.yellow(`[${this.runnerExecutionWorker.id}] release hold (lock) Time taken for socket connection and set object: [${performance.now() - start}ms]`));
184
182
  return fhirClient;
185
183
  } catch (error) {
186
- this.LogErrorMessage(error);
184
+ this.Error(error);
187
185
  throw error;
188
186
  }
189
187
  };
190
188
  #LogMessage = (message) => {};
191
- LogErrorMessage = (message) => {
192
- this.#runner.instrumentData.message.push(chalk.red(`${message}`));
193
- };
194
189
  Debug = (message) => {
195
190
  this.#runnerExecutionWorker.logger.debug(message);
196
191
  };
197
192
  Error = (message) => {
198
- this.LogErrorMessage(message);
199
193
  this.#runnerExecutionWorker.logger.error(message);
194
+ this.#runner.instrumentData.message.push(chalk.red(`${message}`));
200
195
  };
201
196
  Warning = (message) => {
202
197
  this.#runnerExecutionWorker.logger.warn(message);
@@ -238,13 +233,9 @@ var TestCaseFhirBase = class {
238
233
  const match = uri.match(this.#originRegex);
239
234
  return match ? match[1] : null;
240
235
  };
241
- GetAPITokenFromAuthServerUsingScope = async (options, errorCb) => {
236
+ GetAPITokenFromAuthServerUsingScope = async (options) => {
242
237
  const { scope, clientId, authClientSecret, endPoint } = options;
243
238
  let stage = "1";
244
- const invokeErrorCb = (error) => {
245
- this.Debug(error);
246
- errorCb(error);
247
- };
248
239
  try {
249
240
  stage = "2";
250
241
  const scopes = scope.split(" ");
@@ -271,10 +262,7 @@ var TestCaseFhirBase = class {
271
262
  }
272
263
  }
273
264
  stage = "4";
274
- if (error) {
275
- invokeErrorCb(error);
276
- return "";
277
- }
265
+ if (error) throw error;
278
266
  stage = "5";
279
267
  const payload = {
280
268
  client_id: clientId,
@@ -303,11 +291,8 @@ var TestCaseFhirBase = class {
303
291
  this.#runner.instrumentData.authenticationCount++;
304
292
  stage = "7";
305
293
  if (retVal.status) {
306
- if (retVal.status !== 200) this.Debug(chalk.magenta(`Error (AuthUtilsNode:GetAPITokenFromServer): Invalid response from server: [${retVal.status}]`));
307
- } else {
308
- invokeErrorCb(new Error(chalk.red(`Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.status)`)));
309
- return "";
310
- }
294
+ if (retVal.status !== 200) this.Warning(chalk.magenta(`TestCaseFhirBase:GetAPITokenFromAuthServerUsingScope(): Invalid response from server: [${retVal.status}]`));
295
+ } else throw new Error(chalk.red(`No retVal.status)`));
311
296
  stage = "8";
312
297
  if (retVal.data) {
313
298
  stage = "9";
@@ -316,13 +301,11 @@ var TestCaseFhirBase = class {
316
301
  return retVal.data.access_token;
317
302
  } else {
318
303
  stage = "13";
319
- invokeErrorCb(/* @__PURE__ */ new Error(`Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.data.access_token)`));
320
- return "";
304
+ throw new Error(`No retVal.data.access_token)`);
321
305
  }
322
306
  } else {
323
307
  stage = "14";
324
- invokeErrorCb(/* @__PURE__ */ new Error(`Error (AuthUtilsNode:GetAPITokenFromServer:No retVal.data)`));
325
- return "";
308
+ throw new Error(`No retVal.data)`);
326
309
  }
327
310
  } catch (error) {
328
311
  this.Error(error);
@@ -332,34 +315,64 @@ var TestCaseFhirBase = class {
332
315
  } catch (error) {
333
316
  details = `Could not JSON.stringify(error.response.data)`;
334
317
  }
335
- invokeErrorCb(/* @__PURE__ */ new Error(`Error (AuthUtilsNode:GetAPITokenFromServer:catch): [${error}], Stage: [${stage}], Details: [${details}]`));
336
- return "";
318
+ error.message = `TestCaseFhirBase:GetAPITokenFromAuthServerUsingScope(): Error: [${error}], Stage: [${stage}], Details: [${details}]`;
319
+ throw error;
337
320
  }
338
321
  };
339
- GetAccessTokenForSocketClientAccess = () => {
340
- const scopes = `api://fb6513e4-16fe-4931-bed8-33b82b404a14/_.stsfhir5:SocketConnection`.split(" ").sort().join(" ");
341
- const authendpointUrl = `${this.#options.authOptions.asendpoint}:${this.#options.authOptions.asport}`;
342
- return this.GetAPITokenFromAuthServerUsingScope({
343
- clientId: "d8277fce-bb48-44c2-bbf1-257fe13a444b",
344
- authClientSecret: "64e3ef37-c7b8-4cb1-880a-e6ad3ab36e3c",
345
- scope: scopes,
346
- endPoint: authendpointUrl
347
- }, (error) => this.LogErrorMessage(error));
322
+ GetAccessTokenForSocketClientAccess = async () => {
323
+ const timeout = setTimeout(() => {
324
+ this.Warning(`TestCaseFhirBase:GetAccessTokenForSocketClientAccess(): Timeout: [${this._authMaxTimeout}] exceeded for getting access token ...`);
325
+ }, this._authMaxTimeout);
326
+ const start = performance.now();
327
+ try {
328
+ const scopes = `api://fb6513e4-16fe-4931-bed8-33b82b404a14/_.stsfhir5:SocketConnection`.split(" ").sort().join(" ");
329
+ const authendpointUrl = `${this.#options.authOptions.asendpoint}:${this.#options.authOptions.asport}`;
330
+ const retVal = await this.GetAPITokenFromAuthServerUsingScope({
331
+ clientId: "d8277fce-bb48-44c2-bbf1-257fe13a444b",
332
+ authClientSecret: "64e3ef37-c7b8-4cb1-880a-e6ad3ab36e3c",
333
+ scope: scopes,
334
+ endPoint: authendpointUrl
335
+ });
336
+ clearTimeout(timeout);
337
+ const totalTime = performance.now() - start;
338
+ if (totalTime > this._authMaxTimeout) this.Warning(chalk.magenta(`TestCaseFhirBase:GetAccessTokenForSocketClientAccess(): The total time for getting the access token: [${totalTime}]`));
339
+ return retVal;
340
+ } catch (error) {
341
+ clearTimeout(timeout);
342
+ error.message = `TestCaseFhirBase:GetAccessTokenForSocketClientAccess(): Error: [${error}], Duration until error: [${performance.now() - start}]`;
343
+ this.Error(error);
344
+ return "";
345
+ }
348
346
  };
349
347
  GetAccessToken = async () => {
350
- if (performance.now() - this.accessTokenTime > this.newTokenLimitTime * 1e3) this.#accesssToken = null;
351
- if (this.#accesssToken) return this.#accesssToken;
352
- const scopes = `api://fb6513e4-16fe-4931-bed8-33b82b404a14/_.stsfhir5:All`.split(" ").sort().join(" ");
353
- const authendpointUrl = `${this.#options.authOptions.asendpoint}:${this.#options.authOptions.asport}`;
354
- const retVal = await this.GetAPITokenFromAuthServerUsingScope({
355
- clientId: "d8277fce-bb48-44c2-bbf1-257fe13a444b",
356
- authClientSecret: "64e3ef37-c7b8-4cb1-880a-e6ad3ab36e3c",
357
- scope: scopes,
358
- endPoint: authendpointUrl
359
- }, (error) => this.LogErrorMessage(error));
360
- this.accessTokenTime = performance.now();
361
- this.#accesssToken = retVal;
362
- return retVal;
348
+ let timeout = void 0;
349
+ let start = performance.now();
350
+ try {
351
+ if (start - this.accessTokenTime > this.newTokenLimitTime * 1e3) this.#accesssToken = null;
352
+ if (this.#accesssToken) return this.#accesssToken;
353
+ timeout = setTimeout(() => {
354
+ this.Warning(chalk.magenta(`TestCaseFhirBase:GetAccessToken(): Timeout: [${this._authMaxTimeout}] exceeded for getting access token ...`));
355
+ }, this._authMaxTimeout);
356
+ const scopes = `api://fb6513e4-16fe-4931-bed8-33b82b404a14/_.stsfhir5:All`.split(" ").sort().join(" ");
357
+ const authendpointUrl = `${this.#options.authOptions.asendpoint}:${this.#options.authOptions.asport}`;
358
+ const retVal = await this.GetAPITokenFromAuthServerUsingScope({
359
+ clientId: "d8277fce-bb48-44c2-bbf1-257fe13a444b",
360
+ authClientSecret: "64e3ef37-c7b8-4cb1-880a-e6ad3ab36e3c",
361
+ scope: scopes,
362
+ endPoint: authendpointUrl
363
+ });
364
+ this.accessTokenTime = performance.now();
365
+ this.#accesssToken = retVal;
366
+ if (timeout) clearTimeout(timeout);
367
+ const totalTime = performance.now() - start;
368
+ if (totalTime > this._authMaxTimeout) this.Warning(chalk.magenta(`TestCaseFhirBase:GetAccessToken(): The total time for getting the access token: [${totalTime}]`));
369
+ return retVal;
370
+ } catch (error) {
371
+ if (timeout) clearTimeout(timeout);
372
+ error.message = `TestCaseFhirBase:GetAccessToken(): Error: [${error}], Duration until error: [${performance.now() - start}]`;
373
+ this.Error(error);
374
+ return "";
375
+ }
363
376
  };
364
377
  GetPersonRecord = async (prefix, index, version) => {
365
378
  const { workerIndex, runnerIndex, runId } = this.#options;
@@ -491,6 +504,7 @@ var TestCaseFhirBase = class {
491
504
  //#endregion
492
505
  //#region src/libmodule/testCaseFhirQueryBase.ts
493
506
  var TestCaseFhirQueryBase = class extends TestCaseFhirBase {
507
+ _longExecTimeoutVal = 5e3;
494
508
  constructor(workerInstance, runner) {
495
509
  super(workerInstance, runner);
496
510
  }
@@ -511,17 +525,26 @@ var TestCaseFhirQueryBase = class extends TestCaseFhirBase {
511
525
  if (this.runner.instrumentData.requestCount % this.runner.options.clientResetMod === 0) this.#ResetClient("#ResetClient triggered");
512
526
  }
513
527
  };
528
+ _GetDetail = () => {
529
+ return `testType: [${this.runner.options.testType}], description: [${this.runner.options.description}], workerManagerId: [${this.runner.workerManagerId}], Iteration: [${this.runner.iteration}]`;
530
+ };
514
531
  ExecuteRunner = async () => {
515
- 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}`);
532
+ if (this.runner.iteration % 100 === 0) this.Debug(`TestCaseFhirQueryBase:ExecuteRunner(): ${this._GetDetail()}`);
516
533
  const start = performance.now();
517
534
  this.runner.instrumentData.activeRequestCount++;
518
535
  this.#CheckResetClient();
536
+ const longExecTimeout = setTimeout(() => {
537
+ this.Debug(chalk.magenta(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${this._longExecTimeoutVal}] exceeded - still waiting ...`));
538
+ this.Debug(chalk.magenta(`TestCaseFhirQueryBase:ExecuteRunner(): ==> ${this._GetDetail()}`));
539
+ }, this._longExecTimeoutVal);
519
540
  try {
520
541
  await this.ExecuteQuery();
542
+ clearInterval(longExecTimeout);
521
543
  } catch (error) {
544
+ clearInterval(longExecTimeout);
522
545
  this.runner.instrumentData.errorCount++;
523
- const message = `TestCaseFhirQueryBase:ExecuteRunner(): TestType: [${this.runner.options.testType}], Error: [${error}]`;
524
- this.LogErrorMessage(message);
546
+ const message = `TestCaseFhirQueryBase:ExecuteRunner(): Error: [${error}], Error Count: [${this.runner.instrumentData.errorCount}], ${this._GetDetail()}`;
547
+ this.Error(message);
525
548
  this.#ResetClient(message);
526
549
  }
527
550
  this.runner.instrumentData.coreCount = 1;
@@ -530,8 +553,21 @@ var TestCaseFhirQueryBase = class extends TestCaseFhirBase {
530
553
  this.runner.instrumentData.activeRequestCount--;
531
554
  const diff = performance.now() - start;
532
555
  this.runner.instrumentData.duration = diff;
533
- if (diff > 150) this.Debug(chalk.magenta(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${diff}]`));
556
+ if (diff > this._longExecTimeoutVal) {
557
+ this.Error(chalk.red(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${diff}] Completed`));
558
+ this.Error(chalk.red(`TestCaseFhirQueryBase:ExecuteRunner(): ==> ${this._GetDetail()}`));
559
+ this.Error(chalk.red(`TestCaseFhirQueryBase:ExecuteRunner(): ==> Note: While not specifically an error, this is logged as an error.`));
560
+ } else if (diff > 150) {
561
+ this.Debug(chalk.rgb(255, 0, 255)(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${diff}] Completed`));
562
+ this.Debug(chalk.rgb(255, 0, 255)(`TestCaseFhirQueryBase:ExecuteRunner(): -->> ${this._GetDetail()}`));
563
+ }
564
+ const longExecTimeoutpublishTelemetry = setTimeout(() => {
565
+ this.Error(chalk.red(`TestCaseFhirQueryBase:ExecuteRunner(): *** ==> Long execution: [${this._longExecTimeoutVal}] for PublishTelemetry()`));
566
+ this.Error(chalk.red(`TestCaseFhirQueryBase:ExecuteRunner(): ==> ${this._GetDetail()}`));
567
+ this.Error(chalk.red(`TestCaseFhirQueryBase:ExecuteRunner(): ==> Note: While not specifically an error, this is logged as an error.`));
568
+ }, this._longExecTimeoutVal);
534
569
  await this.PublishTelemetry();
570
+ clearInterval(longExecTimeoutpublishTelemetry);
535
571
  return true;
536
572
  };
537
573
  };