1+ #
2+ # Based on Aphyr's test for CockroachDB.
3+ #
4+
15import unittest
26import time
37import subprocess
48import datetime
9+ import docker
510
6- from toxiproxy import Toxiproxy
711from lib .bank_client import MtmClient
12+ from lib .failure_injector import *
813
14+ TEST_DURATION = 10
15+ TEST_RECOVERY_TIME = 10
916
1017class RecoveryTest (unittest .TestCase ):
1118@classmethod
@@ -23,69 +30,71 @@ def setUpClass(self):
2330 ],n_accounts = 1000 )
2431self .client .bgrun ()
2532
26- # self.toxiproxy = Toxiproxy() #Toxiproxy(server_host="toxi")
27-
28-
2933@classmethod
3034def tearDownClass (self ):
3135print ('tearDown' )
3236self .client .stop ()
37+ # XXX: check nodes data identity here
38+
3339# subprocess.check_call(['docker-compose','down'])
3440
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 )
3762
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 )
4563
4664def test_node_partition (self ):
4765print ('### nodePartitionTest ###' )
4866
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' )
5268
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 )
5573
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 )
7183
84+ # join splitted node
85+ failure .stop ()
7286# clear tx history
73- self .client .get_status ()
87+ self .client .get_status (print = False )
7488
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 ()
8391
84- # check that during last aggregation all nodes were working
8592self .assertTrue (aggs ['transfer_0' ]['finish' ]['commit' ]> 0 )
8693self .assertTrue (aggs ['transfer_1' ]['finish' ]['commit' ]> 0 )
8794self .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 )
8998
9099
91100subprocess .check_call (['blockade' ,'join' ])