Exemplo n.º 1
0
 def test_ping_sp_cmd(self):
     hb = NodeHeartBeat(interval=20)
     ip = '1.1.1.1'
     hb.add('spa', ip)
     hb.update_by_ip(ip, latency=5.123)
     assert_that(' '.join(hb.get_agent(ip)),
                 ends_with('-h 1.1.1.1 -t 35 -np getagent'))
     hb.stop()
Exemplo n.º 2
0
 def test_ping_sp_cmd(self):
     hb = NodeHeartBeat(interval=20)
     ip = '1.1.1.1'
     hb.add('spa', ip)
     hb.update_by_ip(ip, latency=5.123)
     assert_that(' '.join(hb.get_agent(ip)),
                 ends_with('-h 1.1.1.1 -t 35 -np getagent'))
     hb.stop()
Exemplo n.º 3
0
 def test_update_by_ip_latency(self):
     hb = NodeHeartBeat(interval=0.01)
     hb.add('spa', '1.1.1.1', False)
     node = hb.nodes[0]
     assert_that(node.available, equal_to(False))
     time.sleep(0.06)
     assert_that(node.available, equal_to(True))
     assert_that(hb.command_count, greater_than(1))
     hb.stop()
Exemplo n.º 4
0
 def test_update_by_ip_latency(self):
     hb = NodeHeartBeat(interval=0.01)
     hb.add('spa', '1.1.1.1', False)
     node = hb.nodes[0]
     assert_that(node.available, equal_to(False))
     time.sleep(0.06)
     assert_that(node.available, equal_to(True))
     assert_that(hb.command_count, greater_than(1))
     hb.stop()
Exemplo n.º 5
0
 def test_normal(self):
     hb = NodeHeartBeat(interval=0.2)
     hb.add('spa', '1.1.1.1')
     hb.add('spb', '1.1.1.2')
     assert_that(hb.is_available('spa'), equal_to(True))
     assert_that(hb.is_available('spb'), equal_to(True))
     time.sleep(0.5)
     assert_that(hb.is_available('spa'), equal_to(True))
     assert_that(hb.is_available('spb'), equal_to(True))
     hb.stop()
Exemplo n.º 6
0
 def test_credential_error_no_heart_beat(self):
     hb = NodeHeartBeat(interval=0.01)
     hb.add('spa', '1.1.1.1')
     hb.add('spb', '1.1.1.2')
     assert_that(hb.is_available('spa'), equal_to(True))
     assert_that(hb.is_available('spb'), equal_to(True))
     time.sleep(0.1)
     assert_that(hb.command_count, less_than_or_equal_to(2))
     assert_that(hb.command_count, less_than_or_equal_to(2))
     hb.stop()
Exemplo n.º 7
0
 def test_normal(self):
     hb = NodeHeartBeat(interval=0.2)
     hb.add('spa', '1.1.1.1')
     hb.add('spb', '1.1.1.2')
     assert_that(hb.is_available('spa'), equal_to(True))
     assert_that(hb.is_available('spb'), equal_to(True))
     time.sleep(0.5)
     assert_that(hb.is_available('spa'), equal_to(True))
     assert_that(hb.is_available('spb'), equal_to(True))
     hb.stop()
Exemplo n.º 8
0
 def test_credential_error_no_heart_beat(self):
     hb = NodeHeartBeat(interval=0.01)
     hb.add('spa', '1.1.1.1')
     hb.add('spb', '1.1.1.2')
     assert_that(hb.is_available('spa'), equal_to(True))
     assert_that(hb.is_available('spb'), equal_to(True))
     time.sleep(0.1)
     assert_that(hb.command_count, less_than_or_equal_to(2))
     assert_that(hb.command_count, less_than_or_equal_to(2))
     hb.stop()
Exemplo n.º 9
0
 def test_picklable(self):
     hb = NodeHeartBeat(interval=0.1)
     hb.add('spa', '1.1.1.1')
     hb.add('spb', '1.1.1.2')
     time.sleep(0.1)
     hb_new = pickle.loads(pickle.dumps(hb))
     time.sleep(0.3)
     assert_that(hb_new._heartbeat_thread is not None, equal_to(True))
     assert_that(len(hb_new.nodes), equal_to(len(hb.nodes)))
     assert_that(hb_new.interval, equal_to(hb.interval))
     assert_that(hb_new.timeout, equal_to(hb.timeout))
     assert_that([n.ip for n in hb_new.nodes],
                 equal_to([n.ip for n in hb.nodes]))
     hb.stop()
     hb_new.stop()
Exemplo n.º 10
0
 def test_interval_change(self):
     hb = NodeHeartBeat(interval=0.1)
     hb.add('spa', '1.1.1.1')
     hb.add('spb', '1.1.1.2')
     time.sleep(0.5)
     hb.interval = 2
     time.sleep(1)
     # total call count is calculated like this:
     #   interval = 0.1, duration = 0.5, 5 >= cycle >= 4
     #   interval = 2, duration = 1, 0 <= cycle <= 1
     #   4 <= total cycle <= 6
     # each cycle has 2 call (one for each SP)
     # 8 <= total call count <= 12
     assert_that(hb.command_count, less_than_or_equal_to(12))
     assert_that(hb.command_count, greater_than_or_equal_to(8))
     hb.stop()
Exemplo n.º 11
0
 def test_interval_change(self):
     hb = NodeHeartBeat(interval=0.1)
     hb.add('spa', '1.1.1.1')
     hb.add('spb', '1.1.1.2')
     time.sleep(0.5)
     hb.interval = 2
     time.sleep(1)
     # total call count is calculated like this:
     #   interval = 0.1, duration = 0.5, 5 >= cycle >= 4
     #   interval = 2, duration = 1, 0 <= cycle <= 1
     #   4 <= total cycle <= 6
     # each cycle has 2 call (one for each SP)
     # 8 <= total call count <= 12
     assert_that(hb.command_count, less_than_or_equal_to(12))
     assert_that(hb.command_count, greater_than_or_equal_to(8))
     hb.stop()