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

Commit f0ed19f

Browse files
committed
check data identity in tests
1 parent c94bbba commit f0ed19f

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

tests2/lib/bank_client.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ def initdb(self):
109109
cur.close()
110110
conn.close()
111111

112+
def is_data_identic(self):
113+
hashes = set()
114+
115+
for dsn in self.dsns:
116+
con = psycopg2.connect(dsn)
117+
cur = con.cursor()
118+
cur.execute("""
119+
select
120+
md5('(' || string_agg(uid::text || ', ' || amount::text , '),(') || ')')
121+
from
122+
(select * from bank_test order by uid) t;""")
123+
hashes.add(cur.fetchone()[0])
124+
cur.close()
125+
con.close()
126+
127+
print(hashes)
128+
return (len(hashes) == 1)
129+
112130
@asyncio.coroutine
113131
def status(self):
114132
while self.running:
@@ -168,7 +186,7 @@ def exec_tx(self, tx_block, aggname_prefix, conn_i):
168186
yield from asyncio.sleep(0.01)
169187
except BaseException as e:
170188
agg.finish_tx(str(e).strip())
171-
print('Catch exception ', e)
189+
print('Catch exception ', str(e).strip())
172190
# Give evloop some free time.
173191
# In case of continuous excetions we can loop here without returning
174192
# back to event loop and block it

tests2/test_recovery.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def performFailure(self, failure):
6868
class RecoveryTest(unittest.TestCase, TestHelper):
6969

7070
@classmethod
71-
def setUpClass(self):
71+
def setUpClass(cls):
7272
subprocess.check_call(['docker-compose','up',
7373
'--force-recreate',
7474
'--build',
@@ -77,17 +77,21 @@ def setUpClass(self):
7777
# XXX: add normal wait here
7878
time.sleep(TEST_SETUP_TIME)
7979

80-
self.client = MtmClient([
80+
cls.client = MtmClient([
8181
"dbname=regression user=postgres host=127.0.0.1 port=15432",
8282
"dbname=regression user=postgres host=127.0.0.1 port=15433",
8383
"dbname=regression user=postgres host=127.0.0.1 port=15434"
8484
], n_accounts=1000)
85-
self.client.bgrun()
85+
cls.client.bgrun()
8686

8787
@classmethod
88-
def tearDownClass(self):
88+
def tearDownClass(cls):
8989
print('tearDown')
90-
self.client.stop()
90+
cls.client.stop()
91+
92+
if not cls.client.is_data_identic():
93+
raise AssertionError('Different data on nodes')
94+
9195
# XXX: check nodes data identity here
9296
# subprocess.check_call(['docker-compose','down'])
9397

0 commit comments

Comments
 (0)