summaryrefslogtreecommitdiff
path: root/jstests/parallel/del.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/parallel/del.js')
-rw-r--r--jstests/parallel/del.js81
1 files changed, 38 insertions, 43 deletions
diff --git a/jstests/parallel/del.js b/jstests/parallel/del.js
index 17c97bc499b..3128f89d05e 100644
--- a/jstests/parallel/del.js
+++ b/jstests/parallel/del.js
@@ -3,71 +3,66 @@ load('jstests/libs/parallelTester.js');
N = 1000;
HOST = db.getMongo().host;
-a = db.getSisterDB( "fooa" );
-b = db.getSisterDB( "foob" );
+a = db.getSisterDB("fooa");
+b = db.getSisterDB("foob");
a.dropDatabase();
b.dropDatabase();
-function del1( dbname, host, max ){
- var m = new Mongo( host );
- var db = m.getDB( "foo" + dbname );
+function del1(dbname, host, max) {
+ var m = new Mongo(host);
+ var db = m.getDB("foo" + dbname);
var t = db.del;
- while ( !db.del_parallel.count() ){
+ while (!db.del_parallel.count()) {
var r = Math.random();
- var n = Math.floor( Math.random() * max );
- if ( r < .9 ){
- t.insert( { x : n } );
+ var n = Math.floor(Math.random() * max);
+ if (r < .9) {
+ t.insert({x: n});
+ } else if (r < .98) {
+ t.remove({x: n});
+ } else if (r < .99) {
+ t.remove({x: {$lt: n}});
+ } else {
+ t.remove({x: {$gt: n}});
}
- else if ( r < .98 ){
- t.remove( { x : n } );
- }
- else if ( r < .99 ){
- t.remove( { x : { $lt : n } } );
- }
- else {
- t.remove( { x : { $gt : n } } );
- }
- if ( r > .9999 )
- print( t.count() );
+ if (r > .9999)
+ print(t.count());
}
}
-function del2( dbname, host, max ){
- var m = new Mongo( host );
- var db = m.getDB( "foo" + dbname );
+function del2(dbname, host, max) {
+ var m = new Mongo(host);
+ var db = m.getDB("foo" + dbname);
var t = db.del;
- while ( !db.del_parallel.count() ){
+ while (!db.del_parallel.count()) {
var r = Math.random();
- var n = Math.floor( Math.random() * max );
+ var n = Math.floor(Math.random() * max);
var s = Math.random() > .5 ? 1 : -1;
-
- if ( r < .5 ){
- t.findOne( { x : n } );
- }
- else if ( r < .75 ){
- t.find( { x : { $lt : n } } ).sort( { x : s } ).itcount();
- }
- else {
- t.find( { x : { $gt : n } } ).sort( { x : s } ).itcount();
+
+ if (r < .5) {
+ t.findOne({x: n});
+ } else if (r < .75) {
+ t.find({x: {$lt: n}}).sort({x: s}).itcount();
+ } else {
+ t.find({x: {$gt: n}}).sort({x: s}).itcount();
}
}
}
all = [];
-all.push( fork( del1 , "a", HOST, N ) );
-all.push( fork( del2 , "a", HOST, N ) );
-all.push( fork( del1 , "b", HOST, N ) );
-all.push( fork( del2 , "b", HOST, N ) );
+all.push(fork(del1, "a", HOST, N));
+all.push(fork(del2, "a", HOST, N));
+all.push(fork(del1, "b", HOST, N));
+all.push(fork(del2, "b", HOST, N));
-for ( i=0; i<all.length; i++ )
+for (i = 0; i < all.length; i++)
all[i].start();
-for ( i=0; i<10; i++ ){
- sleep( 2000 );
- print( "dropping" );
+for (i = 0; i < 10; i++) {
+ sleep(2000);
+ print("dropping");
a.dropDatabase();
b.dropDatabase();
}
@@ -75,5 +70,5 @@ for ( i=0; i<10; i++ ){
a.del_parallel.save({done: 1});
b.del_parallel.save({done: 1});
-for ( i=0; i<all.length; i++ )
+for (i = 0; i < all.length; i++)
all[i].join();