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

Commit6e077eb

Browse files
committed
handle keyboard interrupt
1 parentac1ac79 commit6e077eb

File tree

3 files changed

+97
-47
lines changed

3 files changed

+97
-47
lines changed

‎tests2/docker-entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ if [ "$1" = 'postgres' ]; then
7373
max_replication_slots = 10
7474
max_wal_senders = 10
7575
shared_preload_libraries = 'raftable,multimaster'
76+
log_checkpoints = on
77+
log_autovacuum_min_duration = 0
7678
7779
raftable.id =$NODE_ID
7880
raftable.peers = '$RAFT_PEERS'

‎tests2/lib/bank_client.py

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
importtime
55
importsys
66
fromevent_historyimport*
7+
importselect
8+
importsignal
79

810
classClientCollection(object):
911
def__init__(self,connstrs):
@@ -30,17 +32,29 @@ def stop(self):
3032
forclientinself._clients:
3133
client.stop()
3234

35+
defset_acc_to_tx(self,max_acc):
36+
forclientinself._clients:
37+
client.set_acc_to_tx(max_acc)
38+
3339

3440
classBankClient(object):
3541

36-
def__init__(self,connstr,node_id):
42+
def__init__(self,connstr,node_id,accounts=10000):
3743
self.connstr=connstr
3844
self.node_id=node_id
3945
self.run=Value('b',True)
4046
self._history=EventHistory()
41-
self.accounts=10000
47+
self.accounts=accounts
48+
self.accounts_to_tx=accounts
4249
self.show_errors=True
4350

51+
#x = self
52+
#def on_sigint(sig, frame):
53+
# x.stop()
54+
#
55+
#signal.signal(signal.SIGINT, on_sigint)
56+
57+
4458
definitialize(self):
4559
conn=psycopg2.connect(self.connstr)
4660
cur=conn.cursor()
@@ -57,6 +71,22 @@ def initialize(self):
5771
cur.close()
5872
conn.close()
5973

74+
defaconn(self):
75+
returnpsycopg2.connect(self.connstr,async=1)
76+
77+
@classmethod
78+
defwait(cls,conn):
79+
while1:
80+
state=conn.poll()
81+
ifstate==psycopg2.extensions.POLL_OK:
82+
break
83+
elifstate==psycopg2.extensions.POLL_WRITE:
84+
select.select([], [conn.fileno()], [])
85+
elifstate==psycopg2.extensions.POLL_READ:
86+
select.select([conn.fileno()], [], [])
87+
else:
88+
raisepsycopg2.OperationalError("poll() returned %s"%state)
89+
6090
@property
6191
defhistory(self):
6292
returnself._history
@@ -74,25 +104,16 @@ def exec_tx(self, name, tx_block):
74104

75105
ifconn.closed:
76106
self.history.register_finish(event_id,'ReConnect')
77-
try :
78-
conn=psycopg2.connect(self.connstr)
79-
cur=conn.cursor()
80-
except :
81-
continue
82-
else :
83-
continue
107+
conn=psycopg2.connect(self.connstr)
108+
cur=conn.cursor()
84109

85110
try:
86-
tx_block(conn,cur)
111+
tx_block(conn,cur)
112+
self.history.register_finish(event_id,'Commit')
87113
exceptpsycopg2.InterfaceError:
88114
self.history.register_finish(event_id,'InterfaceError')
89115
exceptpsycopg2.Error:
90116
self.history.register_finish(event_id,'PsycopgError')
91-
except :
92-
print(sys.exc_info())
93-
self.history.register_finish(event_id,'OtherError')
94-
else :
95-
self.history.register_finish(event_id,'Commit')
96117

97118
cur.close()
98119
conn.close()
@@ -104,17 +125,20 @@ def tx(conn, cur):
104125
res=cur.fetchone()
105126
conn.commit()
106127
ifres[0]!=0:
107-
print("Isolation error, total = %d"% (res[0],))
128+
print("Isolation error, total = %d, node = %d"% (res[0],self.node_id))
108129
raiseBaseException
109130

110131
self.exec_tx('total',tx)
111132

133+
defset_acc_to_tx(self,max_acc):
134+
self.accounts_to_tx=max_acc
135+
112136
deftransfer_money(self):
113137

114138
deftx(conn,cur):
115139
amount=1
116-
from_uid=random.randrange(1,self.accounts-10)
117-
to_uid=from_uid+1#random.randrange(1, self.accounts + 1)
140+
from_uid=random.randrange(1,self.accounts_to_tx-1)
141+
to_uid=random.randrange(1,self.accounts_to_tx-1)
118142

