@bsb/base 9.0.0 → 9.0.3
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/README.md +11 -49
- package/lib/plugins/config-default/interfaces.d.ts +3 -2
- package/lib/schemas/config-default.plugin.json +1 -1
- package/lib/schemas/events-default.plugin.json +1 -1
- package/lib/schemas/observable-default.plugin.json +1 -1
- package/lib/serviceBase/events.js +2 -2
- package/lib/serviceBase/events.js.map +1 -1
- package/lib/serviceBase/observable.js +1 -1
- package/lib/serviceBase/observable.js.map +1 -1
- package/lib/serviceBase/plugins.d.ts +8 -1
- package/lib/serviceBase/plugins.js +115 -25
- package/lib/serviceBase/plugins.js.map +1 -1
- package/lib/serviceBase/services.js +2 -2
- package/lib/serviceBase/services.js.map +1 -1
- package/lib/tests/mocks.d.ts +37 -0
- package/lib/tests/mocks.js +164 -0
- package/lib/tests/mocks.js.map +1 -0
- package/lib/tests/sb/plugins/events/broadcast.d.ts +30 -0
- package/lib/tests/sb/plugins/events/broadcast.js +357 -0
- package/lib/tests/sb/plugins/events/broadcast.js.map +1 -0
- package/lib/tests/sb/plugins/events/emit.d.ts +30 -0
- package/lib/tests/sb/plugins/events/emit.js +353 -0
- package/lib/tests/sb/plugins/events/emit.js.map +1 -0
- package/lib/tests/sb/plugins/events/emitAndReturn.d.ts +30 -0
- package/lib/tests/sb/plugins/events/emitAndReturn.js +382 -0
- package/lib/tests/sb/plugins/events/emitAndReturn.js.map +1 -0
- package/lib/tests/sb/plugins/events/emitStreamAndReceiveStream.d.ts +30 -0
- package/lib/tests/sb/plugins/events/emitStreamAndReceiveStream.js +298 -0
- package/lib/tests/sb/plugins/events/emitStreamAndReceiveStream.js.map +1 -0
- package/lib/tests/sb/plugins/events/index.d.ts +28 -0
- package/lib/tests/sb/plugins/events/index.js +69 -0
- package/lib/tests/sb/plugins/events/index.js.map +1 -0
- package/lib/tests/trace.d.ts +41 -0
- package/lib/tests/trace.js +85 -0
- package/lib/tests/trace.js.map +1 -0
- package/package.json +92 -91
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.emitStreamAndReceiveStream = emitStreamAndReceiveStream;
|
|
30
|
+
const fs = require("fs");
|
|
31
|
+
const crypto = require("crypto");
|
|
32
|
+
const stream_1 = require("stream");
|
|
33
|
+
const assert = require("assert");
|
|
34
|
+
const index_1 = require("../../../../index");
|
|
35
|
+
const trace_1 = require("../../../trace");
|
|
36
|
+
const randomName = () => crypto.randomUUID();
|
|
37
|
+
const mockBareFakeStream = () => {
|
|
38
|
+
const obj = {
|
|
39
|
+
listeners: {},
|
|
40
|
+
emit: (name, data) => {
|
|
41
|
+
if (obj.listeners[name] !== undefined) {
|
|
42
|
+
obj.listeners[name](data);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
on: (name, listn) => {
|
|
46
|
+
obj.listeners[name] = listn;
|
|
47
|
+
},
|
|
48
|
+
destroy: () => {
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
return obj;
|
|
52
|
+
};
|
|
53
|
+
const getFileHash = (filename) => new Promise((resolve, reject) => {
|
|
54
|
+
const fd = fs.createReadStream(filename);
|
|
55
|
+
// deepcode ignore InsecureHash/test: not production, just using to verify the files hash
|
|
56
|
+
const hash = crypto.createHash("sha1");
|
|
57
|
+
hash.setEncoding("hex");
|
|
58
|
+
fd.on("error", reject);
|
|
59
|
+
fd.on("end", () => {
|
|
60
|
+
hash.end();
|
|
61
|
+
resolve(hash.read());
|
|
62
|
+
});
|
|
63
|
+
// read all file and pipe it (write it) to the hash object
|
|
64
|
+
fd.pipe(hash);
|
|
65
|
+
});
|
|
66
|
+
// Cross-platform function to create test files with random data
|
|
67
|
+
const createTestFile = (filePath, sizeStr) => {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
// Parse size string (e.g., "1KB", "16MB")
|
|
70
|
+
const match = sizeStr.match(/^(\d+)(KB|MB)$/);
|
|
71
|
+
if (!match) {
|
|
72
|
+
return reject(new Error(`Invalid size format: ${sizeStr}`));
|
|
73
|
+
}
|
|
74
|
+
const num = parseInt(match[1], 10);
|
|
75
|
+
const unit = match[2];
|
|
76
|
+
const sizeBytes = unit === 'KB' ? num * 1024 : num * 1024 * 1024;
|
|
77
|
+
// Create random data in chunks
|
|
78
|
+
const writeStream = fs.createWriteStream(filePath);
|
|
79
|
+
const chunkSize = 64 * 1024; // 64KB chunks
|
|
80
|
+
let written = 0;
|
|
81
|
+
const writeChunk = () => {
|
|
82
|
+
while (written < sizeBytes) {
|
|
83
|
+
const remaining = sizeBytes - written;
|
|
84
|
+
const size = Math.min(chunkSize, remaining);
|
|
85
|
+
const buffer = crypto.randomBytes(size);
|
|
86
|
+
const canContinue = writeStream.write(buffer);
|
|
87
|
+
written += size;
|
|
88
|
+
if (!canContinue) {
|
|
89
|
+
// Wait for drain event
|
|
90
|
+
writeStream.once('drain', writeChunk);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
writeStream.end();
|
|
95
|
+
};
|
|
96
|
+
writeStream.on('finish', () => resolve());
|
|
97
|
+
writeStream.on('error', reject);
|
|
98
|
+
writeChunk();
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
// const convertBytes = (
|
|
102
|
+
// bytes: number,
|
|
103
|
+
// sizes = [
|
|
104
|
+
// "Bytes",
|
|
105
|
+
// "KB",
|
|
106
|
+
// "MB",
|
|
107
|
+
// "GB",
|
|
108
|
+
// "TB",
|
|
109
|
+
// ],
|
|
110
|
+
// ) => {
|
|
111
|
+
// if (bytes == 0) {
|
|
112
|
+
// return "n/a";
|
|
113
|
+
// }
|
|
114
|
+
// //const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
|
|
115
|
+
// const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))
|
|
116
|
+
// .toString());
|
|
117
|
+
// if (i == 0) {
|
|
118
|
+
// return bytes + " " + sizes[i];
|
|
119
|
+
// }
|
|
120
|
+
// return (
|
|
121
|
+
// bytes / Math.pow(1024, i)
|
|
122
|
+
// ).toFixed(1) + " " + sizes[i];
|
|
123
|
+
// };
|
|
124
|
+
function emitStreamAndReceiveStream(genNewPlugin, maxTimeoutToExpectAResponse) {
|
|
125
|
+
let emitter;
|
|
126
|
+
beforeEach(async () => {
|
|
127
|
+
emitter = await genNewPlugin();
|
|
128
|
+
});
|
|
129
|
+
afterEach(function () {
|
|
130
|
+
(0, index_1.SmartFunctionCallSync)(emitter, emitter.dispose);
|
|
131
|
+
});
|
|
132
|
+
describe("EmitStreamAndReceiveStream", async () => {
|
|
133
|
+
//this.timeout(maxTimeoutToExpectAResponse + 20);
|
|
134
|
+
//this.afterEach(done => setTimeout(done, maxTimeoutToExpectAResponse));
|
|
135
|
+
const timermaxTimeoutToExpectAResponse = maxTimeoutToExpectAResponse + 10;
|
|
136
|
+
it("receiveStream creates a should generate a valid string", async () => {
|
|
137
|
+
const thisCaller = randomName();
|
|
138
|
+
const thisCallerEvent = randomName();
|
|
139
|
+
const obs = (0, trace_1.createTestObservable)();
|
|
140
|
+
const uuid = await emitter.receiveStream(obs, thisCaller, thisCallerEvent, async (receivedObs, error, stream) => {
|
|
141
|
+
}, maxTimeoutToExpectAResponse);
|
|
142
|
+
assert.ok(`${uuid}`.length >= 10, "Not a valid unique ID for stream");
|
|
143
|
+
});
|
|
144
|
+
it("sendStream triggers timeout when no receiveStream setup", async () => {
|
|
145
|
+
const thisCaller = randomName();
|
|
146
|
+
const thisEvent = randomName();
|
|
147
|
+
// Use proper streamId format: uuid=timeoutSeconds
|
|
148
|
+
const streamId = `${randomName()}=1`;
|
|
149
|
+
const obs = (0, trace_1.createTestObservable)();
|
|
150
|
+
try {
|
|
151
|
+
await emitter.sendStream(obs, thisCaller, thisEvent, streamId, mockBareFakeStream());
|
|
152
|
+
assert.fail("Timeout not called");
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
assert.ok(true, "Timeout called exception");
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
it("sendStream triggers receiveStream listener", async () => {
|
|
159
|
+
const thisCaller = randomName();
|
|
160
|
+
const thisCallerEvent = randomName();
|
|
161
|
+
const obs = (0, trace_1.createTestObservable)();
|
|
162
|
+
const emitTimeout = setTimeout(() => {
|
|
163
|
+
assert.fail("Event not received");
|
|
164
|
+
}, timermaxTimeoutToExpectAResponse);
|
|
165
|
+
const uuid = await emitter.receiveStream(obs, thisCaller, thisCallerEvent, async (receivedObs, error, stream) => {
|
|
166
|
+
clearTimeout(emitTimeout);
|
|
167
|
+
stream.emit("end");
|
|
168
|
+
assert.ok(true, "Listener called");
|
|
169
|
+
}, maxTimeoutToExpectAResponse);
|
|
170
|
+
try {
|
|
171
|
+
await emitter.sendStream(obs, thisCaller, thisCallerEvent, uuid, mockBareFakeStream());
|
|
172
|
+
//console.log("endededed");
|
|
173
|
+
// eslint-disable-next-line no-empty
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
describe("sendStream triggers receiveStream listener passing in the stream", async () => {
|
|
179
|
+
it("should not call the listener with an error", async () => {
|
|
180
|
+
const thisCaller = randomName();
|
|
181
|
+
const thisCallerEvent = randomName();
|
|
182
|
+
const obs = (0, trace_1.createTestObservable)();
|
|
183
|
+
const emitTimeout = setTimeout(() => {
|
|
184
|
+
assert.fail("Event not received");
|
|
185
|
+
}, timermaxTimeoutToExpectAResponse);
|
|
186
|
+
const uuid = await emitter.receiveStream(obs, thisCaller, thisCallerEvent, async (receivedObs, error, stream) => {
|
|
187
|
+
clearTimeout(emitTimeout);
|
|
188
|
+
stream.emit("end");
|
|
189
|
+
assert.strictEqual(error, null, "Error is not null");
|
|
190
|
+
}, maxTimeoutToExpectAResponse);
|
|
191
|
+
try {
|
|
192
|
+
await emitter.sendStream(obs, thisCaller, thisCallerEvent, uuid, mockBareFakeStream());
|
|
193
|
+
// eslint-disable-next-line no-empty
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
it("should call the listener with a stream", async () => {
|
|
199
|
+
const thisCaller = randomName();
|
|
200
|
+
const thisCallerEvent = randomName();
|
|
201
|
+
const obs = (0, trace_1.createTestObservable)();
|
|
202
|
+
const emitTimeout = setTimeout(() => {
|
|
203
|
+
assert.fail("Event not received");
|
|
204
|
+
}, timermaxTimeoutToExpectAResponse);
|
|
205
|
+
const uuid = await emitter.receiveStream(obs, thisCaller, thisCallerEvent, async (receivedObs, error, stream) => {
|
|
206
|
+
clearTimeout(emitTimeout);
|
|
207
|
+
stream.emit("end");
|
|
208
|
+
assert.strictEqual(typeof stream, typeof mockBareFakeStream(), "Listener called");
|
|
209
|
+
}, maxTimeoutToExpectAResponse);
|
|
210
|
+
try {
|
|
211
|
+
await emitter.sendStream(obs, thisCaller, thisCallerEvent, uuid, mockBareFakeStream());
|
|
212
|
+
// eslint-disable-next-line no-empty
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
describe("sendStream triggers receiveStream files", function () {
|
|
219
|
+
this.timeout(120000);
|
|
220
|
+
const runTest = async (size, count = 1) => {
|
|
221
|
+
it(`should be able to fully stream a file - ${size}`, async () => {
|
|
222
|
+
this.timeout(120000);
|
|
223
|
+
const thisCaller = randomName();
|
|
224
|
+
const thisCallerEvent = randomName();
|
|
225
|
+
const obs = (0, trace_1.createTestObservable)();
|
|
226
|
+
//const now = new Date().getTime();
|
|
227
|
+
const fileName = `./test-file-${size}`;
|
|
228
|
+
const fileNameOut = fileName + "-out";
|
|
229
|
+
try {
|
|
230
|
+
// Create test file with random data (cross-platform)
|
|
231
|
+
await createTestFile(fileName, size);
|
|
232
|
+
//const fileBytes = fs.statSync(fileName).size;
|
|
233
|
+
//const fullBytes = convertBytes(fileBytes);
|
|
234
|
+
//console.log(` ${size} act size: ${fullBytes}`);
|
|
235
|
+
const srcFileHash = await getFileHash(fileName);
|
|
236
|
+
const emitTimeout = setTimeout(() => {
|
|
237
|
+
assert.fail("Event not received");
|
|
238
|
+
}, timermaxTimeoutToExpectAResponse);
|
|
239
|
+
const uuid = await emitter.receiveStream(obs, thisCaller, thisCallerEvent, async (receivedObs, error, stream) => {
|
|
240
|
+
if (error) {
|
|
241
|
+
return assert.fail(error);
|
|
242
|
+
}
|
|
243
|
+
clearTimeout(emitTimeout);
|
|
244
|
+
(0, stream_1.pipeline)(stream, fs.createWriteStream(fileNameOut), (errf) => {
|
|
245
|
+
if (errf) {
|
|
246
|
+
assert.fail(errf);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}, maxTimeoutToExpectAResponse);
|
|
250
|
+
await emitter.sendStream(obs, thisCaller, thisCallerEvent, uuid, fs.createReadStream(fileName));
|
|
251
|
+
fs.unlinkSync(fileName);
|
|
252
|
+
assert.strictEqual(await getFileHash(fileNameOut), srcFileHash, "Validate data equals");
|
|
253
|
+
fs.unlinkSync(fileNameOut);
|
|
254
|
+
//const done = new Date().getTime();
|
|
255
|
+
//const totalTimeMS = done - now;
|
|
256
|
+
// const bytesPerSecond = fileBytes / (
|
|
257
|
+
// totalTimeMS / 1000
|
|
258
|
+
// );
|
|
259
|
+
// console.log(
|
|
260
|
+
// ` ${size} act size: ${fullBytes} as ${convertBytes(
|
|
261
|
+
// bytesPerSecond,
|
|
262
|
+
// [
|
|
263
|
+
// "bps",
|
|
264
|
+
// "kbps",
|
|
265
|
+
// "mbps",
|
|
266
|
+
// "gbps",
|
|
267
|
+
// "tbps",
|
|
268
|
+
// ],
|
|
269
|
+
// )} in ${totalTimeMS}ms`,
|
|
270
|
+
// );
|
|
271
|
+
}
|
|
272
|
+
catch (xx) {
|
|
273
|
+
if (fs.existsSync(fileName)) {
|
|
274
|
+
fs.unlinkSync(fileName);
|
|
275
|
+
}
|
|
276
|
+
if (fs.existsSync(fileNameOut)) {
|
|
277
|
+
fs.unlinkSync(fileNameOut);
|
|
278
|
+
}
|
|
279
|
+
assert.fail(xx.toString());
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
runTest("1KB");
|
|
284
|
+
runTest("16KB");
|
|
285
|
+
runTest("128KB");
|
|
286
|
+
runTest("512KB");
|
|
287
|
+
runTest("1MB");
|
|
288
|
+
runTest("16MB");
|
|
289
|
+
//runTest("128MB", 1);
|
|
290
|
+
//runTest("128MB", 4);
|
|
291
|
+
//runTest('512MB', 16);
|
|
292
|
+
//runTest('1GB', 32);
|
|
293
|
+
//runTest('5GB', 160);
|
|
294
|
+
//runTest('12GB', 384);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=emitStreamAndReceiveStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitStreamAndReceiveStream.js","sourceRoot":"","sources":["../../../../../src/tests/sb/plugins/events/emitStreamAndReceiveStream.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AAqHH,gEAmOC;AAtVD,yBAAyB;AACzB,iCAAiC;AACjC,mCAAkC;AAElC,iCAAiC;AACjC,6CAAiF;AACjF,0CAAsD;AAEtD,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;AAE7C,MAAM,kBAAkB,GAAG,GAAG,EAAE;IAC9B,MAAM,GAAG,GAAQ;QACf,SAAS,EAAE,EAAE;QACb,IAAI,EAAE,CAAC,IAAS,EAAE,IAAU,EAAE,EAAE;YAC9B,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;gBACtC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QACD,EAAE,EAAE,CAAC,IAAS,EAAE,KAAU,EAAE,EAAE;YAC5B,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC9B,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;QACd,CAAC;KACF,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,QAAa,EAAE,EAAE,CACpC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACzC,yFAAyF;IACzF,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU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,EAAE,CAAC;4BAC5B,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;wBAC1B,CAAC;wBACD,IAAI,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;4BAC/B,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;wBAC7B,CAAC;wBACD,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAC7B,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC;YACF,OAAO,CAAC,KAAK,CAAC,CAAC;YACf,OAAO,CAAC,MAAM,CAAC,CAAC;YAChB,OAAO,CAAC,OAAO,CAAC,CAAC;YACjB,OAAO,CAAC,OAAO,CAAC,CAAC;YACjB,OAAO,CAAC,KAAK,CAAC,CAAC;YACf,OAAO,CAAC,MAAM,CAAC,CAAC;YAChB,sBAAsB;YAEtB,sBAAsB;YACtB,uBAAuB;YACvB,qBAAqB;YACrB,sBAAsB;YACtB,uBAAuB;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { BSBEventsRef } from "../../../../index";
|
|
28
|
+
export declare const RunEventsPluginTests: (eventsPlugin: typeof BSBEventsRef, config?: any) => void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.RunEventsPluginTests = void 0;
|
|
30
|
+
const broadcast_1 = require("./broadcast");
|
|
31
|
+
const emit_1 = require("./emit");
|
|
32
|
+
const emitAndReturn_1 = require("./emitAndReturn");
|
|
33
|
+
const emitStreamAndReceiveStream_1 = require("./emitStreamAndReceiveStream");
|
|
34
|
+
const mocks_1 = require("../../../mocks");
|
|
35
|
+
const trace_1 = require("../../../trace");
|
|
36
|
+
const RunEventsPluginTests = (eventsPlugin, config = undefined) => {
|
|
37
|
+
const obs = (0, trace_1.createTestObservable)();
|
|
38
|
+
(0, broadcast_1.broadcast)(async () => {
|
|
39
|
+
const refP = new eventsPlugin(await (0, mocks_1.getEventsConstructorConfig)(config));
|
|
40
|
+
if (refP.init !== undefined) {
|
|
41
|
+
await refP.init(obs);
|
|
42
|
+
}
|
|
43
|
+
return refP;
|
|
44
|
+
}, 100);
|
|
45
|
+
(0, emit_1.emit)(async () => {
|
|
46
|
+
const refP = new eventsPlugin(await (0, mocks_1.getEventsConstructorConfig)(config));
|
|
47
|
+
if (refP.init !== undefined) {
|
|
48
|
+
await refP.init(obs);
|
|
49
|
+
}
|
|
50
|
+
return refP;
|
|
51
|
+
}, 100);
|
|
52
|
+
(0, emitAndReturn_1.emitAndReturn)(async () => {
|
|
53
|
+
const refP = new eventsPlugin(await (0, mocks_1.getEventsConstructorConfig)(config));
|
|
54
|
+
if (refP.init !== undefined) {
|
|
55
|
+
await refP.init(obs);
|
|
56
|
+
}
|
|
57
|
+
return refP;
|
|
58
|
+
}, 100);
|
|
59
|
+
(0, emitStreamAndReceiveStream_1.emitStreamAndReceiveStream)(async () => {
|
|
60
|
+
const refP = new eventsPlugin(await (0, mocks_1.getEventsConstructorConfig)(config));
|
|
61
|
+
if (refP.init !== undefined) {
|
|
62
|
+
await refP.init(obs);
|
|
63
|
+
}
|
|
64
|
+
//refP.eas.staticCommsTimeout = 25;
|
|
65
|
+
return refP;
|
|
66
|
+
}, 50);
|
|
67
|
+
};
|
|
68
|
+
exports.RunEventsPluginTests = RunEventsPluginTests;
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/tests/sb/plugins/events/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,2CAAwC;AACxC,iCAA8B;AAC9B,mDAAgD;AAChD,6EAA0E;AAI1E,0CAA4D;AAC5D,0CAAsD;AAE/C,MAAM,oBAAoB,GAAG,CAClC,YAAiC,EACjC,SAAc,SAAS,EACvB,EAAE;IACF,MAAM,GAAG,GAAG,IAAA,4BAAoB,GAAE,CAAC;IACnC,IAAA,qBAAS,EAAC,KAAK,IAAI,EAAE;QACnB,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,IAAA,kCAA0B,EAAC,MAAM,CAAC,CAAC,CAAC;QACxE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,GAAG,CAAC,CAAC;IACR,IAAA,WAAI,EAAC,KAAK,IAAI,EAAE;QACd,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,IAAA,kCAA0B,EAAC,MAAM,CAAC,CAAC,CAAC;QACxE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,GAAG,CAAC,CAAC;IACR,IAAA,6BAAa,EAAC,KAAK,IAAI,EAAE;QACvB,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,IAAA,kCAA0B,EAAC,MAAM,CAAC,CAAC,CAAC;QACxE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,GAAG,CAAC,CAAC;IACR,IAAA,uDAA0B,EAAC,KAAK,IAAI,EAAE;QACpC,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,IAAA,kCAA0B,EAAC,MAAM,CAAC,CAAC,CAAC;QACxE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;QACD,mCAAmC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CAAC;AAlCW,QAAA,oBAAoB,wBAkC/B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
3
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
11
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
12
|
+
* including the right to create derivative works that are not subject to the terms
|
|
13
|
+
* of the AGPL.
|
|
14
|
+
*
|
|
15
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
16
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
17
|
+
* will be provided upon request.
|
|
18
|
+
*
|
|
19
|
+
* This program is distributed in the hope that it will be useful,
|
|
20
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
+
* GNU Affero General Public License for more details.
|
|
23
|
+
*
|
|
24
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
25
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
26
|
+
*/
|
|
27
|
+
import { DTrace } from '../interfaces';
|
|
28
|
+
import { Observable } from '../interfaces/observable';
|
|
29
|
+
/**
|
|
30
|
+
* @hidden
|
|
31
|
+
*/
|
|
32
|
+
export declare function createFakeDTrace(trace?: string, span?: string): DTrace;
|
|
33
|
+
/**
|
|
34
|
+
* Create a test Observable with minimal setup for testing
|
|
35
|
+
* @param trace - Optional trace ID (default: 'test-trace')
|
|
36
|
+
* @param span - Optional span ID (default: 'test-span')
|
|
37
|
+
* @param pluginName - Optional plugin name (default: 'test-plugin')
|
|
38
|
+
* @returns Observable for testing
|
|
39
|
+
* @hidden
|
|
40
|
+
*/
|
|
41
|
+
export declare function createTestObservable(trace?: string, span?: string, pluginName?: string): Observable;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BSB (Better-Service-Base) is an event-bus based microservice framework.
|
|
4
|
+
* Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
8
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Alternatively, you may obtain a commercial license for this program.
|
|
12
|
+
* The commercial license allows you to use the Program in a closed-source manner,
|
|
13
|
+
* including the right to create derivative works that are not subject to the terms
|
|
14
|
+
* of the AGPL.
|
|
15
|
+
*
|
|
16
|
+
* To obtain a commercial license, please contact the copyright holders at
|
|
17
|
+
* https://www.bettercorp.dev. The terms and conditions of the commercial license
|
|
18
|
+
* will be provided upon request.
|
|
19
|
+
*
|
|
20
|
+
* This program is distributed in the hope that it will be useful,
|
|
21
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23
|
+
* GNU Affero General Public License for more details.
|
|
24
|
+
*
|
|
25
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
26
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.createFakeDTrace = createFakeDTrace;
|
|
30
|
+
exports.createTestObservable = createTestObservable;
|
|
31
|
+
const PluginObservable_1 = require("../base/PluginObservable");
|
|
32
|
+
/**
|
|
33
|
+
* @hidden
|
|
34
|
+
*/
|
|
35
|
+
function createFakeDTrace(trace, span) {
|
|
36
|
+
return {
|
|
37
|
+
t: trace ?? '',
|
|
38
|
+
s: span ?? '',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a test Observable with minimal setup for testing
|
|
43
|
+
* @param trace - Optional trace ID (default: 'test-trace')
|
|
44
|
+
* @param span - Optional span ID (default: 'test-span')
|
|
45
|
+
* @param pluginName - Optional plugin name (default: 'test-plugin')
|
|
46
|
+
* @returns Observable for testing
|
|
47
|
+
* @hidden
|
|
48
|
+
*/
|
|
49
|
+
function createTestObservable(trace, span, pluginName = 'test-plugin') {
|
|
50
|
+
const dTrace = createFakeDTrace(trace ?? 'test-trace', span ?? 'test-span');
|
|
51
|
+
// Create minimal resource context
|
|
52
|
+
const resource = {
|
|
53
|
+
'service.name': pluginName,
|
|
54
|
+
'service.version': '1.0.0-test',
|
|
55
|
+
'service.instance.id': 'test-instance',
|
|
56
|
+
'deployment.environment': 'test',
|
|
57
|
+
};
|
|
58
|
+
// Create stub unified backend - will be replaced by mocks in tests
|
|
59
|
+
const backend = {
|
|
60
|
+
// Logging methods
|
|
61
|
+
debug: () => { },
|
|
62
|
+
info: () => { },
|
|
63
|
+
warn: () => { },
|
|
64
|
+
error: () => { },
|
|
65
|
+
// Metrics methods
|
|
66
|
+
createCounter: () => ({ increment: () => { } }),
|
|
67
|
+
createGauge: () => ({ set: () => { }, increment: () => { }, decrement: () => { } }),
|
|
68
|
+
createHistogram: () => ({ record: () => { } }),
|
|
69
|
+
createTimer: () => ({ stop: () => 0 }),
|
|
70
|
+
createTrace: (name, attrs) => ({
|
|
71
|
+
id: 'test-trace-id',
|
|
72
|
+
trace: createFakeDTrace('test-trace', 'test-span'),
|
|
73
|
+
error: () => { },
|
|
74
|
+
end: () => { }
|
|
75
|
+
}),
|
|
76
|
+
createSpan: (parentTrace, name, attrs) => ({
|
|
77
|
+
id: 'child-span-' + name,
|
|
78
|
+
trace: createFakeDTrace(parentTrace.t, 'child-span-' + name), // Preserve parent trace ID
|
|
79
|
+
error: () => { },
|
|
80
|
+
end: () => { }
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
return new PluginObservable_1.PluginObservable(dTrace, resource, backend, {});
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../src/tests/trace.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AAUH,4CAKC;AAUD,oDA+CC;AApED,+DAA4D;AAG5D;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAc,EAAE,IAAa;IAC5D,OAAO;QACL,CAAC,EAAE,KAAK,IAAI,EAAE;QACd,CAAC,EAAE,IAAI,IAAI,EAAE;KACd,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,KAAc,EACd,IAAa,EACb,aAAqB,aAAa;IAElC,MAAM,MAAM,G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