Skip to content

Commit

Permalink
GODRIVER-206 Finish read/write concern implementation
Browse files Browse the repository at this point in the history
Change-Id: I5cef7364a7b57a8fca81aeff7897afdec2463844
  • Loading branch information
saghm committed Feb 7, 2018
1 parent bfe2933 commit 3646f17
Show file tree
Hide file tree
Showing 15 changed files with 1,117 additions and 9 deletions.
68 changes: 68 additions & 0 deletions data/read-write-concern/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
=======================
Connection String Tests
=======================

The YAML and JSON files in this directory tree are platform-independent tests
that drivers can use to prove their conformance to the Read and Write Concern
specification.

Version
-------

Files in the "specifications" repository have no version scheme. They are not
tied to a MongoDB server version, and it is our intention that each
specification moves from "draft" to "final" with no further versions; it is
superseded by a future spec, not revised.

However, implementers must have stable sets of tests to target. As test files
evolve they will be occasionally tagged like "uri-tests-tests-2015-07-16", until
the spec is final.

Format
------

Connection String
~~~~~~~~~~~~~~~~~

These tests are designed to exercise the connection string parsing related
to read concern and write concern.

Each YAML file contains an object with a single ``tests`` key. This key is an
array of test case objects, each of which have the following keys:

- ``description``: A string describing the test.
- ``uri``: A string containing the URI to be parsed.
- ``valid:``: a boolean indicating if parsing the uri should result in an error.
- ``writeConcern:`` A document indicating the expected write concern.
- ``readConcern:`` A document indicating the expected read concern.

If a test case includes a null value for one of these keys, or if the key is missing,
no assertion is necessary. This both simplifies parsing of the test files and allows flexibility
for drivers that might substitute default values *during* parsing.

Document
~~~~~~~~

These tests are designed to ensure compliance with the spec in relation to what should be
sent to the server.

Each YAML file contains an object with a single ``tests`` key. This key is an
array of test case objects, each of which have the following keys:

- ``description``: A string describing the test.
- ``uri``: A string containing the URI to be parsed.
- ``valid:``: a boolean indicating if the write concern created from the document is valid.
- ``writeConcern:`` A document indicating the write concern to use.
- ``writeConcernDocument:`` A document indicating the write concern to be sent to the server.
- ``readConcern:`` A document indicating the read concern to use.
- ``readConcernDocument:`` A document indicating the read concern to be sent to the server.
- ``isServerDefault:`` Indicates whether the read or write concern is considered the server's default.
- ``isAcknowledged:`` Indicates if the write concern should be considered acknowledged.

Use as unit tests
=================

