Skip to content

Commit

Permalink
Better timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dariober committed Apr 10, 2024
1 parent 917b94b commit f1c3321
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions packages/apollo-cli/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class shell:
def __init__(self, cmd, strict=True):
def __init__(self, cmd, strict=True, timeout=None):
print(cmd)
cmd = f"set -e; set -u; set -o pipefail\n{cmd}"
p = subprocess.Popen(
Expand All @@ -30,7 +30,12 @@ def __init__(self, cmd, strict=True):
stderr=subprocess.PIPE,
executable="/bin/bash",
)
stdout, stderr = p.communicate()
try:
stdout, stderr = p.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
p.kill()
sys.stderr.write(f"Error: Timeout after {timeout} seconds\n")
stdout, stderr = p.communicate()
self.returncode = p.returncode
self.stdout = stdout.decode()
self.stderr = stderr.decode()
Expand All @@ -40,13 +45,11 @@ def __init__(self, cmd, strict=True):
f"\nSTDOUT:\n{self.stdout}\nSTDERR:\n{self.stderr}\nEXIT CODE: {self.returncode}"
)

def handler(signum, frame):
raise Exception("end of time")


apollo = "yarn dev"
P = "--profile testAdmin"


def setUpModule():
# See apollo-collaboration-server/.development.env for credentials etc.
shell(f"{apollo} config {P} address http://localhost:3999")
Expand Down Expand Up @@ -256,24 +259,21 @@ def testAddAssemblyLargeInput(self):
fout.write("CATTGTTGCGGAGTTGAACAACGGCATTAGGAACACTTCCGTCTC\n")
i += 1

signal.signal(signal.SIGALRM, handler)
signal.alarm(120) # Allow these many secs to complete

try:
shell(f"{apollo} assembly add-fasta {P} -i test_data/tmp.fa -a test -f")
shell(
f"{apollo} assembly add-gff {P} -i test_data/tmp.fa -a test -f",
strict=False,
)
shell(f"{apollo} assembly add-fasta {P} -i test_data/tmp.fa -a test -f")
done = True
except Exception as exc:
print(exc)
p.kill()
done = False
shell(
f"{apollo} assembly add-fasta {P} -i test_data/tmp.fa -a test -f",
timeout=60,
)
shell(
f"{apollo} assembly add-gff {P} -i test_data/tmp.fa -a test -f",
strict=False,
timeout=60,
)
shell(
f"{apollo} assembly add-fasta {P} -i test_data/tmp.fa -a test -f",
timeout=60,
)

os.remove("test_data/tmp.fa")
self.assertTrue(done)

def testAddAssemblyFromLocalFasta(self):
shell(f"{apollo} assembly add-fasta {P} -i test_data/tiny.fasta -a vv1 -f")
Expand Down

0 comments on commit f1c3321

Please sign in to comment.