@nsshunt/stsappframework 3.1.209 → 3.1.210

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.
Files changed (81) hide show
  1. package/build.sh +5 -0
  2. package/dist/index.js +0 -5
  3. package/dist/index.js.map +1 -1
  4. package/dist/masterprocessbase.js +3 -53
  5. package/dist/masterprocessbase.js.map +1 -1
  6. package/dist/processbase.js +4 -17
  7. package/dist/processbase.js.map +1 -1
  8. package/dist/testing/app.js +0 -457
  9. package/dist/testing/app.js.map +1 -1
  10. package/dist/workerprocessbase.js +1 -36
  11. package/dist/workerprocessbase.js.map +1 -1
  12. package/package.json +14 -13
  13. package/src/commonTypes.ts +2 -2
  14. package/src/index.ts +0 -5
  15. package/src/masterprocessbase.ts +4 -18
  16. package/src/processbase.ts +7 -22
  17. package/src/testing/app.ts +1 -530
  18. package/src/workerprocessbase.ts +1 -40
  19. package/types/commonTypes.d.ts +0 -2
  20. package/types/commonTypes.d.ts.map +1 -1
  21. package/types/index.d.ts +0 -5
  22. package/types/index.d.ts.map +1 -1
  23. package/types/masterprocessbase.d.ts.map +1 -1
  24. package/types/processbase.d.ts +0 -2
  25. package/types/processbase.d.ts.map +1 -1
  26. package/types/workerprocessbase.d.ts.map +1 -1
  27. package/dist/ipcMessageHandler.js +0 -189
  28. package/dist/ipcMessageHandler.js.map +0 -1
  29. package/dist/ipcMessageManager.js +0 -146
  30. package/dist/ipcMessageManager.js.map +0 -1
  31. package/dist/ipcMessageProcessorPrimary.js +0 -65
  32. package/dist/ipcMessageProcessorPrimary.js.map +0 -1
  33. package/dist/ipcMessageProcessorWorker.js +0 -61
  34. package/dist/ipcMessageProcessorWorker.js.map +0 -1
  35. package/dist/messagehandling/webWorkerMessageHandler.js +0 -280
  36. package/dist/messagehandling/webWorkerMessageHandler.js.map +0 -1
  37. package/dist/messagehandling/webWorkerSupport.js +0 -62
  38. package/dist/messagehandling/webWorkerSupport.js.map +0 -1
  39. package/dist/redisMessageHandler.js +0 -305
  40. package/dist/redisMessageHandler.js.map +0 -1
  41. package/dist/redisMessageHandler.test.js +0 -129
  42. package/dist/redisMessageHandler.test.js.map +0 -1
  43. package/dist/testing/app_ipc_legacy.js +0 -84
  44. package/dist/testing/app_ipc_legacy.js.map +0 -1
  45. package/dist/testing/app_ipcex.js +0 -69
  46. package/dist/testing/app_ipcex.js.map +0 -1
  47. package/dist/testing/app_ww.js +0 -54
  48. package/dist/testing/app_ww.js.map +0 -1
  49. package/src/ipcMessageHandler.ts +0 -201
  50. package/src/ipcMessageManager.ts +0 -171
  51. package/src/ipcMessageProcessorPrimary.ts +0 -76
  52. package/src/ipcMessageProcessorWorker.ts +0 -70
  53. package/src/messagehandling/webWorkerMessageHandler.ts +0 -341
  54. package/src/messagehandling/webWorkerSupport.ts +0 -66
  55. package/src/redisMessageHandler.test.ts +0 -157
  56. package/src/redisMessageHandler.ts +0 -371
  57. package/src/testing/app_ipc_legacy.ts +0 -87
  58. package/src/testing/app_ipcex.ts +0 -68
  59. package/src/testing/app_ww.ts +0 -68
  60. package/types/ipcMessageHandler.d.ts +0 -30
  61. package/types/ipcMessageHandler.d.ts.map +0 -1
  62. package/types/ipcMessageManager.d.ts +0 -30
  63. package/types/ipcMessageManager.d.ts.map +0 -1
  64. package/types/ipcMessageProcessorPrimary.d.ts +0 -26
  65. package/types/ipcMessageProcessorPrimary.d.ts.map +0 -1
  66. package/types/ipcMessageProcessorWorker.d.ts +0 -25
  67. package/types/ipcMessageProcessorWorker.d.ts.map +0 -1
  68. package/types/messagehandling/webWorkerMessageHandler.d.ts +0 -52
  69. package/types/messagehandling/webWorkerMessageHandler.d.ts.map +0 -1
  70. package/types/messagehandling/webWorkerSupport.d.ts +0 -6
  71. package/types/messagehandling/webWorkerSupport.d.ts.map +0 -1
  72. package/types/redisMessageHandler.d.ts +0 -51
  73. package/types/redisMessageHandler.d.ts.map +0 -1
  74. package/types/redisMessageHandler.test.d.ts +0 -2
  75. package/types/redisMessageHandler.test.d.ts.map +0 -1
  76. package/types/testing/app_ipc_legacy.d.ts +0 -2
  77. package/types/testing/app_ipc_legacy.d.ts.map +0 -1
  78. package/types/testing/app_ipcex.d.ts +0 -2
  79. package/types/testing/app_ipcex.d.ts.map +0 -1
  80. package/types/testing/app_ww.d.ts +0 -2
  81. package/types/testing/app_ww.d.ts.map +0 -1