Testing whether a URI is valid or not should simply be a matter of checking
whether URI parsing raises an error or exception.
Testing for emitted warnings may require more legwork (e.g. configuring a log
handler and watching for output).
29 changes: 29 additions & 0 deletions data/read-write-concern/connection-string/read-concern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"tests": [
{
"description": "Default",
"uri": "mongodb://localhost/",
"valid": true,
"warning": false,
"readConcern": {}
},
{
"description": "local specified",
"uri": "mongodb://localhost/?readConcernLevel=local",
"valid": true,
"warning": false,
"readConcern": {
"level": "local"
}
},
{
"description": "majority specified",
"uri": "mongodb://localhost/?readConcernLevel=majority",
"valid": true,
"warning": false,
"readConcern": {
"level": "majority"
}
}
]
}
19 changes: 19 additions & 0 deletions data/read-write-concern/connection-string/read-concern.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
tests:
-
description: "Default"
uri: "mongodb://localhost/"
valid: true
warning: false
readConcern: { }
-
description: "local specified"
uri: "mongodb://localhost/?readConcernLevel=local"
valid: true
warning: false
readConcern: { level: "local" }
-
description: "majority specified"
uri: "mongodb://localhost/?readConcernLevel=majority"
valid: true
warning: false
readConcern: { level: "majority" }
118 changes: 118 additions & 0 deletions data/read-write-concern/connection-string/write-concern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"tests": [
{
"description": "Default",
"uri": "mongodb://localhost/",
"valid": true,
"warning": false,
"writeConcern": {}
},
{
"description": "w as a valid number",
"uri": "mongodb://localhost/?w=1",
"valid": true,
"warning": false,
"writeConcern": {
"w": 1
}
},
{
"description": "w as an invalid number",
"uri": "mongodb://localhost/?w=-2",
"valid": false,
"warning": null
},
{
"description": "w as a string",
"uri": "mongodb://localhost/?w=majority",
"valid": true,
"warning": false,
"writeConcern": {
"w": "majority"
}
},
{
"description": "wtimeoutMS as a valid number",
"uri": "mongodb://localhost/?wtimeoutMS=500",
"valid": true,
"warning": false,
"writeConcern": {
"wtimeoutMS": 500
}
},
{
"description": "wtimeoutMS as an invalid number",
"uri": "mongodb://localhost/?wtimeoutMS=-500",
"valid": false,
"warning": null
},
{
"description": "journal as false",
"uri": "mongodb://localhost/?journal=false",
"valid": true,
"warning": false,
"writeConcern": {
"journal": false
}
},
{
"description": "journal as true",
"uri": "mongodb://localhost/?journal=true",
"valid": true,
"warning": false,
"writeConcern": {
"journal": true
}
},
{
"description": "All options combined",
"uri": "mongodb://localhost/?w=3&wtimeoutMS=500&journal=true",
"valid": true,
"warning": false,
"writeConcern": {
"w": 3,
"wtimeoutMS": 500,
"journal": true
}
},
{
"description": "Unacknowledged with w",
"uri": "mongodb://localhost/?w=0",
"valid": true,
"warning": false,
"writeConcern": {
"w": 0
}
},
{
"description": "Unacknowledged with w and journal",
"uri": "mongodb://localhost/?w=0&journal=false",
"valid": true,
"warning": false,
"writeConcern": {
"w": 0,
"journal": false
}
},
{
"description": "Unacknowledged with w and wtimeoutMS",
"uri": "mongodb://localhost/?w=0&wtimeoutMS=500",
"valid": true,
"warning": false,
"writeConcern": {
"w": 0,
"wtimeoutMS": 500
}
},
{
"description": "Acknowledged with w as 0 and journal true",
"uri": "mongodb://localhost/?w=0&journal=true",
"valid": false,
"warning": false,
"writeConcern": {
"w": 0,
"journal": true
}
}
]
}
77 changes: 77 additions & 0 deletions data/read-write-concern/connection-string/write-concern.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
tests:
-
description: "Default"
uri: "mongodb://localhost/"
valid: true
warning: false
writeConcern: { }
-
description: "w as a valid number"
uri: "mongodb://localhost/?w=1"
valid: true
warning: false
writeConcern: { w: 1 }
-
description: "w as an invalid number"
uri: "mongodb://localhost/?w=-2"
valid: false
warning: ~
-
description: "w as a string"
uri: "mongodb://localhost/?w=majority"
valid: true
warning: false
writeConcern: { w: "majority" }
-
description: "wtimeoutMS as a valid number"
uri: "mongodb://localhost/?wtimeoutMS=500"
valid: true
warning: false
writeConcern: { wtimeoutMS: 500 }
-
description: "wtimeoutMS as an invalid number"
uri: "mongodb://localhost/?wtimeoutMS=-500"
valid: false
warning: ~
-
description: "journal as false"
uri: "mongodb://localhost/?journal=false"
valid: true
warning: false
writeConcern: { journal: false }
-
description: "journal as true"
uri: "mongodb://localhost/?journal=true"
valid: true
warning: false
writeConcern: { journal: true }
-
description: "All options combined"
uri: "mongodb://localhost/?w=3&wtimeoutMS=500&journal=true"
valid: true
warning: false
writeConcern: { w: 3, wtimeoutMS: 500, journal: true }
-
description: "Unacknowledged with w"
uri: "mongodb://localhost/?w=0"
valid: true
warning: false
writeConcern: { w: 0 }
-
description: "Unacknowledged with w and journal"
uri: "mongodb://localhost/?w=0&journal=false"
valid: true
warning: false
writeConcern: { w: 0, journal: false }
-
description: "Unacknowledged with w and wtimeoutMS"
uri: "mongodb://localhost/?w=0&wtimeoutMS=500"
valid: true
warning: false
writeConcern: { w: 0, wtimeoutMS: 500 }
-
description: "Acknowledged with w as 0 and journal true"
uri: "mongodb://localhost/?w=0&journal=true"
valid: false
warning: false
writeConcern: { w: 0, journal: true }
33 changes: 33 additions & 0 deletions data/read-write-concern/document/read-concern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"tests": [
{
"description": "Default",
"valid": true,
"readConcern": {},
"readConcernDocument": {},
"isServerDefault": true
},
{
"description": "Majority",
"valid": true,
"readConcern": {
"level": "majority"
},
"readConcernDocument": {
"level": "majority"
},
"isServerDefault": false
},
{
"description": "Local",
"valid": true,
"readConcern": {
"level": "local"
},
"readConcernDocument": {
"level": "local"
},
"isServerDefault": false
}
]
}
19 changes: 19 additions & 0 deletions data/read-write-concern/document/read-concern.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
tests:
-
description: "Default"
valid: true
readConcern: {}
readConcernDocument: {}
isServerDefault: true
-
description: "Majority"
valid: true
readConcern: { level: "majority" }
readConcernDocument: { level: "majority" }
isServerDefault: false
-
description: "Local"
valid: true
readConcern: { level: "local" }
readConcernDocument: { level: "local" }
isServerDefault: false
Loading

0 comments on commit 3646f17

Please sign in to comment.