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

Commit 7a50383

Browse files
kvapkelvich
authored andcommitted
Prevent the test from failing at the start if 20 seconds were not enough.
1 parent 5453400 commit 7a50383

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests2/client2.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, name):
2020
def clear_values(self):
2121
self.max_latency = 0.0
2222
self.finish = {}
23-
23+
2424
def start_tx(self):
2525
self.start_time = datetime.datetime.now()
2626

@@ -34,7 +34,7 @@ def finish_tx(self, name):
3434
self.finish[name] = 1
3535
else:
3636
self.finish[name] += 1
37-
37+
3838
def as_dict(self):
3939
return {
4040
'running_latency': (datetime.datetime.now() - self.start_time).total_seconds(),
@@ -43,13 +43,24 @@ def as_dict(self):
4343
'finish': copy.deepcopy(self.finish)
4444
}
4545

46+
def keep_trying(tries, delay, method, name, *args, **kwargs):
47+
for t in range(tries):
48+
try:
49+
return method(*args, **kwargs)
50+
except Exception as e:
51+
if t == tries - 1:
52+
raise Exception("%s failed all %d tries" % (name, tries)) from e
53+
print("%s failed [%d of %d]: %s" % (name, t + 1, tries, str(e)))
54+
time.sleep(delay)
55+
raise Exception("this should not happen")
56+
4657
class MtmClient(object):
4758

4859
def __init__(self, dsns, n_accounts=100000):
4960
self.n_accounts = n_accounts
5061
self.dsns = dsns
5162
self.aggregates = {}
52-
self.initdb()
63+
keep_trying(40, 1, self.initdb, 'self.initdb')
5364
self.running = True
5465
self.nodes_state_fields = ["id", "disabled", "disconnected", "catchUp", "slotLag",
5566
"avgTransDelay", "lastStatusChange", "oldestSnapshot", "SenderPid",
@@ -173,7 +184,7 @@ def run(self):
173184
asyncio.async(self.status())
174185

175186
self.loop.run_forever()
176-
187+
177188
def bgrun(self):
178189
print('Starting evloop in different process');
179190
self.parent_pipe, self.child_pipe = aioprocessing.AioPipe()
@@ -187,7 +198,7 @@ def get_status(self):
187198
resp = self.parent_pipe.recv()
188199
print('test: got status response')
189200
return resp
190-
201+
191202
def stop(self):
192203
self.running = False
193204
self.evloop_process.terminate()

0 commit comments

Comments
 (0)