119143
conn.commit()
120144
cur.execute('''update bank_test
@@ -130,7 +154,10 @@ def tx(conn, cur):
130154
self.exec_tx('transfer',tx)
131155

132156
defstart(self):
133-
self.transfer_process=Process(target=self.transfer_money,args=())
157+
print('Starting client');
158+
self.run.value=True
159+
160+
self.transfer_process=Process(target=self.transfer_money,name="txor",args=())
134161
self.transfer_process.start()
135162

136163
self.total_process=Process(target=self.check_total,args=())
@@ -139,7 +166,7 @@ def start(self):
139166
return
140167

141168
defstop(self):
142-
print('Stopping!');
169+
print('Stopping client');
143170
self.run.value=False
144171
self.total_process.terminate()
145172
self.transfer_process.terminate()

‎tests2/test_recovery.py

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,80 @@
44
fromlib.bank_clientimport*
55

66
classRecoveryTest(unittest.TestCase):
7-
defsetUp(self):
7+
@classmethod
8+
defsetUpClass(self):
89
#subprocess.check_call(['blockade','up'])
910
self.clients=ClientCollection([
1011
"dbname=postgres host=127.0.0.1 user=postgres",
1112
"dbname=postgres host=127.0.0.1 user=postgres port=5433",
1213
"dbname=postgres host=127.0.0.1 user=postgres port=5434"
1314
])
14-
self.clients.start()
1515

16-
deftearDown(self):
16+
@classmethod
17+
deftearDownClass(self):
1718
print('tearDown')
19+
#subprocess.check_call(['blockade','join'])
20+
21+
# in case of error
1822
self.clients.stop()
19-
self.clients[0].cleanup()
20-
subprocess.check_call(['blockade','join'])
23+
#self.clients[0].cleanup()
2124

22-
# def test_0_normal_operation(self):
23-
# print('### normalOpsTest ###')
24-
# print('Waiting 5s to check operability')
25-
# time.sleep(5)
26-
#
27-
# for client in self.clients:
28-
# agg = client.history.aggregate()
29-
# print(agg)
30-
# self.assertTrue(agg['transfer']['finish']['Commit'] > 0)
31-
32-
deftest_1_node_disconnect(self):
33-
print('### disconnectTest ###')
3425

35-
subprocess.check_call(['blockade','partition','node3'])
36-
print('Node3 disconnected')
26+
deftest_0_normal_operation(self):
27+
print('### normalOpsTest ###')
3728

38-
print('Waiting 15s to discover failure')
29+
self.clients.set_acc_to_tx(10000)
30+
self.clients.start()
3931

4032
foriinrange(5):
4133
time.sleep(3)
4234
forclientinself.clients:
4335
agg=client.history.aggregate()
4436
print(agg)
45-
print(" ")
37+
self.assertTrue(agg['transfer']['finish']['Commit']>0)
38+
print("\n")
39+
40+
self.clients.stop()
41+
42+
deftest_1_distributed_deadlock(self):
43+
print('### DDD test ###')
4644

47-
# subprocess.check_call(['blockade','join'])
45+
self.clients.set_acc_to_tx(10)
46+
self.clients.start()
4847

49-
print('Waiting 15s to join node')
50-
foriinrange(1000):
48+
foriinrange(5):
5149
time.sleep(3)
5250
forclientinself.clients:
5351
agg=client.history.aggregate()
5452
print(agg)
55-
print(" ")
53+
self.assertTrue(agg['transfer']['finish']['Commit']>0)
54+
print("\n")
5655

56+
self.clients.stop()
5757

58-
if__name__=='__main__':
59-
unittest.main()
58+
deftest_2_node_disconnect(self):
59+
print('### disconnectTest ###')
6060

61+
self.clients.set_acc_to_tx(10000)
62+
self.clients.start()
63+
64+
subprocess.check_call(['blockade','partition','node3'])
65+
print('Node3 disconnected')
66+
67+
# give cluster some time to discover problem
68+
time.sleep(3)
69+
70+
foriinrange(5):
71+
time.sleep(3)
72+
forclientinself.clients:
73+
agg=client.history.aggregate()
74+
print(agg)
75+
self.assertTrue(agg['transfer']['finish']['Commit']>0)
76+
print("\n")
77+
78+
subprocess.check_call(['blockade','join'])
79+
self.clients.stop()
6180

81+
if__name__=='__main__':
82+
unittest.main()
6283

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp