summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2013-05-31 09:00:48 -0400
committerEric Milkie <milkie@10gen.com>2013-05-31 09:00:53 -0400
commit445cb8b8fd98aa30af2b0516d2780b27542681dc (patch)
treec9403277ff169c0ad41bb7d0f1ac2247efb324c2 /src/mongo/dbtests
parentca6e91b774b575cbba2f7cc50d1f9a107e94efda (diff)
downloadmongo-445cb8b8fd98aa30af2b0516d2780b27542681dc.tar.gz
SERVER-8536 prevent race conditions in IndexBuilder tests
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r--src/mongo/dbtests/replsettests.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/mongo/dbtests/replsettests.cpp b/src/mongo/dbtests/replsettests.cpp
index bf85d8d1223..d25ca4315dd 100644
--- a/src/mongo/dbtests/replsettests.cpp
+++ b/src/mongo/dbtests/replsettests.cpp
@@ -192,51 +192,72 @@ namespace ReplSetTests {
Client::initThread("in progress idx build");
Client::WriteContext ctx(ns);
- _client = currentClient.get();
+ {
+ boost::mutex::scoped_lock lk(_mtx);
+ _client = currentClient.get();
+ }
// This spins to mimic the db building an index. Yield the read lock so that other
// dbs can be opened (which requires the write lock)
- while (!_curop || !_curop->killPendingStrict()) {
+ while (true) {
dbtemprelease temp;
sleepmillis(10);
+ boost::mutex::scoped_lock lk(_mtx);
+ if (_curop) {
+ if (_curop->killPendingStrict()) {
+ break;
+ }
+ }
}
log() << "index build ending" << endl;
killCurrentOp.notifyAllWaiters();
cc().shutdown();
+
+ boost::mutex::scoped_lock lk(_mtx);
_done = true;
}
// Make sure the test doesn't end while this "index build" is still spinning
void finish() {
- while (!_curop) {
+ while (true) {
sleepmillis(10);
+ boost::mutex::scoped_lock lk(_mtx);
+ if (_curop) break;
}
_curop->kill();
- while (!_done) {
+ while (!finished()) {
sleepmillis(10);
}
}
bool finished() {
+ boost::mutex::scoped_lock lk(_mtx);
return _done;
}
CurOp* curop() {
- if (_curop != NULL) {
- return _curop;
+ {
+ boost::mutex::scoped_lock lk(_mtx);
+ if (_curop != NULL) {
+ return _curop;
+ }
}
- while (_client == NULL) {
+ while (true) {
sleepmillis(10);
+ boost::mutex::scoped_lock lk(_mtx);
+ if (_client) break;
}
+ boost::mutex::scoped_lock lk(_mtx);
// On the first time through, make sure the curop is set up correctly
_client->curop()->reset(HostAndPort::me(), dbInsert);
_client->curop()->enter(_client->getContext());
_client->curop()->setQuery(_index);
+
_curop = _client->curop();
return _curop;
}
@@ -246,6 +267,9 @@ namespace ReplSetTests {
BSONObj _index;
Client* _client;
CurOp* _curop;
+ // Mutex protects all other members of this class, except _index which is
+ // set in the constructor and never subsequently changed
+ boost::mutex _mtx;
};
class TestDropDB : public Base {