summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/databases_cloner_test.cpp
diff options
context:
space:
mode:
authorADAM David Alan Martin <adam.martin@10gen.com>2019-01-24 18:53:00 -0500
committerADAM David Alan Martin <adam.martin@10gen.com>2019-01-25 11:55:34 -0500
commitc741da0edb4952f58441a5e61b29bc93a0ee596c (patch)
treeefc2988fff5e4b267f11c121bc514bc0f700f31a /src/mongo/db/repl/databases_cloner_test.cpp
parent677a65ba43fecf7cf20b7a2c34b5ec2bed413edd (diff)
downloadmongo-c741da0edb4952f58441a5e61b29bc93a0ee596c.tar.gz
SERVER-38891 Fix some `collection_cloner_test` races.
The mocks in these tests hold pointers to items on the stack. The mocks are held in background threads, such as executors. If the executor accesses one of those mocks after the stack frame of its creator leaves, the pointer to the stack frame is now invalid.
Diffstat (limited to 'src/mongo/db/repl/databases_cloner_test.cpp')
-rw-r--r--src/mongo/db/repl/databases_cloner_test.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/mongo/db/repl/databases_cloner_test.cpp b/src/mongo/db/repl/databases_cloner_test.cpp
index 4340c0a8d51..7463f93ab7c 100644
--- a/src/mongo/db/repl/databases_cloner_test.cpp
+++ b/src/mongo/db/repl/databases_cloner_test.cpp
@@ -1,4 +1,3 @@
-
/**
* Copyright (C) 2018-present MongoDB, Inc.
*
@@ -66,7 +65,7 @@ using namespace unittest;
using Responses = std::vector<std::pair<std::string, BSONObj>>;
struct CollectionCloneInfo {
- CollectionMockStats stats;
+ std::shared_ptr<CollectionMockStats> stats = std::make_shared<CollectionMockStats>();
CollectionBulkLoaderMock* loader = nullptr;
Status status{ErrorCodes::NotYetInitialized, ""};
};
@@ -176,18 +175,20 @@ protected:
[this](const NamespaceString& nss,
const CollectionOptions& options,
const BSONObj idIndexSpec,
- const std::vector<BSONObj>& secondaryIndexSpecs) {
+ const std::vector<BSONObj>& secondaryIndexSpecs)
+ -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> {
// Get collection info from map.
const auto collInfo = &_collections[nss];
- if (collInfo->stats.initCalled) {
+ if (collInfo->stats->initCalled) {
log() << "reusing collection during test which may cause problems, ns:" << nss;
}
- (collInfo->loader = new CollectionBulkLoaderMock(&collInfo->stats))
- ->init(secondaryIndexSpecs)
- .transitional_ignore();
+ auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats);
+ auto status = localLoader->init(secondaryIndexSpecs);
+ if (!status.isOK())
+ return status;
+ collInfo->loader = localLoader.get();
- return StatusWith<std::unique_ptr<CollectionBulkLoader>>(
- std::unique_ptr<CollectionBulkLoader>(collInfo->loader));
+ return std::move(localLoader);
};
_dbWorkThreadPool.startup();