summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-02-14 12:39:53 -0500
committerEliot Horowitz <eliot@10gen.com>2011-02-14 12:39:53 -0500
commit6dee6f9498d0f5d2d5a5eac8e92fb9ff62124105 (patch)
tree82833331f0f7c7a504eb272b6f7361fb647977bc
parent1e5d77f29792f82026df86b3a96323b66aac00c0 (diff)
downloadmongo-6dee6f9498d0f5d2d5a5eac8e92fb9ff62124105.tar.gz
better test
-rw-r--r--client/distlock_test.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/client/distlock_test.cpp b/client/distlock_test.cpp
index 8cc28e37479..88706e2773f 100644
--- a/client/distlock_test.cpp
+++ b/client/distlock_test.cpp
@@ -37,37 +37,55 @@ namespace mongo {
for ( int i=0; i<1000; i++ ) {
if ( current->lock_try( "test" ) ) {
gotit++;
+ int before = count;
for ( int j=0; j<2000; j++ ) {
count++;
+ if ( j % 1000 == 0 ) {
+ //sleepmillis(1);
+ }
}
+ int after = count;
+ if ( before + 2000 != after ) {
+ errors++;
+ error() << " before: " << before << " after: " << after << endl;
+ }
+
current->unlock();
}
}
}
-
+
bool run(const string& , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
+ Timer t;
DistributedLock lk( ConnectionString( cmdObj["host"].String() , ConnectionString::SYNC ), "testdistlockwithsync" );
current = &lk;
count = 0;
gotit = 0;
+ errors = 0;
vector<shared_ptr<boost::thread> > l;
for ( int i=0; i<4; i++ ) {
l.push_back( shared_ptr<boost::thread>( new boost::thread( runThread ) ) );
}
-
+
for ( unsigned i=0; i<l.size(); i++ )
l[i]->join();
+ current = 0;
+
result.append( "count" , count );
result.append( "gotit" , gotit );
- current = 0;
- return count == gotit * 2000;
- }
+ result.append( "errors" , errors );
+ result.append( "timeMS" , t.millis() );
+ return count == gotit * 2000 && errors == 0;
+ }
+
+ // variables for test
static DistributedLock * current;
static int count;
static int gotit;
+ static int errors;
} testDistLockWithSyncCmd;
@@ -75,6 +93,7 @@ namespace mongo {
DistributedLock * TestDistLockWithSync::current;
int TestDistLockWithSync::count;
int TestDistLockWithSync::gotit;
+ int TestDistLockWithSync::errors;
}