Skip to content

Commit

Permalink
Updated retryable-reads tests to latest spec version
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza authored and jyemin committed May 22, 2020
1 parent 9810ce4 commit f9d7705
Show file tree
Hide file tree
Showing 26 changed files with 821 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public void setUp() {
assumeFalse(skipTest);
assumeTrue("Skipping test: " + definition.getString("skipReason", new BsonString("")).getValue(),
!definition.containsKey("skipReason"));
assumeFalse("Skipping list index names tests", filename.startsWith("listIndexNames"));

collectionHelper = new CollectionHelper<Document>(new DocumentCodec(), new MongoNamespace(databaseName, collectionName));

collectionHelper.killAllSessions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ public static List<CommandEvent> getExpectedEvents(final BsonArray expectedEvent
// If the spec test supplies a $db field in the command, then use that database.
if (commandDocument.containsKey("$db")) {
actualDatabaseName = commandDocument.getString("$db").getValue();
}
else if (commandName.equals("commitTransaction") || commandName.equals("abortTransaction")) {
actualDatabaseName = "admin";
} else if (commandName.equals("")) {
commandName = commandDocument.keySet().iterator().next();
}

if (isAdminCommand(commandName)) {
actualDatabaseName = "admin";
}

// Not clear whether these global fields should be included, but also not clear how to efficiently exclude them
if (ClusterFixture.serverVersionAtLeast(3, 6)) {
commandDocument.put("$db", new BsonString(actualDatabaseName));
Expand All @@ -109,6 +111,11 @@ else if (commandName.equals("commitTransaction") || commandName.equals("abortTra
return expectedEvents;
}

private static final List<String> ADMIN_COMMANDS = asList("commitTransaction", "abortTransaction", "listDatabases");
static boolean isAdminCommand(final String commandName) {
return ADMIN_COMMANDS.contains(commandName);
}

static boolean isWriteCommand(final String commandName) {
return asList("insert", "update", "delete").contains(commandName);
}
Expand Down
8 changes: 7 additions & 1 deletion driver-core/src/test/resources/retryable-reads/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ Each YAML file has the following keys:
- ``bucket_name``: Optional. The GridFS bucket name to use for testing.

- ``data``: The data that should exist in the collection(s) under test before
each test run.
each test run. This will typically be an array of documents to be inserted
into the collection under test (i.e. ``collection_name``); however, this field
may also be an object mapping collection names to arrays of documents to be
inserted into the specified collection.

- ``tests``: An array of tests that are to be run independently of each other.
Each test will have some or all of the following fields:
Expand Down Expand Up @@ -126,6 +129,9 @@ GridFS Tests
------------

GridFS tests are denoted by when the YAML file contains ``bucket_name``.
The ``data`` field will also be an object, which maps collection names
(e.g. ``fs.files``) to an array of documents that should be inserted into
the specified collection.

``fs.files`` and ``fs.chunks`` should be created in the database
specified by ``database_name``. This could be done via inserts or by
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"runOn": [
{
"minServerVersion": "4.1.11"
}
],
"database_name": "retryable-reads-tests",
"collection_name": "coll",
"data": [
{
"_id": 1,
"x": 11
},
{
"_id": 2,
"x": 22
},
{
"_id": 3,
"x": 33
}
],
"tests": [
{
"description": "Aggregate with $merge does not retry",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"aggregate"
],
"closeConnection": true
}
},
"operations": [
{
"object": "collection",
"name": "aggregate",
"arguments": {
"pipeline": [
{
"$match": {
"_id": {
"$gt": 1
}
}
},
{
"$sort": {
"x": 1
}
},
{
"$merge": {
"into": "output-collection"
}
}
]
},
"error": true
}
],
"expectations": [
{
"command_started_event": {
"command": {
"aggregate": "coll",
"pipeline": [
{
"$match": {
"_id": {
"$gt": 1
}
}
},
{
"$sort": {
"x": 1
}
},
{
"$merge": {
"into": "output-collection"
}
}
]
},
"command_name": "aggregate",
"database_name": "retryable-reads-tests"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
]
},
{
"description": "Aggregate succeeds after InterruptedDueToStepDown",
"description": "Aggregate succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
]
},
{
"description": "Count succeeds after InterruptedDueToStepDown",
"description": "Count succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
]
},
{
"description": "CountDocuments succeeds after InterruptedDueToStepDown",
"description": "CountDocuments succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
]
},
{
"description": "Distinct succeeds after InterruptedDueToStepDown",
"description": "Distinct succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
]
},
{
"description": "EstimatedDocumentCount succeeds after InterruptedDueToStepDown",
"description": "EstimatedDocumentCount succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
]
},
{
"description": "Find succeeds after InterruptedDueToStepDown",
"description": "Find succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
]
},
{
"description": "FindOne succeeds after InterruptedDueToStepDown",
"description": "FindOne succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
]
},
{
"description": "Download succeeds after InterruptedDueToStepDown",
"description": "Download succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
]
},
{
"description": "DownloadByName succeeds after InterruptedDueToStepDown",
"description": "DownloadByName succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
]
},
{
"description": "ListCollectionNames succeeds after InterruptedDueToStepDown",
"description": "ListCollectionNames succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
]
},
{
"description": "ListCollectionObjects succeeds after InterruptedDueToStepDown",
"description": "ListCollectionObjects succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
]
},
{
"description": "ListCollections succeeds after InterruptedDueToStepDown",
"description": "ListCollections succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]
}
],
"database_name": "admin",
"database_name": "retryable-reads-tests",
"collection_name": "coll",
"data": [],
"tests": [
Expand Down Expand Up @@ -56,7 +56,7 @@
]
},
{
"description": "ListDatabaseNames succeeds after InterruptedDueToStepDown",
"description": "ListDatabaseNames succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]
}
],
"database_name": "admin",
"database_name": "retryable-reads-tests",
"collection_name": "coll",
"data": [],
"tests": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]
}
],
"database_name": "admin",
"database_name": "retryable-reads-tests",
"collection_name": "coll",
"data": [],
"tests": [
Expand Down Expand Up @@ -56,7 +56,7 @@
]
},
{
"description": "ListDatabaseObjects succeeds after InterruptedDueToStepDown",
"description": "ListDatabaseObjects succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]
}
],
"database_name": "admin",
"database_name": "retryable-reads-tests",
"collection_name": "coll",
"data": [],
"tests": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]
}
],
"database_name": "admin",
"database_name": "retryable-reads-tests",
"collection_name": "coll",
"data": [],
"tests": [
Expand Down Expand Up @@ -56,7 +56,7 @@
]
},
{
"description": "ListDatabases succeeds after InterruptedDueToStepDown",
"description": "ListDatabases succeeds after InterruptedDueToReplStateChange",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]
}
],
"database_name": "admin",
"database_name": "retryable-reads-tests",
"collection_name": "coll",
"data": [],
"tests": [
Expand Down
Loading

0 comments on commit f9d7705

Please sign in to comment.