summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-02-14 16:18:52 -0500
committerEliot Horowitz <eliot@10gen.com>2011-02-14 16:21:36 -0500
commitac86cdec4778b37f2b58e78c3f759da75c737df0 (patch)
tree157c1c5727968dbadaff9fa46dccea49de6f0476
parent8ed7eabacb742383c4b8c2fc4de7c4795663676c (diff)
downloadmongo-ac86cdec4778b37f2b58e78c3f759da75c737df0.tar.gz
better distlock test
-rw-r--r--client/distlock_test.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/client/distlock_test.cpp b/client/distlock_test.cpp
index 88706e2773f..83d143fcb12 100644
--- a/client/distlock_test.cpp
+++ b/client/distlock_test.cpp
@@ -34,22 +34,17 @@ namespace mongo {
virtual LockType locktype() const { return NONE; }
static void runThread() {
- for ( int i=0; i<1000; i++ ) {
+ while ( keepGoing ) {
if ( current->lock_try( "test" ) ) {
- gotit++;
+ count++;
int before = count;
- for ( int j=0; j<2000; j++ ) {
- count++;
- if ( j % 1000 == 0 ) {
- //sleepmillis(1);
- }
- }
+ sleepmillis( 3 );
int after = count;
- if ( before + 2000 != after ) {
- errors++;
+
+ if ( after != before ) {
error() << " before: " << before << " after: " << after << endl;
}
-
+
current->unlock();
}
}
@@ -62,12 +57,19 @@ namespace mongo {
count = 0;
gotit = 0;
errors = 0;
-
+ keepGoing = true;
+
vector<shared_ptr<boost::thread> > l;
for ( int i=0; i<4; i++ ) {
l.push_back( shared_ptr<boost::thread>( new boost::thread( runThread ) ) );
}
+ int secs = 10;
+ if ( cmdObj["secs"].isNumber() )
+ secs = cmdObj["secs"].numberInt();
+ sleepsecs( secs );
+ keepGoing = false;
+
for ( unsigned i=0; i<l.size(); i++ )
l[i]->join();
@@ -78,22 +80,25 @@ namespace mongo {
result.append( "errors" , errors );
result.append( "timeMS" , t.millis() );
- return count == gotit * 2000 && errors == 0;
+ return errors == 0;
}
// variables for test
static DistributedLock * current;
- static int count;
static int gotit;
static int errors;
+ static AtomicUInt count;
+
+ static bool keepGoing;
} testDistLockWithSyncCmd;
DistributedLock * TestDistLockWithSync::current;
- int TestDistLockWithSync::count;
+ AtomicUInt TestDistLockWithSync::count;
int TestDistLockWithSync::gotit;
int TestDistLockWithSync::errors;
+ bool TestDistLockWithSync::keepGoing;
}