summaryrefslogtreecommitdiff
path: root/src/mongo/s/write_ops/batch_write_op_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/write_ops/batch_write_op_test.cpp')
-rw-r--r--src/mongo/s/write_ops/batch_write_op_test.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/mongo/s/write_ops/batch_write_op_test.cpp b/src/mongo/s/write_ops/batch_write_op_test.cpp
index b21e64c6d53..bfda09f0814 100644
--- a/src/mongo/s/write_ops/batch_write_op_test.cpp
+++ b/src/mongo/s/write_ops/batch_write_op_test.cpp
@@ -32,7 +32,6 @@
#include "mongo/s/concurrency/locker_mongos_client_observer.h"
#include "mongo/s/mock_ns_targeter.h"
#include "mongo/s/session_catalog_router.h"
-#include "mongo/s/shard_cannot_refresh_due_to_locks_held_exception.h"
#include "mongo/s/sharding_router_test_fixture.h"
#include "mongo/s/transaction_router.h"
#include "mongo/s/write_ops/batch_write_op.h"
@@ -235,6 +234,7 @@ TEST_F(BatchWriteOpTest, SingleWriteConcernErrorOrdered) {
insertOp.setDocuments({BSON("x" << 1)});
return insertOp;
}());
+ request.setWriteConcern(BSON("w" << 3));
BatchWriteOp batchOp(_opCtx, request);
@@ -246,6 +246,7 @@ TEST_F(BatchWriteOpTest, SingleWriteConcernErrorOrdered) {
BatchedCommandRequest targetBatch =
batchOp.buildBatchRequest(*targeted.begin()->second, targeter);
+ ASSERT(targetBatch.getWriteConcern().woCompare(request.getWriteConcern()) == 0);
BatchedCommandResponse response;
buildResponse(1, &response);
@@ -304,22 +305,12 @@ TEST_F(BatchWriteOpTest, SingleStaleError) {
batchOp.noteBatchResponse(*targeted.begin()->second, response, nullptr);
ASSERT(!batchOp.isFinished());
- // Respond with a ShardCannotRefreshDueToLocksHeld error; the batch should still be retriable.
- targeted.clear();
- ASSERT_OK(batchOp.targetBatch(targeter, false, &targeted));
- buildResponse(0, &response);
- response.addToErrDetails(write_ops::WriteError(
- 0, Status{ShardCannotRefreshDueToLocksHeldInfo(nss), "mock cache busy error"}));
-
- batchOp.noteBatchResponse(*targeted.begin()->second, response, nullptr);
- ASSERT(!batchOp.isFinished());
-
- // Respond with an 'ok' response
targeted.clear();
ASSERT_OK(batchOp.targetBatch(targeter, false, &targeted));
buildResponse(1, &response);
+ // Respond with an 'ok' response
batchOp.noteBatchResponse(*targeted.begin()->second, response, nullptr);
ASSERT(batchOp.isFinished());
@@ -1010,7 +1001,9 @@ TEST_F(BatchWriteOpTest, MultiOpPartialSingleShardErrorOrdered) {
// Tests of edge-case functionality, lifecycle is assumed to be behaving normally
//
-// Multi-op (unordered) error and write concern error test.
+// Multi-op (unordered) error and write concern error test. We never report the write concern error
+// for single-doc batches, since the error means there's no write concern applied. Don't suppress
+// the error if ordered : false.
TEST_F(BatchWriteOpTest, MultiOpErrorAndWriteConcernErrorUnordered) {
NamespaceString nss("foo.bar");
ShardEndpoint endpoint(ShardId("shard"), ChunkVersion::IGNORED(), boost::none);
@@ -1027,6 +1020,7 @@ TEST_F(BatchWriteOpTest, MultiOpErrorAndWriteConcernErrorUnordered) {
insertOp.setDocuments({BSON("x" << 1), BSON("x" << 1)});
return insertOp;
}());
+ request.setWriteConcern(BSON("w" << 3));
BatchWriteOp batchOp(_opCtx, request);
@@ -1051,7 +1045,8 @@ TEST_F(BatchWriteOpTest, MultiOpErrorAndWriteConcernErrorUnordered) {
ASSERT(clientResponse.isWriteConcernErrorSet());
}
-// Single-op (ordered) error and write concern error test.
+// Single-op (ordered) error and write concern error test. Suppress the write concern error if
+// ordered and we also have an error
TEST_F(BatchWriteOpTest, SingleOpErrorAndWriteConcernErrorOrdered) {
NamespaceString nss("foo.bar");
ShardEndpoint endpointA(ShardId("shardA"), ChunkVersion::IGNORED(), boost::none);
@@ -1069,6 +1064,7 @@ TEST_F(BatchWriteOpTest, SingleOpErrorAndWriteConcernErrorOrdered) {
updateOp.setUpdates({buildUpdate(BSON("x" << GTE << -1 << LT << 2), true)});
return updateOp;
}());
+ request.setWriteConcern(BSON("w" << 3));
BatchWriteOp batchOp(_opCtx, request);
@@ -1095,14 +1091,14 @@ TEST_F(BatchWriteOpTest, SingleOpErrorAndWriteConcernErrorOrdered) {
ASSERT(batchOp.isFinished());
ASSERT(++targetedIt == targeted.end());
- // Ordered reports write concern error.
+ // Ordered doesn't report write concern error
BatchedCommandResponse clientResponse;
batchOp.buildClientResponse(&clientResponse);
ASSERT(clientResponse.getOk());
ASSERT_EQUALS(clientResponse.getN(), 1);
ASSERT(clientResponse.isErrDetailsSet());
ASSERT_EQUALS(clientResponse.sizeErrDetails(), 1u);
- ASSERT(clientResponse.isWriteConcernErrorSet());
+ ASSERT(!clientResponse.isWriteConcernErrorSet());
}
// Targeting failure on second op in batch op (ordered)
@@ -1411,6 +1407,7 @@ TEST_F(BatchWriteOpTest, MultiOpTwoWCErrors) {
insertOp.setDocuments({BSON("x" << -1), BSON("x" << 2)});
return insertOp;
}());
+ request.setWriteConcern(BSON("w" << 3));
BatchWriteOp batchOp(_opCtx, request);