Skip to content

Commit c94ae67

Browse files
committed
test(NODE-6098): enable unified valid fail tests
1 parent 357ca08 commit c94ae67

16 files changed

+352
-33
lines changed

test/integration/unified-test-format/unified_test_format.spec.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ const filter: TestFilter = ({ description }) => {
4141
return false;
4242
};
4343

44-
describe('Unified test format runner', function unifiedTestRunner() {
44+
describe('Unified test format runner (valid-pass)', function unifiedTestRunner() {
4545
// Valid tests that should pass
4646
runUnifiedSuite(loadSpecTests('unified-test-format/valid-pass'), filter);
4747
});
48+
49+
describe('Unified test format runner (valid-fail)', function unifiedTestRunner() {
50+
runUnifiedSuite(loadSpecTests('unified-test-format/valid-fail'), () => false, true);
51+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"description": "entity-findCursor-malformed",
3+
"schemaVersion": "1.3",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "database0Name"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "coll0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"databaseName": "database0Name",
28+
"collectionName": "coll0",
29+
"documents": []
30+
}
31+
],
32+
"tests": [
33+
{
34+
"description": "createFindCursor fails if filter is not specified",
35+
"operations": [
36+
{
37+
"name": "createFindCursor",
38+
"object": "collection0",
39+
"saveResultAsEntity": "cursor0"
40+
}
41+
]
42+
}
43+
]
44+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This test is split out into a separate file to accommodate drivers that validate operation structure while decoding
2+
# from JSON/YML. Such drivers fail to decode any files containing invalid operations. Combining this test in a file
3+
# with other entity-findCursor valid-fail tests, which test failures that occur during test execution, would prevent
4+
# such drivers from decoding the file and running any of the tests.
5+
description: entity-findCursor-malformed
6+
7+
schemaVersion: '1.3'
8+
9+
createEntities:
10+
- client:
11+
id: &client0 client0
12+
- database:
13+
id: &database0 database0
14+
client: *client0
15+
databaseName: &database0Name database0Name
16+
- collection:
17+
id: &collection0 collection0
18+
database: *database0
19+
collectionName: &collection0Name coll0
20+
21+
initialData:
22+
- databaseName: *database0Name
23+
collectionName: *collection0Name
24+
documents: []
25+
26+
tests:
27+
- description: createFindCursor fails if filter is not specified
28+
operations:
29+
- name: createFindCursor
30+
object: *collection0
31+
saveResultAsEntity: &cursor0 cursor0
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"description": "entity-findCursor",
3+
"schemaVersion": "1.3",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
},
10+
{
11+
"database": {
12+
"id": "database0",
13+
"client": "client0",
14+
"databaseName": "database0Name"
15+
}
16+
},
17+
{
18+
"collection": {
19+
"id": "collection0",
20+
"database": "database0",
21+
"collectionName": "coll0"
22+
}
23+
}
24+
],
25+
"initialData": [
26+
{
27+
"databaseName": "database0Name",
28+
"collectionName": "coll0",
29+
"documents": []
30+
}
31+
],
32+
"tests": [
33+
{
34+
"description": "iterateUntilDocumentOrError fails if it references a nonexistent entity",
35+
"operations": [
36+
{
37+
"name": "iterateUntilDocumentOrError",
38+
"object": "cursor0"
39+
}
40+
]
41+
},
42+
{
43+
"description": "close fails if it references a nonexistent entity",
44+
"operations": [
45+
{
46+
"name": "close",
47+
"object": "cursor0"
48+
}
49+
]
50+
}
51+
]
52+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
description: entity-findCursor
2+
3+
schemaVersion: '1.3'
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
- database:
9+
id: &database0 database0
10+
client: *client0
11+
databaseName: &database0Name database0Name
12+
- collection:
13+
id: &collection0 collection0
14+
database: *database0
15+
collectionName: &collection0Name coll0
16+
17+
initialData:
18+
- databaseName: *database0Name
19+
collectionName: *collection0Name
20+
documents: []
21+
22+
tests:
23+
- description: iterateUntilDocumentOrError fails if it references a nonexistent entity
24+
operations:
25+
- name: iterateUntilDocumentOrError
26+
object: cursor0
27+
28+
- description: close fails if it references a nonexistent entity
29+
operations:
30+
- name: close
31+
object: cursor0
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"description": "ignoreResultAndError-malformed",
3+
"schemaVersion": "1.3",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0",
8+
"useMultipleMongoses": true
9+
}
10+
},
11+
{
12+
"database": {
13+
"id": "database0",
14+
"client": "client0",
15+
"databaseName": "database0Name"
16+
}
17+
},
18+
{
19+
"collection": {
20+
"id": "collection0",
21+
"database": "database0",
22+
"collectionName": "coll0"
23+
}
24+
}
25+
],
26+
"initialData": [
27+
{
28+
"collectionName": "coll0",
29+
"databaseName": "database0Name",
30+
"documents": []
31+
}
32+
],
33+
"tests": [
34+
{
35+
"description": "malformed operation fails if ignoreResultAndError is true",
36+
"operations": [
37+
{
38+
"name": "insertOne",
39+
"object": "collection0",
40+
"arguments": {
41+
"foo": "bar"
42+
},
43+
"ignoreResultAndError": true
44+
}
45+
]
46+
}
47+
]
48+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This test is split out into a separate file to accommodate drivers that validate operation structure while decoding
2+
# from JSON/YML. Such drivers fail to decode any files containing invalid operations. Combining this test in a file
3+
# with other ignoreResultAndError valid-fail tests, which test failures that occur during test execution, would prevent
4+
# such drivers from decoding the file and running any of the tests.
5+
description: ignoreResultAndError-malformed
6+
7+
schemaVersion: '1.3'
8+
9+
createEntities:
10+
- client:
11+
id: &client0 client0
12+
useMultipleMongoses: true
13+
- database:
14+
id: &database0 database0
15+
client: *client0
16+
databaseName: &database0Name database0Name
17+
- collection:
18+
id: &collection0 collection0
19+
database: *database0
20+
collectionName: &collection0Name coll0
21+
22+
initialData:
23+
- collectionName: *collection0Name
24+
databaseName: *database0Name
25+
documents: []
26+
27+
tests:
28+
- description: malformed operation fails if ignoreResultAndError is true
29+
operations:
30+
- name: insertOne
31+
object: *collection0
32+
arguments:
33+
foo: bar
34+
ignoreResultAndError: true

