@@ -20,7 +20,7 @@ def __init__(self, name):
20
20
def clear_values (self ):
21
21
self .max_latency = 0.0
22
22
self .finish = {}
23
-
23
+
24
24
def start_tx (self ):
25
25
self .start_time = datetime .datetime .now ()
26
26
@@ -34,7 +34,7 @@ def finish_tx(self, name):
34
34
self .finish [name ] = 1
35
35
else :
36
36
self .finish [name ] += 1
37
-
37
+
38
38
def as_dict (self ):
39
39
return {
40
40
'running_latency' : (datetime .datetime .now () - self .start_time ).total_seconds (),
@@ -43,13 +43,24 @@ def as_dict(self):
43
43
'finish' : copy .deepcopy (self .finish )
44
44
}
45
45
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
+
46
57
class MtmClient (object ):
47
58
48
59
def __init__ (self , dsns , n_accounts = 100000 ):
49
60
self .n_accounts = n_accounts
50
61
self .dsns = dsns
51
62
self .aggregates = {}
52
- self .initdb ( )
63
+ keep_trying ( 40 , 1 , self .initdb , 'self.initdb' )
53
64
self .running = True
54
65
self .nodes_state_fields = ["id" , "disabled" , "disconnected" , "catchUp" , "slotLag" ,
55
66
"avgTransDelay" , "lastStatusChange" , "oldestSnapshot" , "SenderPid" ,
@@ -173,7 +184,7 @@ def run(self):
173
184
asyncio .async (self .status ())
174
185
175
186
self .loop .run_forever ()
176
-
187
+
177
188
def bgrun (self ):
178
189
print ('Starting evloop in different process' );
179
190
self .parent_pipe , self .child_pipe = aioprocessing .AioPipe ()
@@ -187,7 +198,7 @@ def get_status(self):
187
198
resp = self .parent_pipe .recv ()
188
199
print ('test: got status response' )
189
200
return resp
190
-
201
+
191
202
def stop (self ):
192
203
self .running = False
193
204
self .evloop_process .terminate ()
0 commit comments