Skip to content

Commit

Permalink
Merge pull request #356 from Expensify/tyler-fix-test-segfault
Browse files Browse the repository at this point in the history
Fix segfault in parallel tests - reviewed, merging
  • Loading branch information
coleaeason authored Jan 25, 2018
2 parents 6c21fa8 + 6bf8274 commit 7607a1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/lib/BedrockTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
string BedrockTester::defaultDBFile;
string BedrockTester::defaultServerAddr;
SData BedrockTester::globalArgs;
mutex BedrockTester::_testersMutex;
set<BedrockTester*> BedrockTester::_testers;
list<string> BedrockTester::locations = {
"../bedrock",
Expand Down Expand Up @@ -33,6 +34,7 @@ string BedrockTester::getServerName() {
}

void BedrockTester::stopAll() {
lock_guard<decltype(_testersMutex)> lock(_testersMutex);
for (auto p : _testers) {
p->stopServer();
}
Expand All @@ -41,7 +43,10 @@ void BedrockTester::stopAll() {
BedrockTester::BedrockTester(const map<string, string>& args, const list<string>& queries, bool startImmediately, bool keepFilesWhenFinished)
: _keepFilesWhenFinished(keepFilesWhenFinished)
{
_testers.insert(this);
{
lock_guard<decltype(_testersMutex)> lock(_testersMutex);
_testers.insert(this);
}

// Set these values from the arguments if provided, or the defaults if not.
try {
Expand Down Expand Up @@ -119,6 +124,7 @@ BedrockTester::~BedrockTester() {
SFileExists((_dbName + "-shm").c_str()) && unlink((_dbName + "-shm").c_str());
SFileExists((_dbName + "-wal").c_str()) && unlink((_dbName + "-wal").c_str());
}
lock_guard<decltype(_testersMutex)> lock(_testersMutex);
_testers.erase(this);
}

Expand Down
3 changes: 3 additions & 0 deletions test/lib/BedrockTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ class BedrockTester {

// A version of the DB that can be queries without going through bedrock.
SQLite* _db = 0;

// For locking around changes to the _testers list.
static mutex _testersMutex;
};

0 comments on commit 7607a1e

Please sign in to comment.