def test_recovering_member_triggers_refresh(self): # To test that find_one() and count() trigger immediate refreshes, # we'll create a separate client for each self.c_find_one, self.c_count = yield [ motor.MotorReplicaSetClient(self.seed, replicaSet=self.name, read_preference=SECONDARY).open() for _ in range(2) ] # We've started the primary and one secondary primary = ha_tools.get_primary() secondary = ha_tools.get_secondaries()[0] # Pre-condition: just make sure they all connected OK for c in self.c_find_one, self.c_count: self.assertEqual(one(c.secondaries), _partition_node(secondary)) ha_tools.set_maintenance(secondary, True) # Trigger a refresh in various ways with assert_raises(AutoReconnect): yield self.c_find_one.test.test.find_one() with assert_raises(AutoReconnect): yield self.c_count.test.test.count() # Wait for the immediate refresh to complete - we're not waiting for # the periodic refresh, which has been disabled yield self.pause(1) for c in self.c_find_one, self.c_count: self.assertFalse(c.secondaries) self.assertEqual(_partition_node(primary), c.primary)
def test_recovering_member_triggers_refresh(self, done): # To test that find_one() and count() trigger immediate refreshes, # we'll create a separate connection for each self.c_find_one, self.c_count = [ motor.MotorReplicaSetClient( self.seed, replicaSet=self.name, read_preference=SECONDARY ).open_sync() for _ in xrange(2)] # We've started the primary and one secondary primary = ha_tools.get_primary() secondary = ha_tools.get_secondaries()[0] # Pre-condition: just make sure they all connected OK for c in self.c_find_one, self.c_count: self.assertEqual(one(c.secondaries), _partition_node(secondary)) ha_tools.set_maintenance(secondary, True) # Trigger a refresh in various ways yield AssertRaises(AutoReconnect, self.c_find_one.test.test.find_one) yield AssertRaises(AutoReconnect, self.c_count.test.test.count) # Wait for the immediate refresh to complete - we're not waiting for # the periodic refresh, which has been disabled yield gen.Task( IOLoop.instance().add_timeout, time.time() + 1) for c in self.c_find_one, self.c_count: self.assertFalse(c.secondaries) self.assertEqual(_partition_node(primary), c.primary) done()
def test_monitor_removes_recovering_member(self): self.c = motor.MotorReplicaSetClient(self.seed, replicaSet=self.name) yield self.c.open() secondaries = ha_tools.get_secondaries() for mode in SECONDARY, SECONDARY_PREFERRED: partitioned_secondaries = [_partition_node(s) for s in secondaries] yield assert_read_from_all(self, self.c, partitioned_secondaries, mode) secondary, recovering_secondary = secondaries ha_tools.set_maintenance(recovering_secondary, True) yield self.pause(2 * MONITOR_INTERVAL) for mode in SECONDARY, SECONDARY_PREFERRED: # Don't read from recovering member yield assert_read_from(self, self.c, _partition_node(secondary), mode)
def test_monitor_removes_recovering_member(self): self.c = motor.MotorReplicaSetClient(self.seed, replicaSet=self.name) yield self.c.open() secondaries = ha_tools.get_secondaries() for mode in SECONDARY, SECONDARY_PREFERRED: partitioned_secondaries = [_partition_node(s) for s in secondaries] yield assert_read_from_all( self, self.c, partitioned_secondaries, mode) secondary, recovering_secondary = secondaries ha_tools.set_maintenance(recovering_secondary, True) yield self.pause(2 * MONITOR_INTERVAL) for mode in SECONDARY, SECONDARY_PREFERRED: # Don't read from recovering member yield assert_read_from( self, self.c, _partition_node(secondary), mode)
def test_monitor_removes_recovering_member(self, done): self.c = motor.MotorReplicaSetClient( self.seed, replicaSet=self.name).open_sync() secondaries = ha_tools.get_secondaries() for mode in SECONDARY, SECONDARY_PREFERRED: partitioned_secondaries = [_partition_node(s) for s in secondaries] yield motor.Op(assertReadFromAll, self, self.c, partitioned_secondaries, mode) secondary, recovering_secondary = secondaries ha_tools.set_maintenance(recovering_secondary, True) yield gen.Task( IOLoop.instance().add_timeout, time.time() + 2 * MONITOR_INTERVAL) for mode in SECONDARY, SECONDARY_PREFERRED: # Don't read from recovering member yield motor.Op(assertReadFrom, self, self.c, _partition_node(secondary), mode) done()