1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
import os
import pytest
import parsl
from parsl import bash_app
from parsl.tests.configs.local_threads import fresh_config
def half_handler(*args):
"""Cost 0.5 for each retry, not the default of 1"""
return 0.5
def local_config():
c = fresh_config()
c.retries = 2
c.retry_handler = half_handler
return c
@bash_app
def succeed_on_retry(filename, success_on=1, stdout="succeed.out"):
"""If the input file does not exist it creates it.
Then, if the file contains success_on lines it exits with 0
"""
return """if [[ ! -e {filename} ]]; then touch {filename}; fi;
tries=`wc -l {filename} | cut -f1 -d' '`
echo $tries >> {filename}
if [[ "$tries" -eq "{success_on}" ]]
then
echo "Match. Success"
else
echo "Tries != success_on , exiting with error"
exit 5
fi
""".format(filename=filename, success_on=success_on)
@pytest.mark.local
def test_retry():
"""Test retries via app that succeeds on the Nth retry.
"""
fname = "retry.out"
try:
os.remove(fname)
except OSError:
pass
fu = succeed_on_retry(fname, success_on=4)
fu.result()
try:
os.remove(fname)
except OSError:
pass
fu = succeed_on_retry(fname, success_on=5)
with pytest.raises(parsl.app.errors.BashExitFailure):
fu.result()
assert fu.exception().exitcode == 5
|