Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d26b3c

Browse files
committed
raftable tests
1 parent54849ca commit9d26b3c

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-
forcsinconnstrs:
13-
b=BankClient(cs)
12+
fori,csinenumerate(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
defstop(self):
30+
print('collection stop called',self._clients)
3031
forclientinself._clients:
32+
print('stop coll')
3133
client.stop()
3234

3335

3436
classBankClient(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
definitialize(self):
4347
conn=psycopg2.connect(self.connstr)
@@ -59,6 +63,10 @@ def initialize(self):
5963
defhistory(self):
6064
returnself._history
6165

66+
defprint_error(self,arg,comment=''):
67+
ifself.show_errors:
68+
print('Node',self.node_id,'got error',arg,comment)
69+
6270
defcheck_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
raiseBaseException
7482
exceptpsycopg2.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-
exceptpsycopg2.DatabaseError:
114-
print("Got error: ",sys.exc_info())
115-
print("Reconnecting")
116-
117-
self.history.register_finish(event_id,'rollback')
118+
exceptpsycopg2.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
defconnect(self,reconnect=False):
129130

130-
whileself.run.value:
131+
whileTrue:
131132
try:
132133
conn=psycopg2.connect(self.connstr)
133134
cur=conn.cursor()
135+
returnconn,cur
134136
except:
135-
print("Got error: ",sys.exc_info())
137+
self.print_error(sys.exc_info(),'2')
136138
ifnotreconnect:
137139
raise
138-
else:
139-
returnconn,cur
140+
ifnotself.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
defstop(self):
161+
print('Stopping!');
159162
self.run.value=False
163+
self.total_process.join()
164+
self.transfer_process.join()
160165
return
161166

162167
defcleanup(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
deftearDown(self):
18+
print('tearDown')
1819
self.clients.stop()
1920
self.clients[0].cleanup()
2021
subprocess.check_call(['blockade','join'])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp