@nsshunt/ststestrunner 1.1.69 → 1.1.71

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.
@@ -154,25 +154,33 @@ var TestCaseFhirBase = class {
154
154
  GetFhirSocketClient = async () => {
155
155
  try {
156
156
  this.#clientSocketFetchCount++;
157
- const optionszz = this.runnerExecutionWorker.Options;
158
- if (optionszz) {
159
- console.log(`-----------------------------------------------------------------------------------------------------------------`);
160
- console.log(`optionszz`);
161
- console.log(optionszz);
162
- console.log(this.runnerExecutionWorker.id);
163
- console.log(`-----------------------------------------------------------------------------------------------------------------`);
164
- } else {
165
- console.log(`-----------------------------------------------------------------------------------------------------------------`);
166
- console.log(`no optionszz`);
167
- console.log(this.runnerExecutionWorker.id);
168
- console.log(`-----------------------------------------------------------------------------------------------------------------`);
169
- }
170
157
  let fhirClient = this.runnerExecutionWorker.GetFhirClient();
171
158
  if (fhirClient) {
172
- console.log(chalk.default.green(`[${this.runnerExecutionWorker.id}] Getting existing fhir client`));
159
+ this.Debug(chalk.default.green(`[${this.runnerExecutionWorker.id}] Getting existing fhir client`));
173
160
  return fhirClient;
174
161
  }
175
- console.log(chalk.default.red(`[${this.runnerExecutionWorker.id}] fhir client does not exist - setting up new client`));
162
+ if (this.runnerExecutionWorker.GetOnHold("fhirclient") === true) {
163
+ 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
+ try {
165
+ const start = performance.now();
166
+ await this.runnerExecutionWorker.WaitOnHold("fhirclient", 6e4);
167
+ this.Debug(chalk.default.yellow(`[${this.runnerExecutionWorker.id}] hold (lock) released after: [${performance.now() - start}ms]`));
168
+ const fhirClient = this.runnerExecutionWorker.GetFhirClient();
169
+ if (fhirClient) {
170
+ this.Debug(chalk.default.green(`[${this.runnerExecutionWorker.id}] Getting existing fhir client (post hold release)`));
171
+ return fhirClient;
172
+ } else {
173
+ this.Error(chalk.default.red(`[${this.runnerExecutionWorker.id}] Could not get existing fhir client (post hold release)`));
174
+ this.Error(chalk.default.red(`continue anyway ...`));
175
+ }
176
+ } catch (error) {
177
+ this.Error(chalk.default.red(`GetFhirSocketClient(): Error: [${error}]`));
178
+ }
179
+ }
180
+ const start = performance.now();
181
+ this.Debug(chalk.default.yellow(`[${this.runnerExecutionWorker.id}] fhir client does not exist - setting up new client`));
182
+ this.Debug(chalk.default.yellow(`[${this.runnerExecutionWorker.id}] setting hold (lock)`));
183
+ this.runnerExecutionWorker.SetOnHold("fhirclient");
176
184
  const fhirOptions = this.#options.fhirOptions;
177
185
  const options = {
178
186
  fhirServerEndpoint: fhirOptions.stsfhirserverendpoint,
@@ -192,8 +200,10 @@ var TestCaseFhirBase = class {
192
200
  if (this.runner.options.fhirOptions.stsfhirsocketclientmode === "socket-client-all-in-one") fhirClient = new _nsshunt_stsfhirclient.FhirSocketClientAllInOne("FhirSocketClient", options);
193
201
  else fhirClient = new _nsshunt_stsfhirclient.FhirSocketClientIndividual("FhirSocketClient", options);
194
202
  await fhirClient.WaitForSocketConnected();
195
- console.log(chalk.default.red(`[${this.runnerExecutionWorker.id}] setting fhir client into object`));
203
+ this.Debug(chalk.default.yellow(`[${this.runnerExecutionWorker.id}] setting fhir client into object`));
196
204
  this.runnerExecutionWorker.SetFhirClient(fhirClient);
205
+ this.runnerExecutionWorker.ReleaseOnHold("fhirclient");
206
+ this.Debug(chalk.default.yellow(`[${this.runnerExecutionWorker.id}] release hold (lock) Time taken for socket connection and set object: [${performance.now() - start}ms]`));
197
207
  return fhirClient;
198
208
  } catch (error) {
199
209
  this.LogErrorMessage(error);
@@ -35824,6 +35834,7 @@ var WorkerFhirTestCases = class extends _nsshunt_stsrunnerframework.AbstractRunn
35824
35834
  _resourceDataGenerator;
35825
35835
  fhirClient = void 0;
35826
35836
  _id = crypto.randomUUID();
35837
+ _onHoldKeys = {};
35827
35838
  constructor(options) {
35828
35839
  super();
35829
35840
  this._options = options;
@@ -35860,6 +35871,25 @@ var WorkerFhirTestCases = class extends _nsshunt_stsrunnerframework.AbstractRunn
35860
35871
  myresponsepreterminate: `I got: [${JSON.stringify(messagePayload.payload.data)}]`
35861
35872
  };
35862
35873
  }
35874
+ GetOnHold = (holdKey) => {
35875
+ if (this._onHoldKeys[holdKey]) return true;
35876
+ return false;
35877
+ };
35878
+ WaitOnHold = async (holdKey, timeout) => {
35879
+ const start = performance.now();
35880
+ for (;;) {
35881
+ if (this._onHoldKeys[holdKey]) await (0, _nsshunt_stsutils.Sleep)(100);
35882
+ else break;
35883
+ if (performance.now() - start > timeout) throw new Error(`WaitOnHold timeout: [${timeout}] reached.`);
35884
+ }
35885
+ return true;
35886
+ };
35887
+ SetOnHold = (holdKey) => {
35888
+ this._onHoldKeys[holdKey] = true;
35889
+ };
35890
+ ReleaseOnHold = (holdKey) => {
35891
+ delete this._onHoldKeys[holdKey];
35892
+ };
35863
35893
  };
35864
35894
  //#endregion
35865
35895
  exports.WorkerFhirTestCases = WorkerFhirTestCases;