diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-12-23 16:12:11 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-12-23 16:12:11 -0500 |
commit | 66f302878aabe48a5b6a2c0cd496a3b258403171 (patch) | |
tree | 283f60e4227788b774587db7f9241207eb67df33 /jstests | |
parent | 9a315ce29068d4739f6b08eb20d0ba0fe66590af (diff) | |
parent | c7587eac0b2d5e816c52dd29bc784684aababc47 (diff) | |
download | mongo-66f302878aabe48a5b6a2c0cd496a3b258403171.tar.gz |
Merge branch 'master' of github.com:mongodb/mongo
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/basic1.js | 4 | ||||
-rw-r--r-- | jstests/parallel/basic.js | 32 | ||||
-rw-r--r-- | jstests/parallel/shellfork.js | 22 | ||||
-rw-r--r-- | jstests/type1.js | 2 | ||||
-rw-r--r-- | jstests/where2.js | 2 |
5 files changed, 60 insertions, 2 deletions
diff --git a/jstests/basic1.js b/jstests/basic1.js index ecbb0c37941..e5fa577f0b2 100644 --- a/jstests/basic1.js +++ b/jstests/basic1.js @@ -15,3 +15,7 @@ t.save( o ); assert.eq( 2 , t.findOne().a , "second" ); assert(t.validate().valid); + +// not a very good test of currentOp, but tests that it at least +// is sort of there: +assert( db.currentOp().inprog != null ); diff --git a/jstests/parallel/basic.js b/jstests/parallel/basic.js new file mode 100644 index 00000000000..eb298db9a9a --- /dev/null +++ b/jstests/parallel/basic.js @@ -0,0 +1,32 @@ +f = db.jstests_parallel_basic; +f.drop(); +f.ensureIndex( {me:1} ); + +// would be nice to configure and log a random seed so we can reproduce +// behavior. Seems like that's impossible using Math.random(). + +expTimeout = function( mean ) { + return -Math.log( Math.random() ) * mean; +} + +test = function( mean, me ) { + var m = new Mongo( db.getMongo().host ); + var t = m.getDB( "test" ).jstests_parallel_basic; + for( var i = 0; i < 1000; ++i ) { + sleep( expTimeout( mean ) ); + if ( i % 50 == 0 ) { + assert.eq( i, t.count( { who:me } ) ); + print( me + " " + i ); + } + t.insert( { i:i, who:me } ); + } +} + +runners = new Array(); +for( i = 0; i < 10; ++i ) { + runners.push( fork( test, Math.random() * 40, i ) ); +} + +runners.forEach( function( x ) { x.start() } ); +runners.forEach( function( x ) { x.join() } ); + diff --git a/jstests/parallel/shellfork.js b/jstests/parallel/shellfork.js new file mode 100644 index 00000000000..27379506ec3 --- /dev/null +++ b/jstests/parallel/shellfork.js @@ -0,0 +1,22 @@ +a = fork( function( a, b ) { return a / b; }, 10, 2 ); +a.start(); +b = fork( function( a, b, c ) { return a + b + c; }, 18, " is a ", "multiple of 3" ); +makeFunny = function( text ) { + return text + " ha ha!"; +} +c = fork( makeFunny, "paisley" ); +c.start(); +b.start(); +b.join(); +assert.eq( 5, a.returnData() ); +assert.eq( "18 is a multiple of 3", b.returnData() ); +assert.eq( "paisley ha ha!", c.returnData() ); + +z = fork( function( a ) { + var y = fork( function( a ) { + return a + 1; }, 5 ); + y.start(); + return y.returnData() + a; + }, 1 ); +z.start(); +assert.eq( 7, z.returnData() ); diff --git a/jstests/type1.js b/jstests/type1.js index b9fb94f0524..94385fa5bc2 100644 --- a/jstests/type1.js +++ b/jstests/type1.js @@ -2,7 +2,7 @@ t = db.type1; t.drop(); -t.save( { x : 1 } ); +t.save( { x : 1.1 } ); t.save( { x : "3" } ); t.save( { x : "asd" } ); t.save( { x : "foo" } ); diff --git a/jstests/where2.js b/jstests/where2.js index ae7addb4402..9262b3076b3 100644 --- a/jstests/where2.js +++ b/jstests/where2.js @@ -1,5 +1,5 @@ -t = db.getCollection( "where1" ); +t = db.getCollection( "where2" ); t.drop(); t.save( { a : 1 } ); |