summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
Diffstat (limited to 'jstests')
-rw-r--r--jstests/capped6.js2
-rw-r--r--jstests/capped8.js2
-rw-r--r--jstests/extent.js2
-rw-r--r--jstests/extent2.js31
-rw-r--r--jstests/indexb.js3
-rw-r--r--jstests/objid6.js6
-rw-r--r--jstests/repl/drop_dups.js9
-rw-r--r--jstests/replsets/reconfig.js18
-rw-r--r--jstests/replsets/replset_remove_node.js13
-rw-r--r--jstests/replsets/replsetprio1.js75
-rw-r--r--jstests/sharding/mongos_no_detect_sharding.js42
-rw-r--r--jstests/update3.js6
12 files changed, 154 insertions, 55 deletions
diff --git a/jstests/capped6.js b/jstests/capped6.js
index 098f667..5db12b2 100644
--- a/jstests/capped6.js
+++ b/jstests/capped6.js
@@ -105,3 +105,5 @@ tzz = db.capped6;
for( var i = 0; i < 10; ++i ) {
doTest();
}
+
+tzz.drop();
diff --git a/jstests/capped8.js b/jstests/capped8.js
index e5b28dc..0f30e37 100644
--- a/jstests/capped8.js
+++ b/jstests/capped8.js
@@ -104,3 +104,5 @@ print("pass " + pass++);
t.drop();
db._dbCommand( { create:"jstests_capped8", capped: true, $nExtents: [ 10000 ] } );
testTruncate();
+
+t.drop();
diff --git a/jstests/extent.js b/jstests/extent.js
index 8fca699..47ae868 100644
--- a/jstests/extent.js
+++ b/jstests/extent.js
@@ -7,5 +7,5 @@ for ( var i=0; i<50; i++ ) { // enough iterations to break 32 bit.
assert( t.count() == 1 );
t.drop();
}
+t.drop();
-db.dropDatabase();
diff --git a/jstests/extent2.js b/jstests/extent2.js
new file mode 100644
index 0000000..884c3ca
--- /dev/null
+++ b/jstests/extent2.js
@@ -0,0 +1,31 @@
+
+
+mydb = db.getSisterDB( "test_extent2" );
+mydb.dropDatabase();
+
+t = mydb.foo;
+e = mydb["$freelist"]
+
+function insert(){
+ t.insert( { _id : 1 , x : 1 } )
+ t.insert( { _id : 2 , x : 1 } )
+ t.insert( { _id : 3 , x : 1 } )
+ t.ensureIndex( { x : 1 } );
+}
+
+insert();
+t.drop();
+
+start = e.stats();
+
+for ( i=0; i<100; i++ ) {
+ insert();
+ t.drop();
+}
+
+end = e.stats();
+
+printjson( start );
+printjson( end )
+assert.eq( 4 , start.numExtents );
+assert.eq( 4 , end.numExtents );
diff --git a/jstests/indexb.js b/jstests/indexb.js
index 5507fee..d7d2e8c 100644
--- a/jstests/indexb.js
+++ b/jstests/indexb.js
@@ -5,8 +5,7 @@
// when it doesn't move
-t = db.indexb;t = db.indexb;
-db.dropDatabase();
+t = db.indexb;
t.drop();
t.ensureIndex({a:1},true);
diff --git a/jstests/objid6.js b/jstests/objid6.js
index c414ff0..b90dc9e 100644
--- a/jstests/objid6.js
+++ b/jstests/objid6.js
@@ -6,9 +6,11 @@ b = new ObjectId("4c17f616a707428966a2801c");
assert.eq(a.getTimestamp(), b.getTimestamp() , "A" );
x = Math.floor( (new Date()).getTime() / 1000 );
+sleep(10/*ms*/)
a = new ObjectId();
+sleep(10/*ms*/)
z = Math.floor( (new Date()).getTime() / 1000 );
y = a.getTimestamp().getTime() / 1000;
-assert( x <= y , "B" );
-assert( y <= z , "C" );
+assert.lte( x , y , "B" );
+assert.lte( y , z , "C" );
diff --git a/jstests/repl/drop_dups.js b/jstests/repl/drop_dups.js
index 100f469..ccfb768 100644
--- a/jstests/repl/drop_dups.js
+++ b/jstests/repl/drop_dups.js
@@ -40,14 +40,7 @@ function run( createInBackground ) {
function mymap(z) {
return z._id + ":" + z.x + ",";
- }
-
-
- if ( am.serverStatus().mem.bits == 64 ) {
- assert.neq( tojson(am[collName].find().map(mymap)) ,
- tojson(as[collName].find().map(mymap)) , "order is not supposed to be same on master and slave but it is" );
- }
-
+ }
am[collName].ensureIndex( { x : 1 } , { unique : true , dropDups : true , background : createInBackground } );
am.blah.insert( { x : 1 } )
diff --git a/jstests/replsets/reconfig.js b/jstests/replsets/reconfig.js
index 55ee505..7d43720 100644
--- a/jstests/replsets/reconfig.js
+++ b/jstests/replsets/reconfig.js
@@ -60,10 +60,18 @@ replTest.stopSet();
replTest2 = new ReplSetTest({name : 'testSet2', nodes : 1});
nodes = replTest2.startSet();
-result = nodes[0].getDB("admin").runCommand({replSetInitiate : {_id : "testSet2", members : [
- {_id : 0, tags : ["member0"]}
- ]}});
-
-assert(result.errmsg.match(/bad or missing host field/) , "error message doesn't match, got result:" + tojson(result) );
+assert.soon(function() {
+ try {
+ result = nodes[0].getDB("admin").runCommand({replSetInitiate : {_id : "testSet2", members : [
+ {_id : 0, tags : ["member0"]}
+ ]}});
+ printjson(result);
+ return result.errmsg.match(/bad or missing host field/);
+ }
+ catch (e) {
+ print(e);
+ }
+ return false;
+});
replTest2.stopSet();
diff --git a/jstests/replsets/replset_remove_node.js b/jstests/replsets/replset_remove_node.js
index 9fef721..bf99b12 100644
--- a/jstests/replsets/replset_remove_node.js
+++ b/jstests/replsets/replset_remove_node.js
@@ -1,6 +1,6 @@
doTest = function( signal ) {
- // Make sure that we can manually shutdown a remove a
+ // Make sure that we can manually shutdown a remove a
// slave from the configuration.
// Create a new replica set test. Specify set name and the number of nodes you want.
@@ -12,7 +12,14 @@ doTest = function( signal ) {
// Call initiate() to send the replSetInitiate command
// This will wait for initiation
- replTest.initiate();
+ var name = replTest.nodeList();
+ replTest.initiate({"_id" : "testSet",
+ "members" : [
+ // make sure 0 becomes primary so we don't try to remove the
+ // primary below
+ {"_id" : 0, "host" : name[0], priority:2},
+ {"_id" : 1, "host" : name[1]},
+ {"_id" : 2, "host" : name[2]}]});
// Call getMaster to return a reference to the node that's been
// elected master.
@@ -41,7 +48,7 @@ doTest = function( signal ) {
print(e);
}
-
+
// Make sure that a new master comes up
master = replTest.getMaster();
slaves = replTest.liveNodes.slaves;
diff --git a/jstests/replsets/replsetprio1.js b/jstests/replsets/replsetprio1.js
index a002476..aeeb749 100644
--- a/jstests/replsets/replsetprio1.js
+++ b/jstests/replsets/replsetprio1.js
@@ -1,4 +1,3 @@
-// FAILING TEST
// should check that election happens in priority order
doTest = function( signal ) {
@@ -7,47 +6,55 @@ doTest = function( signal ) {
var nodes = replTest.nodeList();
replTest.startSet();
- replTest.node[0].initiate({"_id" : "unicomplex",
+ replTest.initiate({"_id" : "testSet",
"members" : [
- {"_id" : 0, "host" : nodes[0], "priority" : 1},
- {"_id" : 1, "host" : nodes[1], "priority" : 2},
+ {"_id" : 0, "host" : nodes[0], "priority" : 1},
+ {"_id" : 1, "host" : nodes[1], "priority" : 2},
{"_id" : 2, "host" : nodes[2], "priority" : 3}]});
- sleep(10000);
-
- // 2 should be master
- var m3 = replTest.nodes[2].runCommand({ismaster:1})
-
- // FAILS: node[0] is elected master, regardless of priority
- assert(m3.ismaster, 'highest priority is master');
+ // 2 should be master (give this a while to happen, as 0 will be elected, then demoted)
+ assert.soon(function() {
+ var m2 = replTest.nodes[2].getDB("admin").runCommand({ismaster:1});
+ return m2.ismaster;
+ }, 'highest priority is master', 120000);
// kill 2, 1 should take over
- var m3Id = replTest.getNodeId(nodes[2]);
- replTest.stop(m3Id);
-
- sleep(10000);
-
- var m2 = replTest.nodes[1].runCommand({ismaster:1})
- assert(m2.ismaster, 'node 2 is master');
+ replTest.stop(2);
- // bring 2 back up, nothing should happen
- replTest.start(m3Id);
+ // do some writes on 1
+ master = replTest.getMaster();
+ for (i=0; i<1000; i++) {
+ master.getDB("foo").bar.insert({i:i});
+ }
sleep(10000);
- m2 = replTest.nodes[1].runCommand({ismaster:1})
- assert(m2.ismaster, 'node 2 is still master');
-
- // kill 1, 2 should become master
- var m2Id = replTest.getNodeId(nodes[1]);
- replTest.stop(m2Id);
-
- sleep(10000);
-
- m3 = replTest.nodes[2].runCommand({ismaster:1})
- assert(m3.ismaster, 'node 3 is master');
-
- replTest.stopSet( signal );
+ for (i=0; i<1000; i++) {
+ master.getDB("bar").baz.insert({i:i});
+ }
+
+ var m1 = replTest.nodes[1].getDB("admin").runCommand({ismaster:1})
+ assert(m1.ismaster, 'node 2 is master');
+
+ // bring 2 back up, 2 should wait until caught up and then become master
+ replTest.restart(2);
+ assert.soon(function() {
+ try {
+ m2 = replTest.nodes[2].getDB("admin").runCommand({ismaster:1})
+ return m2.ismaster;
+ }
+ catch (e) {
+ print(e);
+ }
+ return false;
+ }, 'node 2 is master again');
+
+ // make sure nothing was rolled back
+ master = replTest.getMaster();
+ for (i=0; i<1000; i++) {
+ assert(master.getDB("foo").bar.findOne({i:i}) != null, 'checking '+i);
+ assert(master.getDB("bar").baz.findOne({i:i}) != null, 'checking '+i);
+ }
}
-//doTest( 15 );
+doTest( 15 );
diff --git a/jstests/sharding/mongos_no_detect_sharding.js b/jstests/sharding/mongos_no_detect_sharding.js
new file mode 100644
index 0000000..d5e9b53
--- /dev/null
+++ b/jstests/sharding/mongos_no_detect_sharding.js
@@ -0,0 +1,42 @@
+// Tests whether new sharding is detected on insert by mongos
+
+var st = new ShardingTest( name = "test", shards = 1, verbose = 2, mongos = 2, other = { separateConfig : true } )
+
+var mongos = st.s
+var config = mongos.getDB("config")
+
+config.settings.update({ _id : "balancer" }, { $set : { stopped : true } }, true )
+
+
+print( "Creating unsharded connection..." )
+
+
+var mongos2 = st._mongos[1]
+
+var coll = mongos2.getCollection( "test.foo" )
+coll.insert({ i : 0 })
+
+print( "Sharding collection..." )
+
+var admin = mongos.getDB("admin")
+
+assert.eq( coll.getShardVersion().ok, 0 )
+
+admin.runCommand({ enableSharding : "test" })
+admin.runCommand({ shardCollection : "test.foo", key : { _id : 1 } })
+
+print( "Seeing if data gets inserted unsharded..." )
+print( "No splits occur here!" )
+
+// Insert a bunch of data which should trigger a split
+for( var i = 0; i < 100; i++ ){
+ coll.insert({ i : i + 1 })
+}
+coll.getDB().getLastError()
+
+config.printShardingStatus( true )
+
+assert.eq( coll.getShardVersion().ok, 1 )
+assert.eq( 101, coll.find().itcount() )
+
+st.stop() \ No newline at end of file
diff --git a/jstests/update3.js b/jstests/update3.js
index 4dfeb90..e49f050 100644
--- a/jstests/update3.js
+++ b/jstests/update3.js
@@ -21,3 +21,9 @@ f.drop();
f.save( {'_id':0} );
f.update( {}, {$set:{'_id':5}} );
assert.eq( 0, f.findOne()._id , "D" );
+
+// Test replacement update of a field with an empty string field name.
+f.drop();
+f.save( {'':0} );
+f.update( {}, {$set:{'':'g'}} );
+assert.eq( 'g', f.findOne()[''] , "E" );