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

Commit 9d26b3c

Browse files
committed
raftable tests
1 parent 54849ca commit 9d26b3c

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

tests2/lib/bank_client.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class ClientCollection(object):
99
def __init__(self, connstrs):
1010
self._clients = []
1111

12-
for cs in connstrs:
13-
b = BankClient(cs)
12+
for i, cs in enumerate(connstrs):
13+
b = BankClient(cs, i)
1414
self._clients.append(b)
1515

1616
self._clients[0].initialize()
@@ -27,17 +27,21 @@ def start(self):
2727
client.start()
2828

2929
def stop(self):
30+
print('collection stop called', self._clients)
3031
for client in self._clients:
32+
print('stop coll')
3133
client.stop()
3234

3335

3436
class BankClient(object):
3537

36-
def __init__(self, connstr):
38+
def __init__(self, connstr, node_id):
3739
self.connstr = connstr
40+
self.node_id = node_id
3841
self.run = Value('b', True)
3942
self._history = EventHistory()
4043
self.accounts = 10000
44+
self.show_errors = True
4145

4246
def initialize(self):
4347
conn = psycopg2.connect(self.connstr)
@@ -59,6 +63,10 @@ def initialize(self):
5963
def history(self):
6064
return self._history
6165

66+
def print_error(self, arg, comment=''):
67+
if self.show_errors:
68+
print('Node', self.node_id, 'got error', arg, comment)
69+
6270
def check_total(self):
6371
conn, cur = self.connect()
6472

@@ -72,16 +80,13 @@ def check_total(self):
7280
print("Isolation error, total = %d" % (res[0],))
7381
raise BaseException
7482
except psycopg2.InterfaceError:
75-
print("Got error: ", sys.exc_info())
76-
print("Reconnecting")
7783
conn, cur = self.connect(reconnect=True)
7884
except:
79-
print("Got error: ", sys.exc_info())
85+
self.print_error(sys.exc_info(),'3')
8086
self.history.register_finish(event_id, 'rollback')
8187
else:
8288
self.history.register_finish(event_id, 'commit')
8389

84-
8590
cur.close()
8691
conn.close()
8792

@@ -110,14 +115,10 @@ def transfer_money(self):
110115
(amount, to_uid))
111116

112117
conn.commit()
113-
except psycopg2.DatabaseError:
114-
print("Got error: ", sys.exc_info())
115-
print("Reconnecting")
116-
117-
self.history.register_finish(event_id, 'rollback')
118+
except psycopg2.InterfaceError:
118119
conn, cur = self.connect(reconnect=True)
119120
except:
120-
print("Got error: ", sys.exc_info())
121+
self.print_error(sys.exc_info(),'1')
121122
self.history.register_finish(event_id, 'rollback')
122123
else:
123124
self.history.register_finish(event_id, 'commit')
@@ -127,16 +128,17 @@ def transfer_money(self):
127128

128129
def connect(self, reconnect=False):
129130

130-
while self.run.value:
131+
while True:
131132
try:
132133
conn = psycopg2.connect(self.connstr)
133134
cur = conn.cursor()
135+
return conn, cur
134136
except:
135-
print("Got error: ", sys.exc_info())
137+
self.print_error(sys.exc_info(),'2')
136138
if not reconnect:
137139
raise
138-
else:
139-
return conn, cur
140+
if not self.run.value:
141+
raise
140142

141143
# def watchdog(self):
142144
# while self.run.value:
@@ -156,7 +158,10 @@ def start(self):
156158
return
157159

158160
def stop(self):
161+
print('Stopping!');
159162
self.run.value = False
163+
self.total_process.join()
164+
self.transfer_process.join()
160165
return
161166

162167
def cleanup(self):

tests2/test_recovery.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def setUp(self):
1515
self.clients.start()
1616

1717
def tearDown(self):
18+
print('tearDown')
1819
self.clients.stop()
1920
self.clients[0].cleanup()
2021
subprocess.check_call(['blockade','join'])

0 commit comments

Comments
 (0)