1
+ #
2
+ # Based on Aphyr's test for CockroachDB.
3
+ #
4
+
1
5
import unittest
2
6
import time
3
7
import subprocess
4
8
import datetime
9
+ import docker
5
10
6
- from toxiproxy import Toxiproxy
7
11
from lib .bank_client import MtmClient
12
+ from lib .failure_injector import *
8
13
14
+ TEST_DURATION = 10
15
+ TEST_RECOVERY_TIME = 10
9
16
10
17
class RecoveryTest (unittest .TestCase ):
11
18
@classmethod
@@ -23,69 +30,71 @@ def setUpClass(self):
23
30
], n_accounts = 1000 )
24
31
self .client .bgrun ()
25
32
26
- # self.toxiproxy = Toxiproxy() #Toxiproxy(server_host="toxi")
27
-
28
-
29
33
@classmethod
30
34
def tearDownClass (self ):
31
35
print ('tearDown' )
32
36
self .client .stop ()
37
+ # XXX: check nodes data identity here
38
+
33
39
# subprocess.check_call(['docker-compose','down'])
34
40
35
- # def test_normal_operations(self):
36
- # print('### normalOpsTest ###')
41
+ def test_normal_operations (self ):
42
+ print ('### normal_operations ###' )
43
+
44
+ # nofailure here
45
+ # clean aggregates
46
+ self .client .get_status ()
47
+
48
+ time .sleep (TEST_DURATION )
49
+ aggs = self .client .get_status ()
50
+
51
+ for agg in aggs :
52
+ self .assertTrue ( aggs [agg ]['finish' ]['commit' ] > 0 )
53
+
54
+ # nofailure ends here
55
+ self .client .get_status ()
56
+
57
+ time .sleep (TEST_RECOVERY_TIME )
58
+ aggs = self .client .get_status ()
59
+
60
+ for agg in aggs :
61
+ self .assertTrue ( aggs [agg ]['finish' ]['commit' ] > 0 )
37
62
38
- # for i in range(3):
39
- # time.sleep(3)
40
- # aggs = self.client.get_status()
41
- # MtmClient.print_aggregates(aggs)
42
- # print(aggs)
43
- # for agg in aggs:
44
- # self.assertTrue( aggs[agg]['finish']['commit'] > 0 )
45
63
46
64
def test_node_partition (self ):
47
65
print ('### nodePartitionTest ###' )
48
66
49
- # print('### split node3 ###')
50
- # for proxy in ['rep31', 'rep32', 'rep23', 'rep13', 'arb31', 'arb32', 'arb23', 'arb13']:
51
- # self.toxiproxy.get_proxy(proxy).disable()
67
+ failure = SingleNodePartition ('node3' )
52
68
53
- # clear tx history
54
- self .client .get_status ()
69
+ # split one node
70
+ failure .start ()
71
+ # clean aggregates
72
+ self .client .get_status (print = False )
55
73
56
- for i in range (1000 ):
57
- print (i , datetime .datetime .now ())
58
- time .sleep (3 )
59
- aggs = self .client .get_status ()
60
- MtmClient .print_aggregates (aggs )
61
- # self.assertTrue( aggs['transfer_0']['finish']['commit'] > 0 )
62
- # self.assertTrue( aggs['transfer_1']['finish']['commit'] > 0 )
63
- # self.assertTrue( aggs['transfer_2']['finish']['commit'] == 0 )
64
- self .assertTrue ( aggs ['sumtotal_0' ]['isolation' ] == 0 )
65
- self .assertTrue ( aggs ['sumtotal_1' ]['isolation' ] == 0 )
66
- self .assertTrue ( aggs ['sumtotal_2' ]['isolation' ] == 0 )
67
-
68
- # print('### join node3 ###')
69
- # for proxy in ['rep31', 'rep32', 'rep23', 'rep13', 'arb31', 'arb32', 'arb23', 'arb13']:
70
- # self.toxiproxy.get_proxy(proxy).enable()
74
+ time .sleep (TEST_DURATION )
75
+ aggs = self .client .get_status ()
76
+
77
+ self .assertTrue ( aggs ['transfer_0' ]['finish' ]['commit' ] > 0 )
78
+ self .assertTrue ( aggs ['transfer_1' ]['finish' ]['commit' ] > 0 )
79
+ self .assertTrue ( 'commit' not in aggs ['transfer_2' ]['finish' ] )
80
+ self .assertTrue ( aggs ['sumtotal_0' ]['isolation' ] == 0 )
81
+ self .assertTrue ( aggs ['sumtotal_1' ]['isolation' ] == 0 )
82
+ self .assertTrue ( aggs ['sumtotal_2' ]['isolation' ] == 0 )
71
83
84
+ # join splitted node
85
+ failure .stop ()
72
86
# clear tx history
73
- self .client .get_status ()
87
+ self .client .get_status (print = False )
74
88
75
- for i in range (5 ):
76
- print (i , datetime .datetime .now ())
77
- time .sleep (3 )
78
- aggs = self .client .get_status ()
79
- MtmClient .print_aggregates (aggs )
80
- self .assertTrue ( aggs ['sumtotal_0' ]['isolation' ] == 0 )
81
- self .assertTrue ( aggs ['sumtotal_1' ]['isolation' ] == 0 )
82
- self .assertTrue ( aggs ['sumtotal_2' ]['isolation' ] == 0 )
89
+ time .sleep (TEST_RECOVERY_TIME )
90
+ aggs = self .client .get_status ()
83
91
84
- # check that during last aggregation all nodes were working
85
92
self .assertTrue ( aggs ['transfer_0' ]['finish' ]['commit' ] > 0 )
86
93
self .assertTrue ( aggs ['transfer_1' ]['finish' ]['commit' ] > 0 )
87
94
self .assertTrue ( aggs ['transfer_2' ]['finish' ]['commit' ] > 0 )
88
-
95
+ self .assertTrue ( aggs ['sumtotal_0' ]['isolation' ] == 0 )
96
+ self .assertTrue ( aggs ['sumtotal_1' ]['isolation' ] == 0 )
97
+ self .assertTrue ( aggs ['sumtotal_2' ]['isolation' ] == 0 )
89
98
90
99
91
100
subprocess .check_call (['blockade' ,'join' ])
0 commit comments