summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2018-11-02 16:48:45 +0100
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2018-11-02 17:08:11 +0100
commit07b22e23018deef35d97045d97c354a65dd4d61f (patch)
tree04f1e0ef8362b29caad480fd5d94ef49c862be79 /src
parentfb0d42af2b81a64f24c0dc274e26cc0956844d08 (diff)
downloadmongo-07b22e23018deef35d97045d97c354a65dd4d61f.tar.gz
SERVER-37244 Fix race condition due to thread execution timing in session_catalog_test
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/session_catalog_test.cpp53
2 files changed, 30 insertions, 24 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 2921ba61b33..518c6a3b29b 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -1977,6 +1977,7 @@ env.CppUnitTest(
'session_catalog_test.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/unittest/concurrency',
'auth/authmocks',
'service_context_d_test_fixture',
'session_catalog',
diff --git a/src/mongo/db/session_catalog_test.cpp b/src/mongo/db/session_catalog_test.cpp
index 09f28e5e6c8..c5e4a52b7c6 100644
--- a/src/mongo/db/session_catalog_test.cpp
+++ b/src/mongo/db/session_catalog_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/session_catalog.h"
#include "mongo/stdx/future.h"
#include "mongo/stdx/memory.h"
+#include "mongo/unittest/barrier.h"
#include "mongo/unittest/death_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/scopeguard.h"
@@ -381,34 +382,38 @@ TEST_F(SessionCatalogTestWithDefaultOpCtx, KillSessionsThroughScanSessions) {
makeLogicalSessionIdForTest()};
std::vector<stdx::future<void>> futures;
+ unittest::Barrier firstUseOfTheSessionReachedBarrier(lsids.size() + 1);
for (const auto& lsid : lsids) {
- futures.emplace_back(stdx::async(stdx::launch::async, [lsid] {
- ON_BLOCK_EXIT([&] { Client::destroy(); });
- Client::initThreadIfNotAlready();
-
- {
- auto sideOpCtx = Client::getCurrent()->makeOperationContext();
- sideOpCtx->setLogicalSessionId(lsid);
-
- OperationContextSession unusedOperationContextSession(sideOpCtx.get(), true);
- ASSERT_THROWS_CODE(sideOpCtx->sleepFor(Hours{6}),
- AssertionException,
- ErrorCodes::ExceededTimeLimit);
- }
-
- {
- auto sideOpCtx = Client::getCurrent()->makeOperationContext();
- sideOpCtx->setLogicalSessionId(lsid);
-
- OperationContextSession unusedOperationContextSession(sideOpCtx.get(), true);
- }
- }));
-
- ASSERT(stdx::future_status::ready !=
- futures.back().wait_for(Milliseconds(10).toSystemDuration()));
+ futures.emplace_back(
+ stdx::async(stdx::launch::async, [lsid, &firstUseOfTheSessionReachedBarrier] {
+ ON_BLOCK_EXIT([&] { Client::destroy(); });
+ Client::initThreadIfNotAlready();
+
+ {
+ auto sideOpCtx = Client::getCurrent()->makeOperationContext();
+ sideOpCtx->setLogicalSessionId(lsid);
+
+ OperationContextSession unusedOperationContextSession(sideOpCtx.get(), true);
+ firstUseOfTheSessionReachedBarrier.countDownAndWait();
+
+ ASSERT_THROWS_CODE(sideOpCtx->sleepFor(Hours{6}),
+ AssertionException,
+ ErrorCodes::ExceededTimeLimit);
+ }
+
+ {
+ auto sideOpCtx = Client::getCurrent()->makeOperationContext();
+ sideOpCtx->setLogicalSessionId(lsid);
+
+ OperationContextSession unusedOperationContextSession(sideOpCtx.get(), true);
+ }
+ }));
}
+ // Make sure all spawned threads have created the session
+ firstUseOfTheSessionReachedBarrier.countDownAndWait();
+
// Kill the first and the third sessions
{
std::vector<Session::KillToken> firstAndThirdTokens;