@nsshunt/stsrunnerframework 2.0.29 → 2.0.31

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.
package/dist/index.cjs CHANGED
@@ -3686,18 +3686,13 @@ var RunnerInstance = class {
3686
3686
  * @throws Re-throws any error after logging.
3687
3687
  */
3688
3688
  toRunnerCore() {
3689
- try {
3690
- const retVal = {
3691
- id: this.id,
3692
- iteration: this.iteration,
3693
- state: this.state
3694
- };
3695
- if (this.runnerPlanRuntime) retVal.runnerPlanRuntime = { ...this.runnerPlanRuntime };
3696
- return retVal;
3697
- } catch (error) {
3698
- _nsshunt_stsutils.defaultLogger.error(`toRunnerCore(): Error: [${error}]`);
3699
- throw error;
3700
- }
3689
+ const retVal = {
3690
+ id: this.id,
3691
+ iteration: this.iteration,
3692
+ state: this.state
3693
+ };
3694
+ if (this.runnerPlanRuntime) retVal.runnerPlanRuntime = { ...this.runnerPlanRuntime };
3695
+ return retVal;
3701
3696
  }
3702
3697
  /**
3703
3698
  * Send a command for this runner to the owning worker via the message broker.
@@ -4544,7 +4539,7 @@ var WorkerInstance = class {
4544
4539
  });
4545
4540
  return workerCopy;
4546
4541
  } catch (error) {
4547
- _nsshunt_stsutils.defaultLogger.error(`toWorkerCore(): Error: [${error}]`);
4542
+ this.#logger.error(`toWorkerCore(): Error: [${error}]`);
4548
4543
  throw error;
4549
4544
  }
4550
4545
  }
@@ -9980,6 +9975,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
9980
9975
  #socket;
9981
9976
  #reconnectTimeout = 2e3;
9982
9977
  #ackTimeout = 5e3;
9978
+ #reconnectTimeoutVal = void 0;
9983
9979
  constructor(name) {
9984
9980
  super();
9985
9981
  this.#name = name;
@@ -10052,7 +10048,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10052
10048
  return this;
10053
10049
  }
10054
10050
  SetupSocket() {
10055
- if (!this.#address) throw new Error(`SocketIoClientHelper:SetupSocket(): Error: [address not provided]`);
10051
+ if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided]`);
10056
10052
  this.#EstablishSocketConnect();
10057
10053
  return this;
10058
10054
  }
@@ -10062,17 +10058,20 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10062
10058
  EngineReconnect(attempt) {}
10063
10059
  #EstablishSocketConnect() {
10064
10060
  if (this.#socket !== void 0) {
10065
- if (this.#socket.connected === true) this.#socket.disconnect();
10066
- this.#socket = void 0;
10067
- if (_nsshunt_stsutils.isNode) setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10068
- else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10061
+ this.ResetSocket();
10062
+ if (_nsshunt_stsutils.isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10063
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10069
10064
  return;
10070
10065
  }
10071
10066
  let socketOptions;
10072
10067
  if (_nsshunt_stsutils.isNode) {
10073
10068
  socketOptions = { transports: ["websocket"] };
10074
10069
  if (this.#agentManager) {
10075
- if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided when using agentManager]`);
10070
+ if (!this.#address) {
10071
+ const message = `SocketIoClient:#EstablishSocketConnect(): Error: [address not provided when using agentManager]`;
10072
+ this.LogErrorMessage(message);
10073
+ throw new Error(message);
10074
+ }
10076
10075
  socketOptions.agent = this.#agentManager.GetAgent(this.#address);
10077
10076
  }
10078
10077
  } else socketOptions = { transports: ["websocket"] };
@@ -10083,30 +10082,30 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10083
10082
  if (this.#socketIoCustomPath && this.#socketIoCustomPath.localeCompare("") !== 0) socketOptions.path = this.#socketIoCustomPath;
10084
10083
  this.#socket = lookup(this.#address, socketOptions);
10085
10084
  this.#socket.io.on("error", (err) => {
10086
- this.LogErrorMessage(`socketDetail.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
10085
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
10087
10086
  this.EngineError(err);
10088
10087
  });
10089
10088
  this.#socket.io.on("reconnect_error", (err) => {
10090
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
10089
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
10091
10090
  this.EngineReconnectError(err);
10092
10091
  });
10093
10092
  this.#socket.on("connect_error", (err) => {
10094
- this.LogErrorMessage(`socketDetail.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
10093
+ this.LogErrorMessage(`SocketIoClient.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
10095
10094
  this.EngineConnectError(err);
10096
10095
  });
10097
10096
  this.#socket.io.on("reconnect", (attempt) => {
10098
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
10097
+ this.LogErrorMessage(`SocketIoClient:socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
10099
10098
  this.EngineReconnect(attempt);
10100
10099
  });
10101
10100
  this.#socket.on("connect", () => {
10102
10101
  if (this.#socket) {
10103
- this.LogDebugMessage(`Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
10102
+ this.LogDebugMessage(`SocketIoClient:on("connect"): Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
10104
10103
  setTimeout(() => {
10105
10104
  this.SocketConnect(this.#socket);
10106
10105
  }, 0);
10107
10106
  this.SetupSocketEvents(this.#socket);
10108
10107
  } else {
10109
- const errorMessage = "Could not get socket object from socket.io, Address: [${socketDetail.address}]";
10108
+ const errorMessage = "SocketIoClient:on(\"connect\"): Could not get socket object from socket.io, Address: [${socketDetail.address}]";
10110
10109
  this.LogErrorMessage(errorMessage);
10111
10110
  this.SocketConnectError(new Error(errorMessage));
10112
10111
  }
@@ -10116,33 +10115,50 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
10116
10115
  this.SocketDisconnect(reason);
10117
10116
  switch (reason) {
10118
10117
  case "io server disconnect":
10119
- this.LogDebugMessage("The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
10120
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
10121
- this.#socket = void 0;
10122
- if (_nsshunt_stsutils.isNode) {
10123
- if (this.#agentManager) this.#agentManager.ResetAgent();
10124
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10125
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10118
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
10119
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
10120
+ this.ResetSocket();
10121
+ if (_nsshunt_stsutils.isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10122
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10126
10123
  break;
10127
10124
  case "io client disconnect":
10128
- this.LogDebugMessage("The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
10129
- this.LogDebugMessage("The connection will not be re-established automatically.");
10125
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
10126
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will not be re-established automatically.");
10127
+ this.ResetSocket();
10130
10128
  break;
10131
10129
  case "transport close":
10132
10130
  case "ping timeout":
10133
10131
  case "transport error":
10134
- this.LogDebugMessage(`Server unexpectedly disconnected. Reason: [${reason}]`);
10135
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
10136
- if (this.#socket) this.#socket.disconnect();
10137
- this.#socket = void 0;
10138
- if (_nsshunt_stsutils.isNode) {
10139
- if (this.#agentManager) this.#agentManager?.ResetAgent();
10140
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10141
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10132
+ this.LogDebugMessage(`SocketIoClient:on("disconnect"): Server unexpectedly disconnected. Reason: [${reason}]`);
10133
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
10134
+ this.ResetSocket();
10135
+ if (_nsshunt_stsutils.isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
10136
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
10142
10137
  break;
10143
10138
  }
10144
10139
  });
10145
10140
  }
10141
+ ResetSocket = () => {
10142
+ try {
10143
+ if (this.#reconnectTimeoutVal !== void 0) {
10144
+ clearTimeout(this.#reconnectTimeoutVal);
10145
+ this.#reconnectTimeoutVal = void 0;
10146
+ }
10147
+ if (this.#socket) {
10148
+ this.#socket.removeAllListeners();
10149
+ this.#socket.io.removeAllListeners();
10150
+ if (this.#socket.connected === true) this.#socket.disconnect();
10151
+ if (_nsshunt_stsutils.isNode) {
10152
+ if (this.#agentManager) this.#agentManager.ResetAgent();
10153
+ }
10154
+ this.#socket = void 0;
10155
+ }
10156
+ } catch (error) {
10157
+ const errorMessage = `SocketIoClient:ResetSocket(): Error: [${error}]`;
10158
+ this.LogErrorMessage(errorMessage);
10159
+ this.SocketConnectError(new Error(errorMessage));
10160
+ }
10161
+ };
10146
10162
  };
10147
10163
  //#endregion
10148
10164
  //#region src/wsevents.ts
@@ -10273,7 +10289,7 @@ var NodeAgent = class extends SocketIoClient {
10273
10289
  };
10274
10290
  _Start = async () => {
10275
10291
  this._EmitEvent("Starting", {});
10276
- this.WithAddress(this._options.nodeAgentEndpoint).WithLogger(_nsshunt_stsutils.defaultLogger).WithSocketIoCustomPath(this._options.nodeAgentSocketIoCustomPath).WithAckTimeout(5e3);
10292
+ this.WithAddress(this._options.nodeAgentEndpoint).WithLogger(this._options.logger).WithSocketIoCustomPath(this._options.nodeAgentSocketIoCustomPath).WithAckTimeout(5e3);
10277
10293
  if (this._options.agentManager) this.WithAgentManager(this._options.agentManager);
10278
10294
  this.#info(chalk.yellow(`_Start():STS Test Runner Service Instance.`));
10279
10295
  this.#info(chalk.yellow(`_Start():This service instance emulates instances of the ststestrunnernode service.`));