summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/shard_local_test.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2020-10-27 12:10:55 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-10-27 16:27:22 +0000
commit3aafc656417787ad650701cc55f3a95dc8e75741 (patch)
treeadc61f86ae6eb06ef83a492405fbea9bff4c429a /src/mongo/db/s/shard_local_test.cpp
parent2ccf0fe0175419ae3563b3f435723157b5c8b693 (diff)
downloadmongo-3aafc656417787ad650701cc55f3a95dc8e75741.tar.gz
SERVER-51733 add test case for ShardLocal::createIndexOnConfig() with non-empty collections
Diffstat (limited to 'src/mongo/db/s/shard_local_test.cpp')
-rw-r--r--src/mongo/db/s/shard_local_test.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/db/s/shard_local_test.cpp b/src/mongo/db/s/shard_local_test.cpp
index 4945d7a1c04..c551347b2bf 100644
--- a/src/mongo/db/s/shard_local_test.cpp
+++ b/src/mongo/db/s/shard_local_test.cpp
@@ -32,6 +32,7 @@
#include "mongo/client/read_preference.h"
#include "mongo/db/catalog_raii.h"
#include "mongo/db/client.h"
+#include "mongo/db/dbdirectclient.h"
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/query/find_and_modify_request.h"
#include "mongo/db/repl/replication_coordinator.h"
@@ -40,6 +41,7 @@
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/s/client/shard_registry.h"
+#include "mongo/unittest/death_test.h"
namespace mongo {
namespace {
@@ -270,5 +272,17 @@ TEST_F(ShardLocalTest, CreateIndex) {
ASSERT_EQ(2U, indexes.size());
}
+DEATH_TEST_REGEX_F(ShardLocalTest, CreateIndexNonEmptyCollection, "Invariant failure.*isEmpty") {
+ NamespaceString nss("config.foo");
+
+ ASSERT_EQUALS(ErrorCodes::NamespaceNotFound, getIndexes(nss).getStatus());
+
+ // Inserting the document should implicitly create the collection
+ DBDirectClient dbDirectClient(_opCtx.get());
+ dbDirectClient.insert(nss.toString(), BSON("_id" << 1 << "a" << 1));
+
+ _shardLocal->createIndexOnConfig(_opCtx.get(), nss, BSON("a" << 1), false).ignore();
+}
+
} // namespace
} // namespace mongo