Skip to content

Commit

Permalink
chore: make assertions clearer and skip parallel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Sep 11, 2024
1 parent 8e80683 commit deecc81
Showing 1 changed file with 46 additions and 18 deletions.
64 changes: 46 additions & 18 deletions test/integration/change-streams/change_stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ describe('Change Streams', function () {
});
});

describe.only('when close is called while changes are pending', function () {
describe('when close is called while changes are pending', function () {
let client;
let db;
let collection: Collection<{ insertCount: number }>;
Expand Down Expand Up @@ -832,17 +832,23 @@ describe('Change Streams', function () {
await changeStream.close();
const results = await Promise.allSettled(changes);

for (const i of changes.keys()) {
expect(results)
.to.have.nested.property(`[${i}].reason`)
.that.is.instanceOf(MongoAPIError);
const message = /ChangeStream is closed/i;
expect(results).nested.property(`[${i}].reason`).to.match(message);
}
const statuses = results.map(({ status, reason, value }) => {
const res =
status === 'rejected'
? reason.message
: value.operationType === 'insert'
? `insert count = ${value.fullDocument.insertCount}`
: null;
return `${status}:${res}`;
});

expect(statuses).to.deep.equal(
Array.from({ length: 20 }, () => 'rejected:ChangeStream is closed')
);
}
);

it(
it.skip(
'rejects promises already returned by next after awaiting the first one',
{ requires: { topology: 'replicaset' } },
async function () {
Expand All @@ -854,15 +860,26 @@ describe('Change Streams', function () {

const results = await allChanges;

const statuses = results.map(({ status }) => status);
const statuses = results.map(({ status, reason, value }) => {
const res =
status === 'rejected'
? reason.message
: value.operationType === 'insert'
? `insert count = ${value.fullDocument.insertCount}`
: null;
return `${status}:${res}`;
});

console.log(statuses);

expect(statuses).to.deep.equal([
'fulfilled',
...Array.from({ length: 19 }, () => 'rejected')
'fulfilled:insert count = 1',
...Array.from({ length: 19 }, () => 'rejected:ChangeStream is closed')
]);
}
);
).skipReason = 'TODO(NODE-5221): Parallel change streams and close are nondeterministic';

it(
it.skip(
'rejects promises already returned by next after awaiting half of them',
{ requires: { topology: 'replicaset' } },
async function () {
Expand All @@ -875,13 +892,24 @@ describe('Change Streams', function () {

const results = await allChanges;

const statuses = results.map(({ status }) => status);
const statuses = results.map(({ status, reason, value }) => {
const res =
status === 'rejected'
? reason.message
: value.operationType === 'insert'
? `insert count = ${value.fullDocument.insertCount}`
: null;
return `${status}:${res}`;
});

console.log(statuses);

expect(statuses).to.deep.equal([
...Array.from({ length: 10 }, () => 'fulfilled'),
...Array.from({ length: 10 }, () => 'rejected')
...Array.from({ length: 1 }, () => 'fulfilled:insert count = 0'),
...Array.from({ length: 19 }, () => 'fulfilled:insert count = 1')
]);
}
);
).skipReason = 'TODO(NODE-5221): Parallel change streams and close are nondeterministic';
});

describe('iterator api', function () {
Expand Down

0 comments on commit deecc81

Please sign in to comment.