Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fe37141

Browse files
committed
raftable test for node out
1 parent ec159fa commit fe37141

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

contrib/raftable/tests/lib/bank_client.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ def start(self):
2525
client.start()
2626

2727
def stop(self):
28-
print('collection stop called', self._clients)
28+
print('Terminating clients')
2929
for client in self._clients:
30-
print('stop coll')
3130
client.stop()
3231

3332

@@ -52,26 +51,33 @@ def check(self):
5251
value = random.randrange(1, 1000000)
5352

5453
event_id = self.history.register_start('setkey')
54+
#print(self.node_id, 'value <- ')
5555
cur.execute("select raftable('rush', '%d', 100)" % (value))
56-
print(self.node_id, 'value <- ', value)
56+
#print(self.node_id, 'value <- ', value)
5757
self.history.register_finish(event_id, 'commit')
5858

5959
event_id = self.history.register_start('readkey')
60+
#print(self.node_id, 'value -> ')
6061
cur.execute("select raftable('rush')")
6162
value = cur.fetchone()[0]
62-
print(self.node_id, 'value -> ', value)
63+
#print(self.node_id, 'value -> ', value)
6364
self.history.register_finish(event_id, 'commit')
6465

6566
cur.close()
6667
conn.close()
6768

69+
# we should clear to queue before exit as non-empty queue
70+
# will block join()
71+
self._history.close()
72+
73+
6874
def start(self):
6975
self.check_process = Process(target=self.check, args=())
7076
self.check_process.start()
7177

7278
def stop(self):
73-
print('Stopping!');
7479
self.run.value = False
75-
self.check_process.join()
80+
self.check_process.terminate()
81+
7682

7783

contrib/raftable/tests/lib/event_history.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,14 @@ def aggregate(self):
9494
def aggregate_by(self, period):
9595
return
9696

97+
def close(self):
98+
print('closing queue')
99+
self.queue.close()
100+
print('clearing queue')
101+
self.load_queue()
102+
print('joining queue')
103+
self.queue.cancel_join_thread()
104+
105+
106+
97107

contrib/raftable/tests/test_recovery.py

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,34 @@ def setUp(self):
1515
self.clients.start()
1616

1717
def tearDown(self):
18-
print('tearDown')
1918
self.clients.stop()
2019
subprocess.check_call(['blockade','join'])
2120

2221
def test_0_normal_operation(self):
2322
print('### normalOpsTest ###')
24-
print('Waiting 10s to check operability')
25-
time.sleep(10)
26-
27-
28-
# def test_1_node_disconnect(self):
29-
# print('### disconnectTest ###')
30-
#
31-
# subprocess.check_call(['blockade','partition','node3'])
32-
# print('Node3 disconnected')
33-
#
34-
# print('Waiting 12s to discover failure')
35-
# time.sleep(12)
36-
# for client in self.clients:
37-
# agg = client.history.aggregate()
38-
# print(agg)
39-
#
40-
# print('Waiting 3s to check operability')
41-
# time.sleep(3)
42-
# for client in self.clients:
43-
# agg = client.history.aggregate()
44-
# print(agg)
45-
#
46-
# subprocess.check_call(['blockade','join'])
47-
# print('Node3 connected back')
48-
#
49-
# print('Waiting 12s for catch-up')
50-
# time.sleep(12)
51-
#
52-
# for client in self.clients:
53-
# agg = client.history.aggregate()
54-
# print(agg)
23+
print('Waiting 5s to check operability')
24+
time.sleep(5)
5525

26+
for client in self.clients:
27+
agg = client.history.aggregate()
28+
print(agg)
29+
# naively check that we did at least some set ops
30+
self.assertTrue(agg['setkey']['commit'] > 10)
31+
32+
def test_1_node_disconnect(self):
33+
print('### disconnectTest ###')
34+
35+
subprocess.check_call(['blockade','partition','node3'])
36+
print('Node3 disconnected')
37+
38+
print('Waiting 5s to discover failure')
39+
time.sleep(5)
40+
41+
for client in self.clients:
42+
agg = client.history.aggregate()
43+
print(agg)
44+
# check we didn't stuck in set op
45+
self.assertTrue(agg['setkey']['running_latency'] < 3)
5646

5747
if __name__ == '__main__':
5848
unittest.main()

0 commit comments

Comments
 (0)