Skip to content

Commit ea6c1f7

Browse files
committed
Fix: Use unique stream names in tests to avoid cross-run collisions
Stream tests used hardcoded names ("Test Stream", "Child Stream") which collided across test runs since the test user persists. Now appending a cuid suffix to all names. Also: silently ignore double-load of SocketIO add-on instead of throwing.
1 parent af43f83 commit ea6c1f7

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

components/pryv-socket.io/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function (pryv) {
1212
console.log('"pryv" lib version', pryv.version);
1313
// check version here
1414
if (pryv.Connection.SocketIO) {
15-
throw new Error('Socket.IO add-on already loaded');
15+
return; // already loaded
1616
}
1717
// sharing cross references
1818
pryv.Connection.SocketIO = SocketIO;

components/pryv/test/Streams.test.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
const { createId: cuid } = require('@paralleldrive/cuid2');
88

99
let conn = null;
10-
const testStreamId = 'str-' + cuid().slice(0, 8);
11-
const childStreamId = 'str-child-' + cuid().slice(0, 8);
10+
const suffix = cuid().slice(0, 8);
11+
const testStreamId = 'str-' + suffix;
12+
const childStreamId = 'str-child-' + suffix;
13+
const testStreamName = 'Test Stream ' + suffix;
14+
const childStreamName = 'Child Stream ' + suffix;
1215

1316
describe('[STRX] Streams', () => {
1417
before(async function () {
@@ -21,18 +24,18 @@ describe('[STRX] Streams', () => {
2124
it('[SCRA] create a root stream', async () => {
2225
const res = await conn.api([{
2326
method: 'streams.create',
24-
params: { id: testStreamId, name: 'Test Stream' }
27+
params: { id: testStreamId, name: testStreamName }
2528
}]);
2629
expect(res[0]).to.exist;
2730
expect(res[0].stream).to.exist;
2831
expect(res[0].stream.id).to.equal(testStreamId);
29-
expect(res[0].stream.name).to.equal('Test Stream');
32+
expect(res[0].stream.name).to.equal(testStreamName);
3033
});
3134

3235
it('[SCRB] create a child stream', async () => {
3336
const res = await conn.api([{
3437
method: 'streams.create',
35-
params: { id: childStreamId, name: 'Child Stream', parentId: testStreamId }
38+
params: { id: childStreamId, name: childStreamName, parentId: testStreamId }
3639
}]);
3740
expect(res[0]).to.exist;
3841
expect(res[0].stream).to.exist;
@@ -42,7 +45,7 @@ describe('[STRX] Streams', () => {
4245
it('[SCRC] reject duplicate stream id', async () => {
4346
const res = await conn.api([{
4447
method: 'streams.create',
45-
params: { id: testStreamId, name: 'Duplicate' }
48+
params: { id: testStreamId, name: 'Duplicate ' + suffix }
4649
}]);
4750
expect(res[0]).to.exist;
4851
expect(res[0].error).to.exist;
@@ -80,11 +83,11 @@ describe('[STRX] Streams', () => {
8083
it('[SUPA] rename a stream', async () => {
8184
const res = await conn.api([{
8285
method: 'streams.update',
83-
params: { id: childStreamId, update: { name: 'Renamed Child' } }
86+
params: { id: childStreamId, update: { name: 'Renamed ' + suffix } }
8487
}]);
8588
expect(res[0]).to.exist;
8689
expect(res[0].stream).to.exist;
87-
expect(res[0].stream.name).to.equal('Renamed Child');
90+
expect(res[0].stream.name).to.equal('Renamed ' + suffix);
8891
});
8992
});
9093

0 commit comments

Comments
 (0)