@omnitron-dev/testing 0.4.2 → 0.4.4

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 (71) hide show
  1. package/dist/titan/container-utils.d.ts +20 -0
  2. package/dist/titan/container-utils.js +78 -0
  3. package/dist/titan/container-utils.js.map +1 -0
  4. package/dist/titan/database/database-testing.module.d.ts +81 -0
  5. package/dist/titan/database/database-testing.module.js +419 -0
  6. package/dist/titan/database/database-testing.module.js.map +1 -0
  7. package/dist/titan/database/index.d.ts +3 -0
  8. package/dist/titan/database/index.js +4 -0
  9. package/dist/titan/database/index.js.map +1 -0
  10. package/dist/titan/database/test-utilities.d.ts +31 -0
  11. package/dist/titan/database/test-utilities.js +145 -0
  12. package/dist/titan/database/test-utilities.js.map +1 -0
  13. package/dist/titan/index.d.ts +14 -0
  14. package/dist/titan/index.js +10 -0
  15. package/dist/titan/index.js.map +1 -0
  16. package/dist/titan/nexus/index.d.ts +3 -0
  17. package/dist/titan/nexus/index.js +4 -0
  18. package/dist/titan/nexus/index.js.map +1 -0
  19. package/dist/titan/nexus/mock-provider.d.ts +41 -0
  20. package/dist/titan/nexus/mock-provider.js +127 -0
  21. package/dist/titan/nexus/mock-provider.js.map +1 -0
  22. package/dist/titan/nexus/test-container.d.ts +120 -0
  23. package/dist/titan/nexus/test-container.js +559 -0
  24. package/dist/titan/nexus/test-container.js.map +1 -0
  25. package/dist/titan/nexus/test-utilities.d.ts +135 -0
  26. package/dist/titan/nexus/test-utilities.js +484 -0
  27. package/dist/titan/nexus/test-utilities.js.map +1 -0
  28. package/dist/titan/pm/index.d.ts +4 -0
  29. package/dist/titan/pm/index.js +4 -0
  30. package/dist/titan/pm/index.js.map +1 -0
  31. package/dist/titan/pm/mock-process-spawner.d.ts +60 -0
  32. package/dist/titan/pm/mock-process-spawner.js +321 -0
  33. package/dist/titan/pm/mock-process-spawner.js.map +1 -0
  34. package/dist/titan/pm/mock-spawner.d.ts +27 -0
  35. package/dist/titan/pm/mock-spawner.js +99 -0
  36. package/dist/titan/pm/mock-spawner.js.map +1 -0
  37. package/dist/titan/pm/test-process-manager.d.ts +49 -0
  38. package/dist/titan/pm/test-process-manager.js +188 -0
  39. package/dist/titan/pm/test-process-manager.js.map +1 -0
  40. package/dist/titan/redis-test-utils.d.ts +33 -0
  41. package/dist/titan/redis-test-utils.js +415 -0
  42. package/dist/titan/redis-test-utils.js.map +1 -0
  43. package/dist/titan/test-application.d.ts +21 -0
  44. package/dist/titan/test-application.js +90 -0
  45. package/dist/titan/test-application.js.map +1 -0
  46. package/dist/titan/test-fixtures.d.ts +97 -0
  47. package/dist/titan/test-fixtures.js +223 -0
  48. package/dist/titan/test-fixtures.js.map +1 -0
  49. package/dist/titan/test-mocks.d.ts +29 -0
  50. package/dist/titan/test-mocks.js +262 -0
  51. package/dist/titan/test-mocks.js.map +1 -0
  52. package/dist/titan/test-module.d.ts +47 -0
  53. package/dist/titan/test-module.js +120 -0
  54. package/dist/titan/test-module.js.map +1 -0
  55. package/package.json +15 -4
  56. package/src/titan/database/database-testing.module.ts +831 -0
  57. package/src/titan/database/index.ts +30 -0
  58. package/src/titan/database/test-utilities.ts +337 -0
  59. package/src/titan/index.ts +89 -1
  60. package/src/titan/nexus/index.ts +3 -0
  61. package/src/titan/nexus/mock-provider.ts +189 -0
  62. package/src/titan/nexus/test-container.ts +887 -0
  63. package/src/titan/nexus/test-utilities.ts +796 -0
  64. package/src/titan/pm/index.ts +22 -0
  65. package/src/titan/pm/mock-process-spawner.ts +481 -0
  66. package/src/titan/pm/mock-spawner.ts +156 -0
  67. package/src/titan/pm/test-process-manager.ts +345 -0
  68. package/src/titan/redis-test-utils.ts +3 -2
  69. package/src/titan/test-application.ts +2 -2
  70. package/src/titan/test-fixtures.ts +2 -1
  71. package/src/titan/test-module.ts +5 -3
