Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_retry(self):
return_values = [FAIL_REASON.QUEUE_FULL, FAIL_REASON.SUCCESS, FAIL_REASON.REQUEST_DENIED]
def test(callback):
callback(True, return_values.pop(0))
self.assertTrue(self.so.retry(test))
self.assertFalse(self.so.retry(test))
def clbck(res, err):
global _g_error, _g_success
if err == FAIL_REASON.SUCCESS:
_g_success += 1
else:
_g_error += 1
_g_errors[err] += 1
def clbck(res, err):
global _g_error, _g_success, _g_delays
if err == FAIL_REASON.SUCCESS:
_g_success += 1
callTime, recvTime = res
delay = time.time() - callTime
_g_delays.append(delay)
else:
_g_error += 1
_g_errors[err] += 1
doTicks(objs + roObjs, 5.0, stopFunc=lambda: o1.getCounter() == 450 and \
b1.getCounter() == 450 and \
b2.getCounter() == 450 and
currRes.get(0) == FAIL_REASON.SUCCESS)
assert o1.getCounter() == 450
def onAddValue(res, err, info):
assert res == 3
assert err == FAIL_REASON.SUCCESS
info['callback'] = True
event = threading.Event()
ret = {'result': None, 'error': -1}
def callback(result, error):
ret.update(result=result, error=error)
event.set()
kwargs['callback'] = callback
timeout = kwargs.pop('timeout', None) or self.__retry_timeout
deadline = timeout and time.time() + timeout
while True:
event.clear()
func(*args, **kwargs)
event.wait(timeout)
if ret['error'] == FAIL_REASON.SUCCESS:
return ret['result']
elif ret['error'] == FAIL_REASON.REQUEST_DENIED:
break
elif deadline:
timeout = deadline - time.time()
if timeout <= 0:
break
time.sleep(1)
return False
def onAddValue(res, err, info):
assert res == 3
assert err == FAIL_REASON.SUCCESS
info['callback'] = True
def _SyncObj__utilityCallback(self, res, err, conn, cmd, node):
cmdResult = 'FAIL'
if err == FAIL_REASON.SUCCESS:
cmdResult = 'SUCCESS'
conn.send(cmdResult + ' ' + cmd + ' ' + node)
def _SyncObj__utilityCallback(self, res, err, conn, cmd, node):
cmdResult = 'FAIL'
if err == FAIL_REASON.SUCCESS:
cmdResult = 'SUCCESS'
conn.send(cmdResult + ' ' + cmd + ' ' + node)