test/spec/unified-test-format/valid-fail/ignoreResultAndError.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,6 @@
5454
"ignoreResultAndError": false
5555
}
5656
]
57-
},
58-
{
59-
"description": "malformed operation fails if ignoreResultAndError is true",
60-
"operations": [
61-
{
62-
"name": "insertOne",
63-
"object": "collection0",
64-
"arguments": {
65-
"foo": "bar"
66-
},
67-
"ignoreResultAndError": true
68-
}
69-
]
7057
}
7158
]
7259
}

test/spec/unified-test-format/valid-fail/ignoreResultAndError.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,3 @@ tests:
3333
# Insert the same document to force a DuplicateKey error.
3434
document: *insertDocument
3535
ignoreResultAndError: false
36-
37-
- description: malformed operation fails if ignoreResultAndError is true
38-
operations:
39-
- name: insertOne
40-
object: *collection0
41-
arguments:
42-
foo: bar
43-
ignoreResultAndError: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"description": "operation-unsupported",
3+
"schemaVersion": "1.0",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client0"
8+
}
9+
}
10+
],
11+
"tests": [
12+
{
13+
"description": "Unsupported operation",
14+
"operations": [
15+
{
16+
"name": "unsupportedOperation",
17+
"object": "client0"
18+
}
19+
]
20+
}
21+
]
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
description: "operation-unsupported"
2+
3+
schemaVersion: "1.0"
4+
5+
createEntities:
6+
- client:
7+
id: &client0 client0
8+
9+
tests:
10+
- description: "Unsupported operation"
11+
operations:
12+
- name: unsupportedOperation
13+
object: *client0

test/tools/unified-spec-runner/entities.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,17 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
586586
uri = makeConnectionString(config.url({ useMultipleMongoses }), entity.client.uriOptions);
587587
}
588588
const client = new UnifiedMongoClient(uri, entity.client);
589-
new EntityEventRegistry(client, entity.client, map).register();
590589
try {
590+
new EntityEventRegistry(client, entity.client, map).register();
591591
await client.connect();
592592
} catch (error) {
593593
console.error(ejson`failed to connect entity ${entity}`);
594+
// In the case where multiple clients are defined in the test and any one of them failed
595+
// to connect, but others did succeed, we need to ensure all open clients are closed.
596+
const clients = map.mapOf('client');
597+
for (const clientEntry of clients.values()) {
598+
await clientEntry.close();
599+
}
594600
throw error;
595601
}
596602
map.set(entity.client.id, client);
@@ -668,7 +674,7 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
668674
} else if ('stream' in entity) {
669675
throw new Error(`Unsupported Entity ${JSON.stringify(entity)}`);
670676
} else if ('clientEncryption' in entity) {
671-
const clientEncryption = createClientEncryption(map, entity.clientEncryption);
677+
const clientEncryption = await createClientEncryption(map, entity.clientEncryption);
672678

673679
map.set(entity.clientEncryption.id, clientEncryption);
674680
} else {

test/tools/unified-spec-runner/entity_event_registry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ export class EntityEventRegistry {
6060
register(): void {
6161
if (this.clientEntity.storeEventsAsEntities) {
6262
for (const { id, events } of this.clientEntity.storeEventsAsEntities) {
63+
if (this.entitiesMap.has(id) || this.clientEntity.id === id) {
64+
throw new Error(`Duplicate id ${id} found while storing events as entities`);
65+
}
6366
this.entitiesMap.set(id, []);
6467
for (const eventName of events) {
6568
// Need to map the event names to the Node event names.
6669
this.client.on(MAPPINGS[eventName], () => {
67-
this.entitiesMap.getEntity('events', id).push({
70+
const events = this.entitiesMap.getEntity('events', id);
71+
events.push({
6872
name: eventName,
6973
observedAt: Date.now()
7074
});

0 commit comments

Comments
 (0)