Skip to content

Commit

Permalink
DRIVERS-2385: expectedError.errorResponse for asserting server-side e…
Browse files Browse the repository at this point in the history
…rror doc (#1316)

Adds basic tests for expectedError.errorResponse under the unified test format, which are derived from the operation-failure tests in valid-fail.

Also adds tests for write operations (i.e. insert, update, delete, and bulkWrite), which may be problematic for some drivers that use special exceptions such as BulkWriteException, which may not provide direct access to a single response. Note that tests should avoid using errorResponse assertions for such operations and permit drivers to skip those tests as needed.
  • Loading branch information
jmikola authored Oct 14, 2022
1 parent e081028 commit 081578a
Show file tree
Hide file tree
Showing 21 changed files with 1,815 additions and 2 deletions.
118 changes: 118 additions & 0 deletions source/collection-management/tests/modifyCollection-errorResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"description": "modifyCollection-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0",
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "collMod-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"initialData": [
{
"collectionName": "test",
"databaseName": "collMod-tests",
"documents": [
{
"_id": 1,
"x": 1
},
{
"_id": 2,
"x": 1
}
]
}
],
"tests": [
{
"description": "modifyCollection prepareUnique violations are accessible",
"runOnRequirements": [
{
"minServerVersion": "5.2"
}
],
"operations": [
{
"name": "createIndex",
"object": "collection0",
"arguments": {
"keys": {
"x": 1
}
}
},
{
"name": "modifyCollection",
"object": "database0",
"arguments": {
"collection": "test",
"index": {
"keyPattern": {
"x": 1
},
"prepareUnique": true
}
}
},
{
"name": "insertOne",
"object": "collection0",
"arguments": {
"document": {
"_id": 3,
"x": 1
}
},
"expectError": {
"errorCode": 11000
}
},
{
"name": "modifyCollection",
"object": "database0",
"arguments": {
"collection": "test",
"index": {
"keyPattern": {
"x": 1
},
"unique": true
}
},
"expectError": {
"isClientError": false,
"errorCode": 359,
"errorResponse": {
"violations": [
{
"ids": [
1,
2
]
}
]
}
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
description: "modifyCollection-errorResponse"

schemaVersion: "1.12"

createEntities:
- client:
id: &client0 client0
observeEvents: [ commandStartedEvent ]
- database:
id: &database0 database0
client: *client0
databaseName: &database0Name collMod-tests
- collection:
id: &collection0 collection0
database: *database0
collectionName: &collection0Name test

initialData: &initialData
- collectionName: *collection0Name
databaseName: *database0Name
documents:
- { _id: 1, x: 1 }
- { _id: 2, x: 1 }

tests:
- description: "modifyCollection prepareUnique violations are accessible"
runOnRequirements:
- minServerVersion: "5.2" # SERVER-61158
operations:
- name: createIndex
object: *collection0
arguments:
keys: { x: 1 }
- name: modifyCollection
object: *database0
arguments:
collection: *collection0Name
index:
keyPattern: { x: 1 }
prepareUnique: true
- name: insertOne
object: *collection0
arguments:
document: { _id: 3, x: 1 }
expectError:
errorCode: 11000 # DuplicateKey
- name: modifyCollection
object: *database0
arguments:
collection: *collection0Name
index:
keyPattern: { x: 1 }
unique: true
expectError:
isClientError: false
errorCode: 359 # CannotConvertIndexToUnique
errorResponse:
violations:
- { ids: [ 1, 2 ] }
86 changes: 86 additions & 0 deletions source/crud/tests/unified/aggregate-merge-errorResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"description": "aggregate-merge-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"initialData": [
{
"collectionName": "test",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1,
"x": 1
},
{
"_id": 2,
"x": 1
}
]
}
],
"tests": [
{
"description": "aggregate $merge DuplicateKey error is accessible",
"runOnRequirements": [
{
"minServerVersion": "5.1"
}
],
"operations": [
{
"name": "aggregate",
"object": "database0",
"arguments": {
"pipeline": [
{
"$documents": [
{
"_id": 2,
"x": 1
}
]
},
{
"$merge": {
"into": "test",
"whenMatched": "fail"
}
}
]
},
"expectError": {
"errorCode": 11000,
"errorResponse": {
"keyPattern": {
"_id": 1
},
"keyValue": {
"_id": 2
}
}
}
}
]
}
]
}
39 changes: 39 additions & 0 deletions source/crud/tests/unified/aggregate-merge-errorResponse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
description: "aggregate-merge-errorResponse"

schemaVersion: "1.12"

createEntities:
- client:
id: &client0 client0
- database:
id: &database0 database0
client: *client0
databaseName: &database0Name crud-tests
- collection:
id: &collection0 collection0
database: *database0
collectionName: &collection0Name test

initialData: &initialData
- collectionName: *collection0Name
databaseName: *database0Name
documents:
- { _id: 1, x: 1 }
- { _id: 2, x: 1 }

tests:
- description: "aggregate $merge DuplicateKey error is accessible"
runOnRequirements:
- minServerVersion: "5.1" # SERVER-59097

This comment has been minimized.

Copy link
@jmikola

jmikola Oct 14, 2022

Author Member

Forgot to include the requirement to skip this test on sharded clusters. Fixed in 5f8d058

operations:
- name: aggregate
object: *database0
arguments:
pipeline:
- { $documents: [ { _id: 2, x: 1 } ] }
- { $merge: { into: *collection0Name, whenMatched: "fail" } }
expectError:
errorCode: 11000 # DuplicateKey
errorResponse:
keyPattern: { _id: 1 }
keyValue: { _id: 2 }
87 changes: 87 additions & 0 deletions source/crud/tests/unified/bulkWrite-errorResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"description": "bulkWrite-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"tests": [
{
"description": "bulkWrite operations support errorResponse assertions",
"runOnRequirements": [
{
"minServerVersion": "4.0.0",
"topologies": [
"single",
"replicaset"
]
},
{
"minServerVersion": "4.2.0",
"topologies": [
"sharded"
]
}
],
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "client0",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"insert"
],
"errorCode": 8
}
}
}
},
{
"name": "bulkWrite",
"object": "collection0",
"arguments": {
"requests": [
{
"insertOne": {
"document": {
"_id": 1
}
}
}
]
},
"expectError": {
"errorCode": 8,
"errorResponse": {
"code": 8
}
}
}
]
}
]
}
Loading

0 comments on commit 081578a

Please sign in to comment.