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

Commit c05a76f

Browse files
committed
merge
2 parents 3ab1532 + baa49c5 commit c05a76f

File tree

3 files changed

+103
-45
lines changed

3 files changed

+103
-45
lines changed

contrib/mmts/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'

contrib/mmts/tests2/lib/bank_client.py

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import time
66
import sys
77
from event_history import *
8+
import select
9+
import signal
810

911
class ClientCollection(object):
1012
def __init__(self, connstrs):
@@ -59,17 +61,29 @@ def print_agg(self):
5961

6062
print("")
6163

64+
def set_acc_to_tx(self, max_acc):
65+
for client in self._clients:
66+
client.set_acc_to_tx(max_acc)
67+
6268

6369
class BankClient(object):
6470

65-
def __init__(self, connstr, node_id):
71+
def __init__(self, connstr, node_id, accounts = 10000):
6672
self.connstr = connstr
6773
self.node_id = node_id
6874
self.run = Value('b', True)
6975
self._history = EventHistory()
70-
self.accounts = 10000
76+
self.accounts = accounts
77+
self.accounts_to_tx = accounts
7178
self.show_errors = True
7279

80+
#x = self
81+
#def on_sigint(sig, frame):
82+
# x.stop()
83+
#
84+
#signal.signal(signal.SIGINT, on_sigint)
85+
86+
7387
def initialize(self):
7488
conn = psycopg2.connect(self.connstr)
7589
cur = conn.cursor()
@@ -86,6 +100,22 @@ def initialize(self):
86100
cur.close()
87101
conn.close()
88102

103+
def aconn(self):
104+
return psycopg2.connect(self.connstr, async=1)
105+
106+
@classmethod
107+
def wait(cls, conn):
108+
while 1:
109+
state = conn.poll()
110+
if state == psycopg2.extensions.POLL_OK:
111+
break
112+
elif state == psycopg2.extensions.POLL_WRITE:
113+
select.select([], [conn.fileno()], [])
114+
elif state == psycopg2.extensions.POLL_READ:
115+
select.select([conn.fileno()], [], [])
116+
else:
117+
raise psycopg2.OperationalError("poll() returned %s" % state)
118+
89119
@property
90120
def history(self):
91121
return self._history
@@ -103,25 +133,16 @@ def exec_tx(self, name, tx_block):
103133

104134
if conn.closed:
105135
self.history.register_finish(event_id, 'ReConnect')
106-
try :
107-
conn = psycopg2.connect(self.connstr)
108-
cur = conn.cursor()
109-
except :
110-
continue
111-
else :
112-
continue
136+
conn = psycopg2.connect(self.connstr)
137+
cur = conn.cursor()
113138

114139
try:
115-
tx_block(conn, cur)
140+
tx_block(conn, cur)
141+
self.history.register_finish(event_id, 'Commit')
116142
except psycopg2.InterfaceError:
117143
self.history.register_finish(event_id, 'InterfaceError')
118144
except psycopg2.Error:
119145
self.history.register_finish(event_id, 'PsycopgError')
120-
except :
121-
print(sys.exc_info())
122-
self.history.register_finish(event_id, 'OtherError')
123-
else :
124-
self.history.register_finish(event_id, 'Commit')
125146

126147
cur.close()
127148
conn.close()
@@ -133,17 +154,20 @@ def tx(conn, cur):
133154
res = cur.fetchone()
134155
conn.commit()
135156
if res[0] != 0:
136-
print("Isolation error, total = %d" % (res[0],))
157+
print("Isolation error, total = %d, node = %d" % (res[0],self.node_id))
137158
raise BaseException
138159

139160
self.exec_tx('total', tx)
140161

162+
def set_acc_to_tx(self, max_acc):
163+
self.accounts_to_tx = max_acc
164+
141165
def transfer_money(self):
142166

143167
def tx(conn, cur):
144168
amount = 1
145-
from_uid = random.randrange(1, self.accounts - 10)
146-
to_uid = from_uid + 1 #random.randrange(1, self.accounts + 1)
169+
from_uid = random.randrange(1, self.accounts_to_tx - 1)
170+
to_uid = random.randrange(1, self.accounts_to_tx - 1)
147171

148172
conn.commit()
149173
cur.execute('''update bank_test
@@ -159,7 +183,10 @@ def tx(conn, cur):
159183
self.exec_tx('transfer', tx)
160184

161185
def start(self):
162-
self.transfer_process = Process(target=self.transfer_money, args=())
186+
print('Starting client');
187+
self.run.value = True
188+
189+
self.transfer_process = Process(target=self.transfer_money, name="txor", args=())
163190
self.transfer_process.start()
164191

165192
self.total_process = Process(target=self.check_total, args=())
@@ -168,7 +195,7 @@ def start(self):
168195
return
169196

170197
def stop(self):
171-
print('Stopping!');
198+
print('Stopping client');
172199
self.run.value = False
173200
self.total_process.terminate()
174201
self.transfer_process.terminate()

contrib/mmts/tests2/test_recovery.py

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,80 @@
44
from lib.bank_client import *
55

66
class RecoveryTest(unittest.TestCase):
7-
def setUp(self):
7+
@classmethod
8+
def setUpClass(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-
def tearDown(self):
16+
@classmethod
17+
def tearDownClass(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()
24+
25+
26+
def test_0_normal_operation(self):
27+
print('### normalOpsTest ###')
28+
29+
self.clients.set_acc_to_tx(10000)
30+
self.clients.start()
31+
32+
for i in range(5):
33+
time.sleep(3)
34+
for client in self.clients:
35+
agg = client.history.aggregate()
36+
print(agg)
37+
self.assertTrue(agg['transfer']['finish']['Commit'] > 0)
38+
print("\n")
39+
40+
self.clients.stop()
41+
42+
def test_1_distributed_deadlock(self):
43+
print('### DDD test ###')
44+
45+
self.clients.set_acc_to_tx(10)
46+
self.clients.start()
2147

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-
def test_1_node_disconnect(self):
48+
for i in range(5):
49+
time.sleep(3)
50+
for client in self.clients:
51+
agg = client.history.aggregate()
52+
print(agg)
53+
self.assertTrue(agg['transfer']['finish']['Commit'] > 0)
54+
print("\n")
55+
56+
self.clients.stop()
57+
58+
def test_2_node_disconnect(self):
3359
print('### disconnectTest ###')
3460

61+
self.clients.set_acc_to_tx(10000)
62+
self.clients.start()
63+
3564
subprocess.check_call(['blockade','partition','node3'])
3665
print('Node3 disconnected')
3766

67+
# give cluster some time to discover problem
68+
time.sleep(3)
69+
3870
for i in range(5):
3971
time.sleep(3)
40-
self.clients.print_agg()
72+
for client in self.clients:
73+
agg = client.history.aggregate()
74+
print(agg)
75+
self.assertTrue(agg['transfer']['finish']['Commit'] > 0)
76+
print("\n")
4177

4278
subprocess.check_call(['blockade','join'])
43-
print("Node3 joined back")
44-
45-
for i in range(50):
46-
time.sleep(3)
47-
self.clients.print_agg()
48-
79+
self.clients.stop()
4980

5081
if __name__ == '__main__':
5182
unittest.main()
5283

53-
54-

0 commit comments

Comments
 (0)