@@ -0,0 +1,60 @@
1
+ import { EventEmitter } from 'events';
2
+ import type { ILogger } from '@omnitron-dev/titan/module/logger';
3
+ import type { IProcessSpawner, ISpawnOptions, IWorkerHandle, IProcessManagerConfig } from '@omnitron-dev/titan/module/pm';
4
+ import { ProcessStatus } from '@omnitron-dev/titan/module/pm';
5
+ export declare class MockWorker extends EventEmitter {
6
+ readonly id: string;
7
+ private readonly options;
8
+ readonly threadId: number;
9
+ readonly pid: number;
10
+ private instance;
11
+ private publicMethods;
12
+ private _status;
13
+ private metrics;
14
+ constructor(id: string, ProcessClass: new (...args: any[]) => any, options?: ISpawnOptions);
15
+ get status(): ProcessStatus;
16
+ private extractPublicMethods;
17
+ private setupInternalMethods;
18
+ callMethod(methodName: string, args: unknown[]): Promise<unknown>;
19
+ postMessage(message: any): void;
20
+ terminate(): Promise<void>;
21
+ }
22
+ export declare class MockNetronClient {
23
+ readonly processId: string;
24
+ readonly logger: ILogger;
25
+ private connected;
26
+ private worker;
27
+ constructor(processId: string, logger: ILogger, worker: MockWorker);
28
+ start(): Promise<void>;
29
+ connect(url: string): Promise<void>;
30
+ disconnect(): Promise<void>;
31
+ stop(): Promise<void>;
32
+ isConnected(): boolean;
33
+ call(service: string, method: string, args: any[]): Promise<any>;
34
+ mockCall(method: string, args: any[]): Promise<any>;
35
+ }
36
+ export declare class MockWorkerHandle implements IWorkerHandle {
37
+ readonly id: string;
38
+ readonly transportUrl: string;
39
+ readonly serviceName: string;
40
+ readonly serviceVersion: string;
41
+ private readonly logger;
42
+ readonly proxy: any;
43
+ readonly netronClient: MockNetronClient;
44
+ readonly worker: MockWorker;
45
+ constructor(id: string, worker: MockWorker, transportUrl: string, serviceName: string, serviceVersion: string, logger: ILogger);
46
+ get status(): ProcessStatus;
47
+ terminate(): Promise<void>;
48
+ isAlive(): boolean;
49
+ send(message: any): Promise<void>;
50
+ onMessage(handler: (data: any) => void): void;
51
+ }
52
+ export declare class MockProcessSpawner implements IProcessSpawner {
53
+ private readonly logger;
54
+ private readonly config;
55
+ private workers;
56
+ constructor(logger: ILogger, config?: IProcessManagerConfig);
57
+ spawn<T>(processPathOrClass: string | (new (...args: any[]) => T), options?: ISpawnOptions): Promise<IWorkerHandle>;
58
+ cleanup(): Promise<void>;
59
+ }
60
+ export { MockProcessSpawner as SimpleMockProcessSpawner };
@@ -0,0 +1,321 @@
1
+ import { EventEmitter } from 'events';
2
+ import path from 'path';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ import { Errors } from '@omnitron-dev/titan/errors';
5
+ import { ProcessStatus } from '@omnitron-dev/titan/module/pm';
6
+ import { PROCESS_METHOD_METADATA_KEY } from '@omnitron-dev/titan/module/pm';
7
+ export class MockWorker extends EventEmitter {
8
+ constructor(id, ProcessClass, options = {}) {
9
+ super();
10
+ this.id = id;
11
+ this.options = options;
12
+ this.threadId = Math.floor(Math.random() * 10000);
13
+ this.pid = process.pid;
14
+ this.publicMethods = new Map();
15
+ this._status = ProcessStatus.STARTING;
16
+ this.metrics = {
17
+ cpu: 0,
18
+ memory: 0,
19
+ requests: 0,
20
+ errors: 0,
21
+ };
22
+ try {
23
+ this.instance = new ProcessClass(options.config || {});
24
+ }
25
+ catch (error) {
26
+ this.instance = {};
27
+ }
28
+ if (ProcessClass && ProcessClass.prototype) {
29
+ this.extractPublicMethods(ProcessClass);
30
+ }
31
+ this.setupInternalMethods();
32
+ setImmediate(() => {
33
+ this._status = ProcessStatus.RUNNING;
34
+ this.emit('message', { type: 'ready' });
35
+ });
36
+ }
37
+ get status() {
38
+ return this._status;
39
+ }
40
+ extractPublicMethods(ProcessClass) {
41
+ if (!ProcessClass || !ProcessClass.prototype) {
42
+ return;
43
+ }
44
+ const prototype = ProcessClass.prototype;
45
+ const propertyNames = Object.getOwnPropertyNames(prototype);
46
+ for (const propertyName of propertyNames) {
47
+ if (propertyName === 'constructor')
48
+ continue;
49
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, propertyName);
50
+ if (!descriptor || typeof descriptor.value !== 'function')
51
+ continue;
52
+ const pmMetadata = Reflect.getMetadata(PROCESS_METHOD_METADATA_KEY, prototype, propertyName);
53
+ const corePublic = Reflect.getMetadata('public', prototype, propertyName);
54
+ if (pmMetadata?.public || corePublic) {
55
+ this.publicMethods.set(propertyName, descriptor.value.bind(this.instance));
56
+ }
57
+ }
58
+ const specialMethods = ['checkHealth', 'onShutdown', 'getMetrics'];
59
+ for (const method of specialMethods) {
60
+ if (typeof this.instance[method] === 'function') {
61
+ this.publicMethods.set(method, this.instance[method].bind(this.instance));
62
+ }
63
+ }
64
+ }
65
+ setupInternalMethods() {
66
+ this.publicMethods.set('__getProcessMetrics', async () => {
67
+ if (this.metrics)
68
+ this.metrics.requests = (this.metrics.requests || 0) + 1;
69
+ return {
70
+ ...(this.metrics || { cpu: 0, memory: 0, requests: 0, errors: 0 }),
71
+ cpu: Math.random() * 100,
72
+ memory: process.memoryUsage().heapUsed,
73
+ };
74
+ });
75
+ this.publicMethods.set('__getProcessHealth', async () => {
76
+ if (this.publicMethods.has('checkHealth')) {
77
+ const result = await this.publicMethods.get('checkHealth')();
78
+ if (result && typeof result === 'object') {
79
+ const healthResult = result;
80
+ if ('status' in healthResult && 'checks' in healthResult && 'timestamp' in healthResult) {
81
+ return healthResult;
82
+ }
83
+ const status = healthResult.status || (this._status === ProcessStatus.RUNNING ? 'healthy' : 'unhealthy');
84
+ return {
85
+ status: status,
86
+ checks: healthResult.checks || [
87
+ {
88
+ name: 'checkHealth',
89
+ status: status === 'healthy' ? 'pass' : 'fail',
90
+ message: healthResult.message,
91
+ details: healthResult.details,
92
+ },
93
+ ],
94
+ timestamp: healthResult.timestamp || Date.now(),
95
+ };
96
+ }
97
+ }
98
+ return {
99
+ status: this._status === ProcessStatus.RUNNING ? 'healthy' : 'unhealthy',
100
+ checks: [
101
+ {
102
+ name: 'mock',
103
+ status: 'pass',
104
+ },
105
+ ],
106
+ timestamp: Date.now(),
107
+ };
108
+ });
109
+ this.publicMethods.set('__destroy', async () => {
110
+ await this.terminate();
111
+ });
112
+ }
113
+ async callMethod(methodName, args) {
114
+ const method = this.publicMethods.get(methodName);
115
+ if (!method) {
116
+ if (this.metrics)
117
+ this.metrics.errors = (this.metrics.errors || 0) + 1;
118
+ throw Errors.notFound('Method', methodName);
119
+ }
120
+ try {
121
+ if (this.metrics)
122
+ this.metrics.requests = (this.metrics.requests || 0) + 1;
123
+ const result = method(...args);
124
+ if (result && typeof result === 'object' && 'then' in result && typeof result.then === 'function') {
125
+ return await result;
126
+ }
127
+ return result;
128
+ }
129
+ catch (error) {
130
+ if (this.metrics)
131
+ this.metrics.errors = (this.metrics.errors || 0) + 1;
132
+ throw error;
133
+ }
134
+ }
135
+ postMessage(message) {
136
+ setImmediate(() => {
137
+ if (message.type === 'shutdown') {
138
+ this.terminate();
139
+ }
140
+ else {
141
+ this.emit('message', { type: 'response', data: message });
142
+ }
143
+ });
144
+ }
145
+ async terminate() {
146
+ this._status = ProcessStatus.STOPPING;
147
+ if (this.publicMethods.has('onShutdown')) {
148
+ try {
149
+ await this.publicMethods.get('onShutdown')();
150
+ }
151
+ catch (error) {
152
+ }
153
+ }
154
+ this._status = ProcessStatus.STOPPED;
155
+ this.emit('exit', 0);
156
+ }
157
+ }
158
+ export class MockNetronClient {
159
+ constructor(processId, logger, worker) {
160
+ this.processId = processId;
161
+ this.logger = logger;
162
+ this.connected = false;
163
+ this.worker = worker;
164
+ }
165
+ async start() {
166
+ }
167
+ async connect(url) {
168
+ this.connected = true;
169
+ }
170
+ async disconnect() {
171
+ this.connected = false;
172
+ }
173
+ async stop() {
174
+ await this.disconnect();
175
+ }
176
+ isConnected() {
177
+ return this.connected;
178
+ }
179
+ async call(service, method, args) {
180
+ return this.worker.callMethod(method, args);
181
+ }
182
+ async mockCall(method, args) {
183
+ return this.worker.callMethod(method, args);
184
+ }
185
+ }
186
+ export class MockWorkerHandle {
187
+ constructor(id, worker, transportUrl, serviceName, serviceVersion, logger) {
188
+ this.id = id;
189
+ this.transportUrl = transportUrl;
190
+ this.serviceName = serviceName;
191
+ this.serviceVersion = serviceVersion;
192
+ this.logger = logger;
193
+ this.worker = worker;
194
+ this.netronClient = new MockNetronClient(id, logger, worker);
195
+ this.proxy = new Proxy({}, {
196
+ get: (target, property) => {
197
+ if (property === '__processId') {
198
+ return this.id;
199
+ }
200
+ if (property === '__destroy') {
201
+ return () => this.terminate();
202
+ }
203
+ if (property === '__getMetrics') {
204
+ return () => this.worker.callMethod('__getProcessMetrics', []);
205
+ }
206
+ if (property === '__getHealth') {
207
+ return () => this.worker.callMethod('__getProcessHealth', []);
208
+ }
209
+ if (property === 'then' || property === 'catch' || property === 'finally') {
210
+ return undefined;
211
+ }
212
+ if (typeof property === 'symbol') {
213
+ return undefined;
214
+ }
215
+ const methodName = String(property);
216
+ const isStreamMethod = methodName.startsWith('stream') || methodName.toLowerCase().includes('stream');
217
+ if (isStreamMethod) {
218
+ const workerInstance = this.worker;
219
+ return async (...args) => {
220
+ const result = await workerInstance.callMethod(methodName, args);
221
+ const anyResult = result;
222
+ if (anyResult && typeof anyResult[Symbol.asyncIterator] === 'function') {
223
+ return anyResult;
224
+ }
225
+ if (anyResult && typeof anyResult[Symbol.iterator] === 'function') {
226
+ return (async function* () {
227
+ yield* anyResult;
228
+ })();
229
+ }
230
+ return result;
231
+ };
232
+ }
233
+ return async (...args) => this.worker.callMethod(methodName, args);
234
+ },
235
+ has: (target, property) => {
236
+ const controlMethods = ['__processId', '__destroy', '__getMetrics', '__getHealth'];
237
+ if (typeof property === 'string' && controlMethods.includes(property)) {
238
+ return true;
239
+ }
240
+ return typeof property === 'string';
241
+ },
242
+ });
243
+ }
244
+ get status() {
245
+ return this.worker.status;
246
+ }
247
+ async terminate() {
248
+ await this.worker.terminate();
249
+ }
250
+ isAlive() {
251
+ return this.worker.status === ProcessStatus.RUNNING;
252
+ }
253
+ async send(message) {
254
+ this.worker.postMessage(message);
255
+ }
256
+ onMessage(handler) {
257
+ this.worker.on('message', handler);
258
+ }
259
+ }
260
+ export class MockProcessSpawner {
261
+ constructor(logger, config = {}) {
262
+ this.logger = logger;
263
+ this.config = config;
264
+ this.workers = new Map();
265
+ }
266
+ async spawn(processPathOrClass, options = {}) {
267
+ const processId = options.processId || uuidv4();
268
+ let ProcessClass;
269
+ let serviceName;
270
+ if (typeof processPathOrClass === 'string') {
271
+ try {
272
+ const module = await import(processPathOrClass);
273
+ if (module.default) {
274
+ ProcessClass = module.default;
275
+ }
276
+ else {
277
+ const keys = Object.keys(module);
278
+ const firstKey = keys[0];
279
+ if (firstKey && module[firstKey]) {
280
+ ProcessClass = module[firstKey];
281
+ }
282
+ else {
283
+ throw Errors.notFound('Default export', 'process file');
284
+ }
285
+ }
286
+ serviceName = options.name || path.basename(processPathOrClass, '.js');
287
+ }
288
+ catch (error) {
289
+ ProcessClass = class MockProcess {
290
+ constructor() { }
291
+ };
292
+ serviceName = options.name || 'MockProcess';
293
+ }
294
+ }
295
+ else {
296
+ ProcessClass = processPathOrClass;
297
+ serviceName = options.name || ProcessClass.name;
298
+ }
299
+ const serviceVersion = options.version || '1.0.0';
300
+ const transportUrl = `mock://${processId}`;
301
+ const worker = new MockWorker(processId, ProcessClass, options);
302
+ this.workers.set(processId, worker);
303
+ const handle = new MockWorkerHandle(processId, worker, transportUrl, serviceName, serviceVersion, this.logger);
304
+ await new Promise((resolve) => {
305
+ worker.once('message', (data) => {
306
+ if (data.type === 'ready') {
307
+ resolve();
308
+ }
309
+ });
310
+ });
311
+ return handle;
312
+ }
313
+ async cleanup() {
314
+ for (const [id, worker] of this.workers) {
315
+ await worker.terminate();
316
+ }
317
+ this.workers.clear();
318
+ }
319
+ }
320
+ export { MockProcessSpawner as SimpleMockProcessSpawner };
321
+ //# sourceMappingURL=mock-process-spawner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-process-spawner.js","sourceRoot":"","sources":["../../../src/titan/pm/mock-process-spawner.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CA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,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;IAKD,KAAK,CAAC,OAAO;QAEX,KAAK,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACxC,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF;AAKD,OAAO,EAAE,kBAAkB,IAAI,wBAAwB,EAAE,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { EventEmitter } from 'events';
2
+ import { Netron } from '@omnitron-dev/titan/netron';
3
+ import type { ILogger } from '@omnitron-dev/titan/module/logger';
4
+ import type { IProcessOptions, IProcessManagerConfig } from '@omnitron-dev/titan/module/pm';
5
+ declare class MockWorker extends EventEmitter {
6
+ threadId: number;
7
+ pid: number;
8
+ private instance;
9
+ private publicMethods;
10
+ constructor(ProcessClass: new (...args: any[]) => any);
11
+ callMethod(methodName: string, args: any[]): Promise<any>;
12
+ postMessage(message: any): void;
13
+ terminate(): Promise<number>;
14
+ }
15
+ export declare class MockProcessSpawner {
16
+ private readonly logger;
17
+ private readonly config;
18
+ private mockWorkers;
19
+ constructor(logger: ILogger, config?: IProcessManagerConfig);
20
+ spawn(ProcessClass: new (...args: any[]) => any, processId: string, options: IProcessOptions): Promise<{
21
+ worker: MockWorker;
22
+ netron: Netron;
23
+ transportUrl: string;
24
+ }>;
25
+ cleanup(processId: string): Promise<void>;
26
+ }
27
+ export {};
@@ -0,0 +1,99 @@
1
+ import { EventEmitter } from 'events';
2
+ import { Netron } from '@omnitron-dev/titan/netron';
3
+ import { Errors } from '@omnitron-dev/titan/errors';
4
+ import { PROCESS_METHOD_METADATA_KEY } from '@omnitron-dev/titan/module/pm';
5
+ class MockWorker extends EventEmitter {
6
+ constructor(ProcessClass) {
7
+ super();
8
+ this.threadId = Math.floor(Math.random() * 10000);
9
+ this.pid = process.pid;
10
+ this.publicMethods = new Map();
11
+ this.instance = new ProcessClass();
12
+ const prototype = ProcessClass.prototype;
13
+ const propertyNames = Object.getOwnPropertyNames(prototype);
14
+ for (const propertyName of propertyNames) {
15
+ if (propertyName === 'constructor')
16
+ continue;
17
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, propertyName);
18
+ if (!descriptor || typeof descriptor.value !== 'function')
19
+ continue;
20
+ const metadata = Reflect.getMetadata(PROCESS_METHOD_METADATA_KEY, prototype, propertyName);
21
+ if (metadata?.public) {
22
+ this.publicMethods.set(propertyName, descriptor.value.bind(this.instance));
23
+ }
24
+ }
25
+ if (typeof this.instance.checkHealth === 'function') {
26
+ this.publicMethods.set('checkHealth', this.instance.checkHealth.bind(this.instance));
27
+ }
28
+ this.publicMethods.set('__getProcessMetrics', async () => ({
29
+ cpu: 0.1,
30
+ memory: process.memoryUsage().heapUsed,
31
+ requests: 0,
32
+ errors: 0,
33
+ uptime: process.uptime(),
34
+ }));
35
+ this.publicMethods.set('__getProcessHealth', async () => {
36
+ if (typeof this.instance.checkHealth === 'function') {
37
+ return await this.instance.checkHealth();
38
+ }
39
+ return {
40
+ status: 'healthy',
41
+ checks: [],
42
+ timestamp: Date.now(),
43
+ };
44
+ });
45
+ setImmediate(() => {
46
+ this.emit('message', { type: 'ready' });
47
+ });
48
+ }
49
+ async callMethod(methodName, args) {
50
+ const method = this.publicMethods.get(methodName);
51
+ if (!method) {
52
+ throw Errors.notFound('Method', methodName);
53
+ }
54
+ return await method(...args);
55
+ }
56
+ postMessage(message) {
57
+ if (message.type === 'shutdown') {
58
+ this.emit('exit', 0);
59
+ }
60
+ }
61
+ terminate() {
62
+ this.emit('exit', 0);
63
+ return Promise.resolve(0);
64
+ }
65
+ }
66
+ export class MockProcessSpawner {
67
+ constructor(logger, config = {}) {
68
+ this.logger = logger;
69
+ this.config = config;
70
+ this.mockWorkers = new Map();
71
+ }
72
+ async spawn(ProcessClass, processId, options) {
73
+ const worker = new MockWorker(ProcessClass);
74
+ this.mockWorkers.set(processId, worker);
75
+ const netron = new Netron(this.logger, {
76
+ id: `mock-${processId}`,
77
+ });
78
+ netron.mockCall = async (methodName, args) => worker.callMethod(methodName, args);
79
+ netron.peer = {
80
+ call: async (serviceName, methodName, args) => worker.callMethod(methodName, args),
81
+ expose: async () => { },
82
+ start: async () => { },
83
+ stop: async () => { },
84
+ connect: async () => { },
85
+ disconnect: async () => { },
86
+ listen: async () => { },
87
+ };
88
+ const transportUrl = `mock://${processId}`;
89
+ return { worker, netron, transportUrl };
90
+ }
91
+ async cleanup(processId) {
92
+ const worker = this.mockWorkers.get(processId);
93
+ if (worker) {
94
+ await worker.terminate();
95
+ this.mockWorkers.delete(processId);
96
+ }
97
+ }
98
+ }
99
+ //# sourceMappingURL=mock-spawner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-spawner.js","sourceRoot":"","sources":["../../../src/titan/pm/mock-spawner.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAIpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAK5E,MAAM,UAAW,SAAQ,YAAY;IAMnC,YAAY,YAAyC;QACnD,KAAK,EAAE,CAAC;QANH,aAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC;QAC7C,QAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QAEjB,kBAAa,GAA+B,IAAI,GAAG,EAAE,CAAC;QAM5D,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;QAGnC,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC;QACzC,MAAM,aAAa,GA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C,CAAC;QACrC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,49 @@
1
+ import { ProcessManager } from '@omnitron-dev/titan/module/pm';
2
+ import { ProcessStatus } from '@omnitron-dev/titan/module/pm';
3
+ import type { IProcessOptions, IProcessInfo, ServiceProxy, IProcessManagerConfig } from '@omnitron-dev/titan/module/pm';
4
+ export interface ITestProcessManagerConfig extends IProcessManagerConfig {
5
+ mock?: boolean;
6
+ controlTime?: boolean;
7
+ recordOperations?: boolean;
8
+ }
9
+ export interface IOperationRecord {
10
+ type: 'spawn' | 'kill' | 'restart' | 'health' | 'metrics';
11
+ processId?: string;
12
+ processClass?: string;
13
+ timestamp: number;
14
+ data?: any;
15
+ }
16
+ export declare class TestProcessManager extends ProcessManager {
17
+ private operations;
18
+ private simulatedFailures;
19
+ private simulatedMetrics;
20
+ private simulatedHealth;
21
+ private timeOffset;
22
+ private crashHandlers;
23
+ private recoveryHandlers;
24
+ constructor(config?: ITestProcessManagerConfig);
25
+ private setupTestHandlers;
26
+ spawn<T>(ProcessClass: new (...args: any[]) => T, options?: IProcessOptions): Promise<ServiceProxy<T>>;
27
+ simulateCrash(processOrId: ServiceProxy<any> | string): Promise<void>;
28
+ waitForRecovery(processOrId: ServiceProxy<any> | string, timeout?: number): Promise<boolean>;
29
+ setMetrics(processId: string, metrics: any): void;
30
+ getMetrics(processId: string): Promise<any>;
31
+ setHealth(processId: string, health: any): void;
32
+ getHealth(processId: string): Promise<any>;
33
+ simulateFailure(operation: string, error: Error): void;
34
+ clearFailures(): void;
35
+ advanceTime(ms: number): void;
36
+ resetTime(): void;
37
+ getCurrentTime(): number;
38
+ getOperations(): IOperationRecord[];
39
+ clearOperations(): void;
40
+ verifyOperation(type: string, predicate?: (op: IOperationRecord) => boolean): boolean;
41
+ waitForOperation(type: string, timeout?: number): Promise<IOperationRecord | null>;
42
+ private recordOperation;
43
+ cleanup(): Promise<void>;
44
+ spyOnMethod<T>(proxy: ServiceProxy<T>, methodName: keyof T): jest.SpyInstance | any;
45
+ assertProcessState(processId: string, expectedStatus: ProcessStatus): void;
46
+ getProcessesByClass<T>(ProcessClass: new (...args: any[]) => T): IProcessInfo[];
47
+ countByStatus(status: ProcessStatus): number;
48
+ }
49
+ export declare function createTestProcessManager(config?: ITestProcessManagerConfig): TestProcessManager;