@@ -1,341 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF */ // --> OFF
2
- import { TinyEmitter } from "tiny-emitter";
3
- import { ISTSLogger, JSONObject } from '@nsshunt/stsutils'
4
-
5
- import { IIPCMessageProcessorIPCPayload, IServiceProcessContext, ProcessOptions } from '../commonTypes'
6
-
7
- import { IPCMessageManager, IPCMessageManagerOptions } from '../ipcMessageManager'
8
-
9
- import chalk from 'chalk';
10
-
11
- import { MessagePort } from 'worker_threads';
12
-
13
- export interface IWebWorderMessageHandlerOptions {
14
- logger: ISTSLogger
15
- role: 'SERVER' | 'CLIENT'
16
- namespace: string
17
- groups: string[]
18
- ignoreEvents?: string[]
19
- processOptions?: ProcessOptions
20
- messagePort: MessagePort
21
- }
22
-
23
- export interface IClientRecord {
24
- id: string
25
- clientConnected: Date
26
- pingCount: number
27
- timeout: NodeJS.Timeout
28
- groups: string[]
29
- serviceProcessContext?: IServiceProcessContext
30
- }
31
-
32
- export interface IEventPayload {
33
- __eventName: string
34
- args: any[]
35
- }
36
-
37
- export interface IEventRecord {
38
- event: string
39
- callback: any,
40
- ctx?: any
41
- }
42
-
43
- export interface IPingData {
44
- id: string
45
- groups: string[]
46
- serviceProcessContext?: IServiceProcessContext
47
- }
48
-
49
- export class WebWorkerMessageHandler extends TinyEmitter {
50
- #ipcMessageManager: IPCMessageManager | null = null;
51
- #options: IWebWorderMessageHandlerOptions;
52
- #events: Record<string, IEventRecord> = { };
53
- #clients: Record<string, IClientRecord> = { };
54
- #pingTimeout: NodeJS.Timeout | null = null;
55
- #messagePort: MessagePort;
56
-
57
- constructor(options: IWebWorderMessageHandlerOptions) {
58
- super();
59
- this.#options = options;
60
- this.#messagePort = options.messagePort;
61
-
62
- this.SetupPrimary();
63
-
64
- if (this.#options.role.localeCompare('CLIENT') === 0) {
65
- const ping = () => {
66
- this.#pingTimeout = setTimeout(() => {
67
- const pingData: IPingData = {
68
- id: (this.#ipcMessageManager as IPCMessageManager).id,
69
- groups: this.#options.groups,
70
- }
71
- if (this.#options.processOptions) {
72
- pingData.serviceProcessContext = this.#options.processOptions.serviceProcessContext;
73
- }
74
- this.emit('ping', pingData, (response: any) => { });
75
- ping();
76
- }, 1000).unref();
77
- }
78
- ping();
79
- } else {
80
- this.on('ping', (pingData: IPingData, callback: any) => {
81
- const { id, groups, serviceProcessContext } = pingData;
82
- if (this.#clients[id]) {
83
- clearTimeout(this.#clients[id].timeout);
84
- this.#clients[id].pingCount++;
85
- this.#clients[id].timeout = setTimeout(() => {
86
- delete this.#clients[id];
87
- }, 2000);
88
- this.#clients[id].groups = groups;
89
- this.#clients[id].serviceProcessContext = serviceProcessContext;
90
- } else {
91
- this.#clients[id] = {
92
- id,
93
- clientConnected: new Date(),
94
- pingCount: 0,
95
- timeout: setTimeout(() => {
96
- delete this.#clients[id];
97
- }, 2000),
98
- groups,
99
- serviceProcessContext
100
- }
101
- }
102
- callback('ok');
103
- });
104
- }
105
- }
106
-
107
- #processRawMessage = (rawmessage: string) => {
108
- const message = JSON.parse(rawmessage);
109
- this.#ipcMessageManager?.ProcessMessage(message, { });
110
- }
111
-
112
- get clients(): Record<string, IClientRecord> {
113
- return this.#clients;
114
- }
115
-
116
- get groups(): string[] {
117
- return this.#options.groups;
118
- }
119
-
120
- AddGroup = (group: string) => {
121
- const index = this.#options.groups.indexOf(group);
122
- if (index === -1) {
123
- this.#options.groups.push(group);
124
- }
125
- }
126
-
127
- RemoveGroup = (group: string) => {
128
- const removeIndex = this.#options.groups.indexOf(group);
129
- if (removeIndex !== -1) {
130
- this.#options.groups.splice(removeIndex, 1);
131
- }
132
- }
133
-
134
- SetupPrimary = () => {
135
- const ipcMessageManagerOptions: IPCMessageManagerOptions = {
136
- logger: this.#options.logger,
137
- requestResponseMessageTimeout: 5000,
138
- namespace: this.#options.namespace,
139
- role: this.#options.role,
140
- messageSender: this.#messageSender,
141
- groups: this.#options.groups,
142
- // This method is used to calculate if all responses have been received from multiple clients (broadcast)
143
- // returns true/false.
144
- ProcessResponseMessage: this.#ProcessResponseMessage,
145
- // This gets called when an event is received from a message receiver (when ProcessMessage is invoked from the receiver event handler)
146
- ProcessRequestMessage: this.#processPayload,
147
-
148
- messageReceiverStart: (options: any) => {
149
- this.#messagePort.on('message', this.#processRawMessage);
150
- //this.#redisSubscriber.on("message", this.#processRawMessage);
151
- },
152
-
153
- messageReceiverStop: (options: any) => {
154
- this.#messagePort.off("message", this.#processRawMessage);
155
- //this.#redisSubscriber.off("message", this.#processRawMessage);
156
- }
157
- }
158
- this.#ipcMessageManager = new IPCMessageManager(ipcMessageManagerOptions);
159
- }
160
-
161
-
162
- #messageSender = (payload: IIPCMessageProcessorIPCPayload, options: any) => {
163
- if (payload.messageType.localeCompare('REQUEST') === 0) {
164
- //this.#redisPublisher.publish(this.#requestChannel, JSON.stringify(payload));
165
- this.#messagePort.postMessage(JSON.stringify(payload));
166
- } else if (payload.messageType.localeCompare('RESPONSE') === 0) {
167
- this.#messagePort.postMessage(JSON.stringify(payload));
168
- //this.#redisPublisher.publish(this.#responseChannel, JSON.stringify(payload));
169
- }
170
- }
171
-
172
-
173
- #ProcessResponseMessage = async (responses: Record<string, IIPCMessageProcessorIPCPayload>, options: any): Promise<boolean> => {
174
- // Now check if we have all responses ...
175
- let allFound = false;
176
-
177
- for (const [responseId, response] of Object.entries(responses)) {
178
- if (response.senderRole.localeCompare('CLIENT') === 0) {
179
- allFound = true;
180
- break;
181
- }
182
- }
183
- if (allFound) {
184
- return allFound;
185
- }
186
-
187
- let found = true;
188
-
189
- // Sender role here is SERVER
190
- let requestGroup = null;
191
- for (const [responseId, response] of Object.entries(responses)) {
192
- if (response.requestPayload.args.length > 0 && response.requestPayload.args[0].group) {
193
- requestGroup = response.requestPayload.args[0].group;
194
- break;
195
- }
196
- }
197
-
198
- if (requestGroup) {
199
- const clientsInGroup = Object.values(this.#clients).filter(c => {
200
- if (c.groups.indexOf(requestGroup) === -1) {
201
- return false;
202
- }
203
- return true;
204
- });
205
-
206
- // Now make sure that all clients are in the responses
207
- found = true;
208
- clientsInGroup.forEach(c => {
209
- if (!responses[c.id]) {
210
- found = false;
211
- }
212
- })
213
- } else {
214
- const clientsInGroup = Object.values(this.#clients)
215
-
216
- // Now make sure that all clients are in the responses
217
- found = true;
218
- clientsInGroup.forEach(c => {
219
- if (!responses[c.id]) {
220
- found = false;
221
- }
222
- })
223
- }
224
-
225
- return found;
226
- }
227
-
228
- #processPayload = (payload: IIPCMessageProcessorIPCPayload, options: any): Promise<JSONObject> => {
229
- // check the event name from the collection and invoke that function
230
- return new Promise<JSONObject>((resolve, reject) => {
231
- if (payload.messageType.localeCompare('REQUEST') === 0) {
232
- if (payload.requestPayload['__eventName']) {
233
- const eventName = payload.requestPayload['__eventName'];
234
- // Only process events that I have registered interest in (using .on)
235
- if (this.#events[eventName]) {
236
- try {
237
- //const retVal = this.#events[eventName].callback(payload.requestPayload.args, payload, options, this.#events[eventName].ctx);
238
- this.#events[eventName].callback(...payload.requestPayload.args, (responseMessage: any) => {
239
- resolve(responseMessage);
240
- });
241
- } catch (error) {
242
- reject(error);
243
- }
244
- }
245
- }
246
- }
247
- });
248
- }
249
-
250
- // p.on('fromworker', (arg1: number, arg2: string, callback: any) => {
251
- override on(event: string, callback: any, ctx?: any): this {
252
- if (this.#events[event]) {
253
- // Update the event with the same name
254
- delete this.#events[event];
255
- }
256
- const eventObject: IEventRecord = {
257
- event,
258
- callback,
259
- ctx
260
- }
261
- this.#events[eventObject.event] = eventObject;
262
- return this;
263
- }
264
-
265
- override off(event: string, callback?: any): this {
266
- if (this.#events[event]) {
267
- delete this.#events[event];
268
- }
269
- return this;
270
- }
271
-
272
- Start = () => {
273
- this.#ipcMessageManager?.Start();
274
- }
275
-
276
- Stop = () => {
277
- if (this.#pingTimeout) {
278
- clearTimeout(this.#pingTimeout);
279
- this.#pingTimeout = null;
280
- }
281
-
282
- this.#ipcMessageManager?.Stop();
283
-
284
- /*
285
- this.#redisSubscriber.quit();
286
- this.#redisSubscriber.disconnect();
287
-
288
- this.#redisPublisher.quit();
289
- this.#redisPublisher.disconnect();
290
- */
291
- }
292
-
293
- override emit(event: string, ...args: any[]): this {
294
- (async () => {
295
- try {
296
- const retVal = await this.#ipcMessageManager?.SendMessage({
297
- __eventName: event,
298
- args: args.slice(0, args.length-1)
299
- } as IEventPayload);
300
- // Invoke the response callback
301
- args[args.length-1](retVal);
302
- } catch (error) {
303
- if (this.#options.ignoreEvents) {
304
- if (this.#options.ignoreEvents.indexOf((error as any).__eventName) !== -1) {
305
- return;
306
- }
307
- }
308
- this.#options.logger.error(chalk.red(`RedisMessageHandler:emit(): Error: [${JSON.stringify(error)}]`));
309
- }
310
- })();
311
- return this;
312
- }
313
-
314
- emitWithError(event: string, args: JSONObject, responseCb: (response: JSONObject | undefined) => void, errorCb: (error: any) => void): this {
315
- (async () => {
316
- try {
317
- const retVal = await this.#ipcMessageManager?.SendMessage({
318
- __eventName: event,
319
- args: [ args ]
320
- } as IEventPayload);
321
- // Invoke the response callback
322
- responseCb(retVal);
323
- } catch (error) {
324
- if (this.#options.ignoreEvents) {
325
- if (this.#options.ignoreEvents.indexOf((error as any).__eventName) !== -1) {
326
- return;
327
- }
328
- }
329
- errorCb(error);
330
- }
331
- })();
332
- return this;
333
- }
334
-
335
- emitex = async(event: string, ...args: any[]): Promise<JSONObject> => {
336
- return (this.#ipcMessageManager as IPCMessageManager).SendMessage({
337
- __eventName: event,
338
- args
339
- } as IEventPayload);
340
- }
341
- }
@@ -1,66 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF */ // --> OFF
2
- import { parentPort, MessagePort } from 'worker_threads';
3
-
4
- import { WebWorkerMessageHandler } from './webWorkerMessageHandler'
5
-
6
- import { defaultLogger, JSONObject } from '@nsshunt/stsutils'
7
-
8
- import chalk from 'chalk';
9
-
10
- export class WorkerSupport {
11
- #wwClient: WebWorkerMessageHandler | null = null;
12
-
13
- constructor() {
14
- this.#wwClient = new WebWorkerMessageHandler({
15
- logger: defaultLogger,
16
- role: 'CLIENT',
17
- namespace: 'mytestapp',
18
- groups: [ ],
19
- ignoreEvents: [ 'ping' ],
20
- messagePort: parentPort as MessagePort
21
- });
22
- this.#wwClient.Start();
23
-
24
- this.#wwClient.on('test', (arg1: JSONObject, callback: any) => {
25
- callback( {
26
- status: `PID: [${process.pid}]: response message from event = test with args ${JSON.stringify(arg1)}`
27
- })
28
- });
29
-
30
- this.#wwClient.on('globalmessage', (arg1: JSONObject, callback: any) => {
31
- callback( {
32
- status: `PID: [${process.pid}]: response message from event = globalmessage with args ${JSON.stringify(arg1)}`
33
- })
34
- });
35
-
36
- setTimeout(async () => {
37
- const sendObj1 = { from: 'child1' };
38
- console.log(chalk.magenta(`calling globalmessage = [${JSON.stringify(sendObj1)}]`));
39
- const retVal1 = await this.#wwClient?.emitex('globalmessage', sendObj1);
40
- console.log(chalk.magenta(`caller response from globalmessage = [${JSON.stringify(retVal1)}]`));
41
-
42
- const sendObj2 = { from: 'child2' };
43
- console.log(chalk.magenta(`calling test = [${JSON.stringify(sendObj2)}]`));
44
- const retVal2 = await this.#wwClient?.emitex('test', sendObj2);
45
- console.log(chalk.magenta(`caller response from test = [${JSON.stringify(retVal2)}]`));
46
- }, 2000);
47
- }
48
-
49
- ProcessMessage = async(data: any) => {
50
- console.log(`Received: [${data}]`);
51
- //parentPort?.postMessage(data);
52
- }
53
- }
54
-
55
- new WorkerSupport();
56
-
57
- /*
58
- parentPort?.on('message', (data: any) => {
59
- if (isNode) {
60
- worker.ProcessMessage(data);
61
- } else {
62
- // const payloadMessage: IIWMessagePayload = data.data as IIWMessagePayload; // browser version
63
- worker.ProcessMessage(data.data); // browser version
64
- }
65
- });
66
- */
@@ -1,157 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
- import { beforeAll, afterAll, test, describe, expect } from 'vitest';
3
-
4
- import { RedisMessageHandler } from './redisMessageHandler'
5
-
6
- import { JSONObject, Sleep, defaultLogger } from '@nsshunt/stsutils';
7
-
8
- import chalk from 'chalk';
9
-
10
- import { v4 as uuidv4 } from 'uuid';
11
-
12
- import { GenericContainer } from "testcontainers";
13
-
14
- describe.skip("Redis Message Handler Test", () =>
15
- {
16
- let ioRedisContainer: any;
17
- let ioRedisMessageProcessorUrl = '';
18
-
19
- beforeAll(async () => {
20
- // --- [ioRedis ] -------------------------------------------------------------------------
21
-
22
- ioRedisContainer = await new GenericContainer("redis")
23
- .withExposedPorts(6379)
24
- .start();
25
- ioRedisMessageProcessorUrl = `redis://${ioRedisContainer.getHost()}:${ioRedisContainer.getMappedPort(6379)}`;
26
- });
27
-
28
- afterAll(async () => {
29
- if (ioRedisContainer) {
30
- await ioRedisContainer.stop();
31
- }
32
- }, 5000);
33
-
34
- class Server {
35
- #r1: RedisMessageHandler;
36
-
37
- constructor() {
38
- this.#r1 = new RedisMessageHandler({
39
- logger: defaultLogger,
40
- role: 'SERVER',
41
- redisUrl: ioRedisMessageProcessorUrl, // goptions.imRedisMessageProcessorUrl,
42
- namespace: 'redistestingstsframework',
43
- groups: [ ]
44
- });
45
- this.#r1.Start();
46
-
47
- this.#r1.on('fromworkerredis', (arg1: string, arg2: number, arg3: string, callback: any) => {
48
- console.log(chalk.magenta(`${process.pid}: fromworkerredis.ON: [${arg1} ${arg2} ${arg3}]`));
49
- //callback(null);
50
- callback({status: `response message from event = fromworkerredis with args ${arg1} ${arg2} ${arg3}`})
51
- });
52
- }
53
-
54
- Start = async (expectedResponses: number, iterations: number, delay: number) => {
55
- for (let i=0; i < iterations; i++) {
56
- /*
57
- Object.keys(p).forEach(async (pKey) => {
58
- const emitobj = { i: i, a: 'a', b: 'b', worker: pKey };
59
- console.log(chalk.green(`${process.pid}: emit event to worker: [${pKey}] fromprimary: [${JSON.stringify(emitobj)}`));
60
- p[pKey].emit('fromprimary', emitobj, (response: any) => {
61
- console.log(chalk.green(`${process.pid}: ${JSON.stringify(response)}`));
62
- });
63
- });
64
- */
65
-
66
-
67
- const emitobj = { i: i, a: 'a', b: 'b' };
68
- console.log(chalk.cyan(`${process.pid}: emit event fromprimaryredis fromprimary: [${JSON.stringify(emitobj)}`));
69
- this.#r1.emit('fromprimaryredis', emitobj, (response: any) => {
70
- console.log(chalk.cyan(`${process.pid}: Response(fromprimaryredis): Count: [${response.length}] [${JSON.stringify(response)}]`));
71
- expect(response.length).toEqual(expectedResponses);
72
- });
73
-
74
- await Sleep(delay);
75
- }
76
- }
77
-
78
- Stop = () => {
79
- this.#r1.Stop();
80
- }
81
- }
82
-
83
- class Client {
84
- #r1: RedisMessageHandler;
85
-
86
- constructor() {
87
- this.#r1 = new RedisMessageHandler({
88
- logger: defaultLogger,
89
- role: 'CLIENT',
90
- redisUrl: ioRedisMessageProcessorUrl, // goptions.imRedisMessageProcessorUrl,
91
- namespace: 'redistestingstsframework',
92
- groups: [ ]
93
- });
94
- this.#r1.Start();
95
-
96
- this.#r1.on('fromprimaryredis', (arg1: JSONObject, callback: any) => {
97
- //callback();
98
- console.log(chalk.yellow(`${process.pid}: fromprimaryredis.ON: [${JSON.stringify(arg1)}]`));
99
- callback({status: `PID: [${process.pid}]: response message from event = fromprimaryredis with args ${JSON.stringify(arg1)}`})
100
- });
101
- }
102
-
103
- Start = async (iterations: number, delay: number) => {
104
- for (let i=0; i < iterations; i++) {
105
- const id = uuidv4();
106
- /*
107
- console.log(chalk.yellow(`${process.pid}: emit event fromworker: [${id} ${i} Hello]`));
108
- w1.emit('fromworker', id, i, 'Hello', (response: any) => {
109
- console.log(chalk.yellow(`${process.pid}: ${JSON.stringify(response)}`));
110
- });
111
- */
112
-
113
- console.log(chalk.green(`${process.pid}: emit event fromworkerredis: [${id} ${i} Hello]`));
114
- this.#r1.emit('fromworkerredis', id, i, 'Hello', (response: any) => {
115
- console.log(chalk.green(`${process.pid}: Response(fromworkerredis): [${JSON.stringify(response)}]`));
116
- });
117
- await Sleep(delay);
118
- }
119
- }
120
-
121
- Stop = () => {
122
- this.#r1.Stop();
123
- }
124
- }
125
-
126
-
127
- test('Test 1', async () =>
128
- {
129
- const clientCount = 20;
130
- const iterations = 5;
131
- const delay = 100;
132
-
133
- expect.assertions(iterations);
134
-
135
- // Setup new server and clients
136
- const server = new Server();
137
- const clients: Client[] = [ ];
138
- for (let i=0; i < clientCount; i++) {
139
- clients.push(new Client());
140
- }
141
-
142
- // Need this delay to ensure the pings are all sent and received between the clients and the server
143
- await Sleep(2000);
144
-
145
- // Start sending messages
146
- server.Start(clientCount, iterations, delay);
147
- clients.forEach(c => c.Start(iterations, delay));
148
-
149
- // Allow time to process
150
- await Sleep(3000);
151
-
152
- // All done, stop.
153
- clients.forEach(c => c.Stop());
154
- server.Stop();
155
- }, 30000);
156
- });
157
-