summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/counttests.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-01-24 11:40:43 -0500
committerBenety Goh <benety@mongodb.com>2019-01-24 11:40:43 -0500
commit7106a8ed5f278c81e10b94a3501b8d3992b4a97e (patch)
tree484fb0efacaaad8368a5cdb1290215bc38836779 /src/mongo/dbtests/counttests.cpp
parent731bc64f8dbbee1def448b10feca305887bdc180 (diff)
downloadmongo-7106a8ed5f278c81e10b94a3501b8d3992b4a97e.tar.gz
SERVER-37643 fix dbtests to avoid creating indexes using DBClient while holding locks
Diffstat (limited to 'src/mongo/dbtests/counttests.cpp')
-rw-r--r--src/mongo/dbtests/counttests.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index a591320a4d4..1781617fc19 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -31,12 +31,13 @@
#include "mongo/platform/basic.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/client.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/dbdirectclient.h"
+#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/json.h"
#include "mongo/dbtests/dbtests.h"
-#include "mongo/stdx/thread.h"
namespace CountTests {
@@ -50,16 +51,24 @@ public:
{
WriteUnitOfWork wunit(&_opCtx);
+
_collection = _database->getCollection(&_opCtx, ns());
if (_collection) {
_database->dropCollection(&_opCtx, ns()).transitional_ignore();
}
_collection = _database->createCollection(&_opCtx, ns());
+
+ IndexCatalog* indexCatalog = _collection->getIndexCatalog();
+ auto indexSpec =
+ BSON("v" << static_cast<int>(IndexDescriptor::kLatestIndexVersion) << "ns" << ns()
+ << "key"
+ << BSON("a" << 1)
+ << "name"
+ << "a_1");
+ uassertStatusOK(indexCatalog->createIndexOnEmptyCollection(&_opCtx, indexSpec));
+
wunit.commit();
}
-
- DBDirectClient client(&_opCtx);
- client.createIndex(ns(), IndexSpec().addKey("a").unique(false));
}
~Base() {