Skip to content

Commit 202b77a

Browse files
committed
test timeout feature
1 parent 027e688 commit 202b77a

File tree

10 files changed

+85
-8
lines changed

10 files changed

+85
-8
lines changed

.coveragerc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[run]
2+
branch = True
3+
source = cwltest
4+
omit = cwltest/tests/*
5+
6+
[report]
7+
exclude_lines =
8+
if self.debug:
9+
pragma: no cover
10+
raise NotImplementedError
11+
if __name__ == .__main__.:
12+
ignore_errors = True
13+
omit =
14+
cwltest/tests/*

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ diff_pylint_report: pylint_report.txt
112112
diff-quality --violations=pylint pylint_report.txt
113113

114114
.coverage: $(PYSOURCES) all
115-
python setup.py test --addopts "--cov --cov-config=.coveragerc --cov-report= -n auto ${PYTEST_EXTRA}"
115+
python setup.py test --addopts "--cov --cov-config=.coveragerc --cov-report= ${PYTEST_EXTRA}"
116116

117117
coverage.xml: .coverage
118118
coverage xml

cwltest/tests/mock_cwl_runner.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import argparse
2+
import sys
3+
from time import sleep
24

35
from cwltest import UNSUPPORTED_FEATURE
46

57
UNSUPPORTED_FEATURE_TOOL = "return-unsupported.cwl"
68
ERROR_TOOL = "return-1.cwl"
9+
TIMEOUT_TOOL = "timeout.cwl"
710

811

9-
def main(): # type: ()->int
12+
def main() -> int:
1013
parser = argparse.ArgumentParser()
1114
parser.add_argument("processfile")
1215
parser.add_argument("jobfile")
@@ -20,6 +23,11 @@ def main(): # type: ()->int
2023
exit(UNSUPPORTED_FEATURE)
2124
elif args.processfile.endswith(ERROR_TOOL):
2225
exit(1)
26+
elif args.processfile.endswith(TIMEOUT_TOOL):
27+
print("timeout stderr", file=sys.stderr)
28+
sys.stderr.flush()
29+
sleep(100000)
30+
exit(1)
2331

2432
exit(0)
2533

cwltest/tests/test-data/timeout.cwl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.0
3+
inputs: []
4+
outputs: []
5+
baseCommand: [sleep, "15"]

cwltest/tests/test-data/timeout.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- job: v1.0/empty.json
2+
output:
3+
output_txt:
4+
class: File
5+
checksum: sha1$47a013e660d408619d894b20806b1d5086aab03b
6+
location: output.txt
7+
size: 13
8+
tool: timeout.cwl
9+
doc: Test of timeout stdout and stderr capture
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cwltest/tests/test_timeout.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import re
2+
import os
3+
from os import linesep as n
4+
from os import sep as p
5+
from pathlib import Path
6+
7+
import defusedxml.ElementTree as ET
8+
9+
from .util import run_with_mock_cwl_runner, get_data
10+
import schema_salad.ref_resolver
11+
12+
13+
def test_timeout_stderr_stdout(tmp_path):
14+
junit_xml_report = tmp_path / "junit-report.xml"
15+
16+
args = [
17+
"--test",
18+
schema_salad.ref_resolver.file_uri(get_data("tests/test-data/timeout.yml")),
19+
"--timeout",
20+
"5",
21+
"--junit-xml",
22+
str(junit_xml_report),
23+
]
24+
try:
25+
cwd = os.getcwd()
26+
os.chdir(get_data("tests/test-data/"))
27+
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
28+
finally:
29+
os.chdir(cwd)
30+
31+
assert error_code == 1
32+
assert "Test 1 timed out" in stderr
33+
tree = ET.parse(junit_xml_report)
34+
try:
35+
root = tree.getroot()
36+
timeout_text = root.find("testsuite").find("testcase").find("failure").text
37+
timeout_stderr = root.find("testsuite").find("testcase").find("system-err").text
38+
assert "Test timed out" in timeout_text
39+
assert "timeout stderr" in timeout_stderr
40+
except AttributeError as e:
41+
print(junit_xml_report.read_text())
42+
raise e

cwltest/tests/util.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import sys
32

43
import subprocess # nosec
54

@@ -11,9 +10,9 @@
1110

1211

1312
def get_data(filename):
14-
filename = os.path.normpath(
15-
filename
16-
) # normalizing path depending on OS or else it will cause problem when joining path
13+
filename = os.path.normpath(filename)
14+
# normalizing path depending on OS or else it will cause problem when
15+
# joining path
1716
filepath = None
1817
try:
1918
filepath = resource_filename(Requirement.parse("cwltest"), filename)

test-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
pytest >= 6.2, < 6.3
22
pytest-cov
3-
pytest-xdist

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ skipsdist = True
1212
skip_missing_interpreters = True
1313

1414
[pytest]
15-
addopts=-n auto --pyargs cwltest
15+
addopts = --pyargs cwltest
1616
testpaths = cwltest/tests
1717

1818
[gh-actions]

0 commit comments

Comments
 (0)