Increase test timing and thresholds so it works on slower computers as well.
This commit is contained in:
parent
1eba58f599
commit
176ef7b9d9
@ -25,7 +25,7 @@ class TestBasic(object):
|
||||
'''
|
||||
|
||||
def test_funcTimeout(self):
|
||||
sleepFunction = getSleepLambda(1.25)
|
||||
sleepFunction = getSleepLambda(2.00)
|
||||
|
||||
expectedResult = 5 + 13
|
||||
|
||||
@ -36,9 +36,9 @@ class TestBasic(object):
|
||||
assert result == expectedResult , 'Did not get return from sleepFunction'
|
||||
|
||||
try:
|
||||
result = func_timeout(1.5, sleepFunction, args=(5, 13))
|
||||
result = func_timeout(2.5, sleepFunction, args=(5, 13))
|
||||
except FunctionTimedOut as te:
|
||||
raise AssertionError('Got unexpected timeout at 1.5 second timeout for 1.25 second function: %s' %(str(te),))
|
||||
raise AssertionError('Got unexpected timeout at 2.5 second timeout for 2.00 second function: %s' %(str(te),))
|
||||
|
||||
assert result == expectedResult , 'Got wrong return from func_timeout.\nGot: %s\nExpected: %s\n' %(repr(result), repr(expectedResult))
|
||||
|
||||
@ -51,16 +51,16 @@ class TestBasic(object):
|
||||
assert gotException , 'Expected to get FunctionTimedOut exception for 1.25 sec function at 1s timeout'
|
||||
|
||||
try:
|
||||
result = func_timeout(1.5, sleepFunction, args=(5,), kwargs={ 'b' : 13})
|
||||
result = func_timeout(2.5, sleepFunction, args=(5,), kwargs={ 'b' : 13})
|
||||
except FunctionTimedOut as te:
|
||||
raise AssertionError('Got unexpected timeout at 1.5 second timeout for 1.25 second function: %s' %(str(te), ))
|
||||
raise AssertionError('Got unexpected timeout at 2.5 second timeout for 2.00 second function: %s' %(str(te), ))
|
||||
except Exception as e:
|
||||
raise AssertionError('Got unknown exception mixing args and kwargs: < %s > %s' %(e.__class__.__name__, str(e)))
|
||||
|
||||
assert result == expectedResult , 'Got wrong result when mixing args and kwargs'
|
||||
|
||||
def test_retry(self):
|
||||
sleepFunction = getSleepLambda(.5)
|
||||
sleepFunction = getSleepLambda(1.2)
|
||||
|
||||
expectedResult = 5 + 19
|
||||
|
||||
@ -69,14 +69,14 @@ class TestBasic(object):
|
||||
|
||||
startTime = time.time()
|
||||
try:
|
||||
result = func_timeout(.3, sleepFunction, args=(5, 19))
|
||||
result = func_timeout(.8, sleepFunction, args=(5, 19))
|
||||
except FunctionTimedOut as fte:
|
||||
functionTimedOut = fte
|
||||
gotException = True
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception'
|
||||
assert compareTimes(endTime, startTime, .3, 3, None, .10) == 0 , 'Expected to wait .3 seconds. Was: %f - %f = %f' %(endTime, startTime, round(endTime - startTime, 3))
|
||||
assert compareTimes(endTime, startTime, .8, 3, deltaFixed=.15) == 0 , 'Expected to wait .8 seconds. Was: %f - %f = %f' %(endTime, startTime, round(endTime - startTime, 3))
|
||||
|
||||
gotException = False
|
||||
startTime = time.time()
|
||||
@ -87,7 +87,7 @@ class TestBasic(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception on retry.'
|
||||
assert compareTimes(endTime, startTime, .3, 3, None, .10) == 0 , 'Expected retry with no arguments to use same timeout of .3'
|
||||
assert compareTimes(endTime, startTime, .8, 3, deltaFixed=.15) == 0 , 'Expected retry with no arguments to use same timeout of .8'
|
||||
|
||||
gotException = False
|
||||
startTime = time.time()
|
||||
@ -98,19 +98,19 @@ class TestBasic(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Did NOT to get exception with no timeout'
|
||||
assert compareTimes(endTime, startTime, .5, 3, None, .10) == 0 , 'Expected retry with None as timeout to last full length of function'
|
||||
assert compareTimes(endTime, startTime, 1.2, 3, deltaFixed=.15) == 0 , 'Expected retry with None as timeout to last full length of function'
|
||||
|
||||
gotException = False
|
||||
startTime = time.time()
|
||||
try:
|
||||
result = functionTimedOut.retry(.4)
|
||||
result = functionTimedOut.retry(.55)
|
||||
except FunctionTimedOut:
|
||||
gotException = True
|
||||
finally:
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to time out after .4 seconds when providing .4'
|
||||
assert compareTimes(endTime, startTime, .4, 3, .05, None) == 0 , 'Expected providing .4 would allow timeout of up to .4 seconds'
|
||||
assert gotException , 'Expected to time out after .55 seconds when providing .55'
|
||||
assert compareTimes(endTime, startTime, .55, 3, deltaFixed=.15) == 0 , 'Expected providing .55 would allow timeout of up to .55 seconds'
|
||||
|
||||
threadsCleanedUp = False
|
||||
|
||||
@ -126,7 +126,7 @@ class TestBasic(object):
|
||||
assert threadsCleanedUp , 'Expected other threads to get cleaned up after gc collection'
|
||||
|
||||
def test_exception(self):
|
||||
sleepFunction = getSleepLambda(.5)
|
||||
sleepFunction = getSleepLambda(.85)
|
||||
|
||||
expectedResult = 5 + 19
|
||||
|
||||
@ -135,7 +135,7 @@ class TestBasic(object):
|
||||
|
||||
startTime = time.time()
|
||||
try:
|
||||
result = func_timeout(.3, sleepFunction, args=(5, 19))
|
||||
result = func_timeout(.5, sleepFunction, args=(5, 19))
|
||||
except FunctionTimedOut as fte:
|
||||
functionTimedOut = fte
|
||||
gotException = True
|
||||
@ -144,7 +144,7 @@ class TestBasic(object):
|
||||
assert gotException , 'Expected to get exception'
|
||||
|
||||
assert 'timed out after ' in functionTimedOut.msg , 'Expected message to be constructed. Got: %s' %(repr(functionTimedOut.msg), )
|
||||
assert round(functionTimedOut.timedOutAfter, 1) == .3 , 'Expected timedOutAfter to equal timeout ( .3 ). Got: %s' %(str(round(functionTimedOut.timedOutAfter, 1)), )
|
||||
assert round(functionTimedOut.timedOutAfter, 1) == .5 , 'Expected timedOutAfter to equal timeout ( .5 ). Got: %s' %(str(round(functionTimedOut.timedOutAfter, 1)), )
|
||||
assert functionTimedOut.timedOutFunction == sleepFunction , 'Expected timedOutFunction to equal sleepFunction'
|
||||
assert functionTimedOut.timedOutArgs == (5, 19) , 'Expected args to equal (5, 19)'
|
||||
assert functionTimedOut.timedOutKwargs == {} , 'Expected timedOutKwargs to equal {}'
|
||||
|
||||
@ -19,7 +19,7 @@ from func_timeout import func_timeout, FunctionTimedOut, func_set_timeout
|
||||
|
||||
from TestUtils import ARG_NO_DEFAULT, getSleepLambda, getSleepLambdaWithArgs, compareTimes
|
||||
|
||||
SLEEP_TIME = .5
|
||||
SLEEP_TIME = 1.25
|
||||
|
||||
def doSleep(a, b):
|
||||
time.sleep(a)
|
||||
@ -52,7 +52,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception at sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, .1) == 0 , 'Expected to sleep up to sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, deltaFixed=.15) == 0 , 'Expected to sleep up to sleep time'
|
||||
|
||||
expected = SLEEP_TIME * .8 + 4
|
||||
gotException = False
|
||||
@ -64,7 +64,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected not to get exception at 80% sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, .1) == 0 , 'Expected to only sleep for 80% of sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, deltaFixed=.15) == 0 , 'Expected to only sleep for 80% of sleep time'
|
||||
assert result == expected , 'Got wrong result'
|
||||
|
||||
def test_funcSetTimeoutOverride(self):
|
||||
@ -85,7 +85,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception at 130% sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * 1.2, None, .1) == 0 , 'Expected to sleep up to 120% of sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * 1.2, None, deltaFixed=.15) == 0 , 'Expected to sleep up to 120% of sleep time'
|
||||
|
||||
@func_set_timeout(SLEEP_TIME, allowOverride=False)
|
||||
def doSleepFuncNoOverride(a, b):
|
||||
@ -113,7 +113,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected not to get exception with forced 115% sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, .1) == 0 , 'Expected to sleep for SLEEP_TIME'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, deltaFixed=.15) == 0 , 'Expected to sleep for SLEEP_TIME'
|
||||
assert result == expected , 'Got wrong result'
|
||||
|
||||
def test_funcSetTimeCalculate(self):
|
||||
@ -145,7 +145,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected not to get exception with calculated 120% timeout on sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, .1) == 0 , 'Expected to sleep for SLEEP_TIME'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, deltaFixed=.15) == 0 , 'Expected to sleep for SLEEP_TIME'
|
||||
assert result == expected , 'Got wrong result'
|
||||
|
||||
|
||||
@ -164,7 +164,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception with calculated 80% timeout on sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, .1) == 0 , 'Expected to sleep for 80% SLEEP_TIME'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, deltaFixed=.15) == 0 , 'Expected to sleep for 80% SLEEP_TIME'
|
||||
|
||||
@func_set_timeout(calculateSleepOverArgs, allowOverride=False)
|
||||
def doSleepFuncOverArgs(a, b):
|
||||
@ -181,7 +181,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected not to get exception with calculated 120% timeout on sleep time using *args'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, .1) == 0 , 'Expected to sleep for SLEEP_TIME using *args'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, deltaFixed=.15) == 0 , 'Expected to sleep for SLEEP_TIME using *args'
|
||||
assert result == expected , 'Got wrong result'
|
||||
|
||||
@func_set_timeout(calculateSleepUnderArgs, allowOverride=False)
|
||||
@ -199,7 +199,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception with calculated 80% timeout on sleep time using *args'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, .1) == 0 , 'Expected to sleep for 80% SLEEP_TIME using *args'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, deltaFixed=.15) == 0 , 'Expected to sleep for 80% SLEEP_TIME using *args'
|
||||
|
||||
|
||||
def test_funcSetTimeCalculateWithOverride(self):
|
||||
@ -231,7 +231,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected not to get exception with calculated 120% timeout on sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, .1) == 0 , 'Expected to sleep for SLEEP_TIME'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, deltaFixed=.15) == 0 , 'Expected to sleep for SLEEP_TIME'
|
||||
assert result == expected , 'Got wrong result'
|
||||
|
||||
expected = SLEEP_TIME + 4
|
||||
@ -244,7 +244,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected not to get exception with calculated 120% timeout on sleep time but 150% timeout on override'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, .1) == 0 , 'Expected to sleep for SLEEP_TIME with 150% timeout on override'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, deltaFixed=.15) == 0 , 'Expected to sleep for SLEEP_TIME with 150% timeout on override'
|
||||
assert result == expected , 'Got wrong result'
|
||||
|
||||
|
||||
@ -258,7 +258,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception with calculated 120% timeout on sleep time but 70% timeout on override'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .7, None, .1) == 0 , 'Expected to sleep for 70% SLEEP_TIME with 70% timeout on override'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .7, None, deltaFixed=.15) == 0 , 'Expected to sleep for 70% SLEEP_TIME with 70% timeout on override'
|
||||
|
||||
|
||||
@func_set_timeout(calculateSleepUnder, allowOverride=True)
|
||||
@ -276,7 +276,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception with calculated 80% timeout on sleep time'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, .1) == 0 , 'Expected to sleep for 80% SLEEP_TIME'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, deltaFixed=.15) == 0 , 'Expected to sleep for 80% SLEEP_TIME'
|
||||
|
||||
expected = SLEEP_TIME + 4
|
||||
gotException = False
|
||||
@ -288,7 +288,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected not to get exception with calculated 80% timeout on sleep time but 120% timeout on override'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME , None, .1) == 0 , 'Expected to sleep for SLEEP_TIME with 120% timeout on override'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME , None, deltaFixed=.15) == 0 , 'Expected to sleep for SLEEP_TIME with 120% timeout on override'
|
||||
|
||||
|
||||
def test_setFuncTimeoutetry(self):
|
||||
@ -322,7 +322,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception with calculated 80% timeout'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, .1) == 0 , 'Expected to sleep for 80% SLEEP_TIME with 80% timeout'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, deltaFixed=.15) == 0 , 'Expected to sleep for 80% SLEEP_TIME with 80% timeout'
|
||||
|
||||
gotException = False
|
||||
startTime = time.time()
|
||||
@ -335,7 +335,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception with calculated same 80% timeout on retry'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, .1) == 0 , 'Expected to sleep for 80% SLEEP_TIME with same 80% timeout on retry'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .8, None, deltaFixed=.15) == 0 , 'Expected to sleep for 80% SLEEP_TIME with same 80% timeout on retry'
|
||||
|
||||
result = None
|
||||
gotException = False
|
||||
@ -349,7 +349,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected to get exception with calculated 80% timeout on retry ( None ) [ No timeout ]'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, .1) == 0 , 'Expected to sleep for 100% SLEEP_TIME with 80% timeout overriden on retry ( None ) [ No timeout ]'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME, None, deltaFixed=.15) == 0 , 'Expected to sleep for 100% SLEEP_TIME with 80% timeout overriden on retry ( None ) [ No timeout ]'
|
||||
assert result == expected , 'Got wrong result'
|
||||
|
||||
|
||||
@ -365,7 +365,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert gotException , 'Expected to get exception with calculated 80% timeout overriden by 60% timeout on retry'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .6, None, .1) == 0 , 'Expected to sleep for 60% SLEEP_TIME with 80% timeout overriden on retry ( SLEEP_TIME * .6 ) [ 60% timeout ]'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME * .6, None, deltaFixed=.15) == 0 , 'Expected to sleep for 60% SLEEP_TIME with 80% timeout overriden on retry ( SLEEP_TIME * .6 ) [ 60% timeout ]'
|
||||
|
||||
result = None
|
||||
gotException = False
|
||||
@ -379,7 +379,7 @@ class TestDecorator(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert not gotException , 'Expected to get exception with calculated 80% timeout overriden by 150% timeout on retry'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME , None, .1) == 0 , 'Expected to sleep for 100% SLEEP_TIME with 80% timeout overriden on retry ( SLEEP_TIME * 1.5 ) [ 150% timeout ]'
|
||||
assert compareTimes(endTime, startTime, SLEEP_TIME , None, deltaFixed=.15) == 0 , 'Expected to sleep for 100% SLEEP_TIME with 80% timeout overriden on retry ( SLEEP_TIME * 1.5 ) [ 150% timeout ]'
|
||||
assert result == expected
|
||||
|
||||
threadsCleanedUp = False
|
||||
|
||||
@ -35,7 +35,7 @@ class TestBasicSleepWithArgs(object):
|
||||
raise AssertionError('Expected to have 1 default arg and 2 standard. Tried 3 args')
|
||||
endTime = time.time()
|
||||
|
||||
assert compareTimes(endTime, startTime, 2, 2, deltaFixed=.1, deltaPct=None) == 0 , 'Expected getSleepLambdaWithArgs(2) to take 2 seconds.'
|
||||
assert compareTimes(endTime, startTime, 2, 2, deltaFixed=.15, deltaPct=None) == 0 , 'Expected getSleepLambdaWithArgs(2) to take 2 seconds.'
|
||||
|
||||
try:
|
||||
sleepLambda(4, 7, 12)
|
||||
@ -54,7 +54,7 @@ class TestBasicSleepWithArgs(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert result == expectedResult , 'Got wrong result'
|
||||
assert compareTimes(endTime, startTime, 1.75, 2, deltaFixed=.1, deltaPct=None) == 0 , 'Expected getSleepLambdaWithArgs(1.75) to take 1.75 seconds.'
|
||||
assert compareTimes(endTime, startTime, 1.75, 2, deltaFixed=.15, deltaPct=None) == 0 , 'Expected getSleepLambdaWithArgs(1.75) to take 1.75 seconds.'
|
||||
|
||||
expectedResult = 5 + 13
|
||||
|
||||
@ -63,7 +63,7 @@ class TestBasicSleepWithArgs(object):
|
||||
endTime = time.time()
|
||||
|
||||
assert result == expectedResult , 'Did not get return from sleepFunction'
|
||||
assert compareTimes(endTime, startTime, 1.75, 2, deltaFixed=.1, deltaPct=None) == 0 , 'Expected getSleepLambda(1.75) to take 1.75 seconds.'
|
||||
assert compareTimes(endTime, startTime, 1.75, 2, deltaFixed=.15, deltaPct=None) == 0 , 'Expected getSleepLambda(1.75) to take 1.75 seconds.'
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(subprocess.Popen('GoodTests.py -n1 "%s" %s' %(sys.argv[0], ' '.join(['"%s"' %(arg.replace('"', '\\"'), ) for arg in sys.argv[1:]]) ), shell=True).wait())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user