Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

replsetfreeze test SERVER-1940

  • Loading branch information...
commit ac2dc245b272e3d84a110b3f7120416d52ee26d5 1 parent 522303d
Kristina authored October 26, 2010

Showing 1 changed file with 105 additions and 0 deletions. Show diff stats Hide diff stats

  1. 105  jstests/replsets/replsetfreeze.js
105  jstests/replsets/replsetfreeze.js
... ...
@@ -0,0 +1,105 @@
  1
+/*
  2
+ * 1: initialize set
  3
+ * 2: step down m1
  4
+ * 3: freeze set for 30 seconds
  5
+ * 4: check no one is master for 30 seconds
  6
+ * 5: check for new master
  7
+ * 6: step down new master
  8
+ * 7: freeze for 30 seconds
  9
+ * 8: unfreeze
  10
+ * 9: check we get a new master within 30 seconds
  11
+ */
  12
+
  13
+
  14
+var w = 0;
  15
+var wait = function(f) {
  16
+    w++;
  17
+    var n = 0;
  18
+    while (!f()) {
  19
+        if( n % 4 == 0 )
  20
+            print("toostale.js waiting " + w);
  21
+        if (++n == 4) {
  22
+            print("" + f);
  23
+        }
  24
+        assert(n < 200, 'tried 200 times, giving up');
  25
+        sleep(1000);
  26
+    }
  27
+}
  28
+
  29
+var reconnect = function(a) {
  30
+  wait(function() { 
  31
+      try {
  32
+        a.getDB("foo").bar.stats();
  33
+        return true;
  34
+      } catch(e) {
  35
+        print(e);
  36
+        return false;
  37
+      }
  38
+    });
  39
+};
  40
+
  41
+
  42
+print("1: initialize set");
  43
+var replTest = new ReplSetTest( {name: 'unicomplex', nodes: 3} );
  44
+var nodes = replTest.nodeList();
  45
+var conns = replTest.startSet();
  46
+var config = {"_id" : "unicomplex", "members" : [
  47
+    {"_id" : 0, "host" : nodes[0] },
  48
+    {"_id" : 1, "host" : nodes[1] },
  49
+    {"_id" : 2, "host" : nodes[2], "arbiterOnly" : true}]};
  50
+var r = replTest.initiate(config);
  51
+var master = replTest.getMaster();
  52
+
  53
+
  54
+print("2: step down m1");
  55
+try {
  56
+  master.getDB("admin").runCommand({replSetStepDown : 1});
  57
+}
  58
+catch(e) {
  59
+  print(e);
  60
+}
  61
+reconnect(master);
  62
+
  63
+print("3: freeze set for 30 seconds");
  64
+master.getDB("admin").runCommand({replSetFreeze : 30});
  65
+
  66
+
  67
+print("4: check no one is master for 30 seconds");
  68
+var start = (new Date()).getTime();
  69
+while ((new Date()).getTime() - start < 30000) {
  70
+  var result = master.getDB("admin").runCommand({isMaster:1});
  71
+  assert.eq(result.ismaster, false);
  72
+  assert.eq(result.primary, undefined);
  73
+  sleep(1000);
  74
+}
  75
+
  76
+
  77
+print("5: check for new master");
  78
+master = replTest.getMaster();
  79
+
  80
+
  81
+print("6: step down new master");
  82
+try {
  83
+  master.getDB("admin").runCommand({replSetStepDown : 1});
  84
+}
  85
+catch(e) {
  86
+  print(e);
  87
+}
  88
+reconnect(master);
  89
+
  90
+
  91
+print("7: freeze for 30 seconds");
  92
+master.getDB("admin").runCommand({replSetFreeze : 30});
  93
+sleep(1000);
  94
+
  95
+
  96
+print("8: unfreeze");
  97
+master.getDB("admin").runCommand({replSetFreeze : 0});
  98
+
  99
+
  100
+print("9: check we get a new master within 30 seconds");
  101
+master = replTest.getMaster();
  102
+
  103
+
  104
+replTest.stopSet( 15 );
  105
+

0 notes on commit ac2dc24

Please sign in to comment.
Something went wrong with that request. Please try again.