Skip to content

Commit 0a9031a

Browse files
PanaetiusRalf Grubenmann
authored andcommitted
tests: improve performance of tests by caching repos
1 parent e02e5bf commit 0a9031a

29 files changed

+360
-262
lines changed

.github/workflows/test_deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ on:
1414
branches:
1515
- "**"
1616
- "!master"
17-
17+
env:
18+
RENKU_TEST_RECREATE_CACHE: "${{ (endsWith(github.ref, 'master') || endsWith(github.ref, 'develop') || startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/release/' ) ) && '1' || '0' }}"
1819
jobs:
1920
set-matrix:
2021
runs-on: ubuntu-latest

tests/cli/fixtures/cli_workflow.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@
1919

2020

2121
@pytest.fixture
22-
def workflow_graph(run_shell, project):
22+
def workflow_graph(run_shell, project, cache_test_project):
2323
"""Setup a project with a workflow graph."""
24+
cache_test_project.set_name("workflow_graph_fixture")
25+
if not cache_test_project.setup():
2426

25-
def _run_workflow(name, command, extra_args=""):
26-
output = run_shell(f"renku run --name {name} {extra_args} -- {command}")
27-
# Assert not allocated stderr.
28-
assert output[1] is None
27+
def _run_workflow(name, command, extra_args=""):
28+
output = run_shell(f"renku run --name {name} {extra_args} -- {command}")
29+
# Assert not allocated stderr.
30+
assert output[1] is None
2931

30-
_run_workflow("r1", "echo 'test' > A")
31-
_run_workflow("r2", "tee B C < A")
32-
_run_workflow("r3", "cp A Z")
33-
_run_workflow("r4", "cp B X")
34-
_run_workflow("r5", "cat C Z > Y")
35-
_run_workflow("r6", "bash -c 'cat X Y | tee R S'", extra_args="--input X --input Y --output R --output S")
36-
_run_workflow("r7", "echo 'other' > H")
37-
_run_workflow("r8", "tee I J < H")
32+
_run_workflow("r1", "echo 'test' > A")
33+
_run_workflow("r2", "tee B C < A")
34+
_run_workflow("r3", "cp A Z")
35+
_run_workflow("r4", "cp B X")
36+
_run_workflow("r5", "cat C Z > Y")
37+
_run_workflow("r6", "bash -c 'cat X Y | tee R S'", extra_args="--input X --input Y --output R --output S")
38+
_run_workflow("r7", "echo 'other' > H")
39+
_run_workflow("r8", "tee I J < H")
40+
cache_test_project.save()

tests/cli/test_graph.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727

2828

2929
@pytest.mark.parametrize("revision", ["", "HEAD", "HEAD^", "HEAD^..HEAD"])
30-
def test_graph_export_validation(runner, project, directory_tree, run, revision):
30+
def test_graph_export_validation(runner, project, directory_tree, run, revision, cache_test_project):
3131
"""Test graph validation when exporting."""
32-
assert 0 == runner.invoke(cli, ["dataset", "add", "--copy", "-c", "my-data", str(directory_tree)]).exit_code
32+
if not cache_test_project.setup():
33+
assert 0 == runner.invoke(cli, ["dataset", "add", "--copy", "-c", "my-data", str(directory_tree)]).exit_code
3334

34-
file1 = project.path / DATA_DIR / "my-data" / directory_tree.name / "file1"
35-
file2 = project.path / DATA_DIR / "my-data" / directory_tree.name / "dir1" / "file2"
36-
assert 0 == run(["run", "head", str(file1)], stdout="out1")
37-
assert 0 == run(["run", "tail", str(file2)], stdout="out2")
35+
file1 = project.path / DATA_DIR / "my-data" / directory_tree.name / "file1"
36+
file2 = project.path / DATA_DIR / "my-data" / directory_tree.name / "dir1" / "file2"
37+
assert 0 == run(["run", "head", str(file1)], stdout="out1")
38+
assert 0 == run(["run", "tail", str(file2)], stdout="out2")
39+
cache_test_project.save()
3840

3941
result = runner.invoke(cli, ["graph", "export", "--format", "json-ld", "--strict", "--revision", revision])
4042

@@ -57,12 +59,14 @@ def test_graph_export_validation(runner, project, directory_tree, run, revision)
5759

5860
@pytest.mark.serial
5961
@pytest.mark.shelled
60-
def test_graph_export_strict_run(runner, project, run_shell):
62+
def test_graph_export_strict_run(runner, project, run_shell, cache_test_project):
6163
"""Test graph export output of run command."""
62-
# Run a shell command with pipe.
63-
assert run_shell('renku run --name run1 echo "my input string" > my_output_file')[1] is None
64-
assert run_shell("renku run --name run2 cp my_output_file my_output_file2")[1] is None
65-
assert run_shell("renku workflow compose my-composite-plan run1 run2")[1] is None
64+
if not cache_test_project.setup():
65+
# Run a shell command with pipe.
66+
assert run_shell('renku run --name run1 echo "my input string" > my_output_file')[1] is None
67+
assert run_shell("renku run --name run2 cp my_output_file my_output_file2")[1] is None
68+
assert run_shell("renku workflow compose my-composite-plan run1 run2")[1] is None
69+
cache_test_project.save()
6670

6771
# Assert created output file.
6872
result = runner.invoke(cli, ["graph", "export", "--full", "--strict", "--format=json-ld"])
@@ -80,21 +84,23 @@ def test_graph_export_strict_run(runner, project, run_shell):
8084
assert 0 == result.exit_code, format_result_exception(result)
8185

8286

83-
def test_graph_export_strict_dataset(tmpdir, runner, project, subdirectory):
87+
def test_graph_export_strict_dataset(tmpdir, runner, project, subdirectory, cache_test_project):
8488
"""Test output of graph export for dataset add."""
85-
result = runner.invoke(cli, ["dataset", "create", "my-dataset"])
86-
assert 0 == result.exit_code, format_result_exception(result)
87-
paths = []
88-
test_paths = []
89-
for i in range(3):
90-
new_file = tmpdir.join(f"file_{i}")
91-
new_file.write(str(i))
92-
paths.append(str(new_file))
93-
test_paths.append(os.path.relpath(str(new_file), str(project.path)))
94-
95-
# add data
96-
result = runner.invoke(cli, ["dataset", "add", "--copy", "my-dataset"] + paths)
97-
assert 0 == result.exit_code, format_result_exception(result)
89+
with cache_test_project.setup():
90+
result = runner.invoke(cli, ["dataset", "create", "my-dataset"])
91+
assert 0 == result.exit_code, format_result_exception(result)
92+
paths = []
93+
test_paths = []
94+
for i in range(3):
95+
new_file = tmpdir.join(f"file_{i}")
96+
new_file.write(str(i))
97+
paths.append(str(new_file))
98+
test_paths.append(os.path.relpath(str(new_file), str(project.path)))
99+
100+
# add data
101+
result = runner.invoke(cli, ["dataset", "add", "--copy", "my-dataset"] + paths)
102+
assert 0 == result.exit_code, format_result_exception(result)
103+
cache_test_project.save()
98104

99105
result = runner.invoke(cli, ["graph", "export", "--strict", "--format=json-ld", "--revision", "HEAD"])
100106
assert 0 == result.exit_code, format_result_exception(result)

tests/cli/test_merge.py

Lines changed: 99 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -24,96 +24,98 @@
2424
from tests.utils import format_result_exception
2525

2626

27-
def test_mergetool(runner, project, directory_tree, run_shell, with_injection):
27+
def test_mergetool(runner, project, directory_tree, run_shell, with_injection, cache_test_project):
2828
"""Test that merge tool can merge renku metadata."""
29-
result = runner.invoke(cli, ["mergetool", "install"])
29+
if not cache_test_project.setup():
30+
result = runner.invoke(cli, ["mergetool", "install"])
3031

31-
assert 0 == result.exit_code, format_result_exception(result)
32+
assert 0 == result.exit_code, format_result_exception(result)
3233

33-
# create a common dataset
34-
result = runner.invoke(
35-
cli, ["dataset", "add", "--copy", "--create", "shared-dataset", str(directory_tree)], catch_exceptions=False
36-
)
37-
assert 0 == result.exit_code, format_result_exception(result)
34+
# create a common dataset
35+
result = runner.invoke(
36+
cli, ["dataset", "add", "--copy", "--create", "shared-dataset", str(directory_tree)], catch_exceptions=False
37+
)
38+
assert 0 == result.exit_code, format_result_exception(result)
3839

39-
# Create a common workflow
40-
output = run_shell('renku run --name "shared-workflow" echo "a unique string" > my_output_file')
40+
# Create a common workflow
41+
output = run_shell('renku run --name "shared-workflow" echo "a unique string" > my_output_file')
4142

42-
assert b"" == output[0]
43-
assert output[1] is None
43+
assert b"" == output[0]
44+
assert output[1] is None
4445

45-
# switch to a new branch
46-
output = run_shell("git checkout -b remote-branch")
46+
# switch to a new branch
47+
output = run_shell("git checkout -b remote-branch")
4748

48-
assert b"Switched to a new branch 'remote-branch'\n" == output[0]
49-
assert output[1] is None
49+
assert b"Switched to a new branch 'remote-branch'\n" == output[0]
50+
assert output[1] is None
5051

51-
# edit the dataset
52-
result = runner.invoke(cli, ["dataset", "edit", "-d", "remote description", "shared-dataset"])
53-
assert 0 == result.exit_code, format_result_exception(result)
52+
# edit the dataset
53+
result = runner.invoke(cli, ["dataset", "edit", "-d", "remote description", "shared-dataset"])
54+
assert 0 == result.exit_code, format_result_exception(result)
5455

55-
result = runner.invoke(
56-
cli, ["dataset", "add", "--copy", "--create", "remote-dataset", str(directory_tree)], catch_exceptions=False
57-
)
58-
assert 0 == result.exit_code, format_result_exception(result)
56+
result = runner.invoke(
57+
cli, ["dataset", "add", "--copy", "--create", "remote-dataset", str(directory_tree)], catch_exceptions=False
58+
)
59+
assert 0 == result.exit_code, format_result_exception(result)
5960

60-
# Create a new workflow
61-
output = run_shell('renku run --name "remote-workflow" echo "a unique string" > remote_output_file')
61+
# Create a new workflow
62+
output = run_shell('renku run --name "remote-workflow" echo "a unique string" > remote_output_file')
6263

63-
assert b"" == output[0]
64-
assert output[1] is None
64+
assert b"" == output[0]
65+
assert output[1] is None
6566

66-
# Create a downstream workflow
67-
output = run_shell('renku run --name "remote-downstream-workflow" cp my_output_file my_remote_downstream')
67+
# Create a downstream workflow
68+
output = run_shell('renku run --name "remote-downstream-workflow" cp my_output_file my_remote_downstream')
6869

69-
assert b"" == output[0]
70-
assert output[1] is None
70+
assert b"" == output[0]
71+
assert output[1] is None
7172

72-
# Create another downstream workflow
73-
output = run_shell('renku run --name "remote-downstream-workflow2" cp remote_output_file my_remote_downstream2')
73+
# Create another downstream workflow
74+
output = run_shell('renku run --name "remote-downstream-workflow2" cp remote_output_file my_remote_downstream2')
7475

75-
assert b"" == output[0]
76-
assert output[1] is None
76+
assert b"" == output[0]
77+
assert output[1] is None
7778

78-
# Edit the project metadata
79-
result = runner.invoke(cli, ["project", "edit", "-k", "remote"])
79+
# Edit the project metadata
80+
result = runner.invoke(cli, ["project", "edit", "-k", "remote"])
8081

81-
assert 0 == result.exit_code, format_result_exception(result)
82+
assert 0 == result.exit_code, format_result_exception(result)
8283

83-
# Switch back to master
84-
output = run_shell("git checkout master")
84+
# Switch back to master
85+
output = run_shell("git checkout master")
8586

86-
assert b"Switched to branch 'master'\n" == output[0]
87-
assert output[1] is None
87+
assert b"Switched to branch 'master'\n" == output[0]
88+
assert output[1] is None
8889

89-
# Add a new dataset
90-
result = runner.invoke(
91-
cli, ["dataset", "add", "--copy", "--create", "local-dataset", str(directory_tree)], catch_exceptions=False
92-
)
93-
assert 0 == result.exit_code, format_result_exception(result)
90+
# Add a new dataset
91+
result = runner.invoke(
92+
cli, ["dataset", "add", "--copy", "--create", "local-dataset", str(directory_tree)], catch_exceptions=False
93+
)
94+
assert 0 == result.exit_code, format_result_exception(result)
9495

95-
# Create a local workflow
96-
output = run_shell('renku run --name "local-workflow" echo "a unique string" > local_output_file')
96+
# Create a local workflow
97+
output = run_shell('renku run --name "local-workflow" echo "a unique string" > local_output_file')
9798

98-
assert b"" == output[0]
99-
assert output[1] is None
99+
assert b"" == output[0]
100+
assert output[1] is None
100101

101-
# Create a local downstream workflow
102-
output = run_shell('renku run --name "local-downstream-workflow" cp my_output_file my_local_downstream')
102+
# Create a local downstream workflow
103+
output = run_shell('renku run --name "local-downstream-workflow" cp my_output_file my_local_downstream')
103104

104-
assert b"" == output[0]
105-
assert output[1] is None
105+
assert b"" == output[0]
106+
assert output[1] is None
106107

107-
# Create another local downstream workflow
108-
output = run_shell('renku run --name "local-downstream-workflow2" cp local_output_file my_local_downstream2')
108+
# Create another local downstream workflow
109+
output = run_shell('renku run --name "local-downstream-workflow2" cp local_output_file my_local_downstream2')
109110

110-
assert b"" == output[0]
111-
assert output[1] is None
111+
assert b"" == output[0]
112+
assert output[1] is None
112113

113-
# Edit the project in master as well
114-
result = runner.invoke(cli, ["project", "edit", "-k", "local"])
114+
# Edit the project in master as well
115+
result = runner.invoke(cli, ["project", "edit", "-k", "local"])
115116

116-
assert 0 == result.exit_code, format_result_exception(result)
117+
assert 0 == result.exit_code, format_result_exception(result)
118+
cache_test_project.save()
117119

118120
# Merge branches
119121
output = run_shell("git merge --no-edit remote-branch")
@@ -146,32 +148,34 @@ def test_mergetool(runner, project, directory_tree, run_shell, with_injection):
146148
assert "remote description" == shared_dataset.description
147149

148150

149-
def test_mergetool_workflow_conflict(runner, project, run_shell, with_injection):
151+
def test_mergetool_workflow_conflict(runner, project, run_shell, with_injection, cache_test_project):
150152
"""Test that merge tool can merge conflicting workflows."""
151-
result = runner.invoke(cli, ["mergetool", "install"])
153+
if not cache_test_project.setup():
154+
result = runner.invoke(cli, ["mergetool", "install"])
152155

153-
assert 0 == result.exit_code, format_result_exception(result)
156+
assert 0 == result.exit_code, format_result_exception(result)
154157

155-
output = run_shell('renku run --name "shared-workflow" echo "a unique string" > my_output_file')
158+
output = run_shell('renku run --name "shared-workflow" echo "a unique string" > my_output_file')
156159

157-
assert b"" == output[0]
158-
assert output[1] is None
160+
assert b"" == output[0]
161+
assert output[1] is None
159162

160-
# Switch to a new branch and create some workflows
161-
output = run_shell("git checkout -b remote-branch")
163+
# Switch to a new branch and create some workflows
164+
output = run_shell("git checkout -b remote-branch")
162165

163-
assert b"Switched to a new branch 'remote-branch'\n" == output[0]
164-
assert output[1] is None
166+
assert b"Switched to a new branch 'remote-branch'\n" == output[0]
167+
assert output[1] is None
165168

166-
output = run_shell('renku run --name "remote-workflow" cp my_output_file out1')
169+
output = run_shell('renku run --name "remote-workflow" cp my_output_file out1')
167170

168-
assert b"" == output[0]
169-
assert output[1] is None
171+
assert b"" == output[0]
172+
assert output[1] is None
170173

171-
output = run_shell('renku run --name "common-name" cp my_output_file out2')
174+
output = run_shell('renku run --name "common-name" cp my_output_file out2')
172175

173-
assert b"" == output[0]
174-
assert output[1] is None
176+
assert b"" == output[0]
177+
assert output[1] is None
178+
cache_test_project.save()
175179

176180
with with_injection():
177181
plan_gateway = PlanGateway()
@@ -237,30 +241,33 @@ def test_mergetool_workflow_conflict(runner, project, run_shell, with_injection)
237241
assert len(plans) == 4
238242

239243

240-
def test_mergetool_workflow_complex_conflict(runner, project, run_shell, with_injection):
244+
def test_mergetool_workflow_complex_conflict(runner, project, run_shell, with_injection, cache_test_project):
241245
"""Test that merge tool can merge complex conflicts in workflows."""
242-
result = runner.invoke(cli, ["mergetool", "install"])
246+
if not cache_test_project.setup():
247+
result = runner.invoke(cli, ["mergetool", "install"])
243248

244-
assert 0 == result.exit_code, format_result_exception(result)
249+
assert 0 == result.exit_code, format_result_exception(result)
245250

246-
output = run_shell('renku run --name "shared-workflow" echo "a unique string" > my_output_file')
251+
output = run_shell('renku run --name "shared-workflow" echo "a unique string" > my_output_file')
247252

248-
assert b"" == output[0]
249-
assert output[1] is None
253+
assert b"" == output[0]
254+
assert output[1] is None
250255

251-
# Switch to a new branch and create some workflows
252-
output = run_shell("git checkout -b remote-branch")
256+
# Switch to a new branch and create some workflows
257+
output = run_shell("git checkout -b remote-branch")
253258

254-
assert b"Switched to a new branch 'remote-branch'\n" == output[0]
255-
assert output[1] is None
259+
assert b"Switched to a new branch 'remote-branch'\n" == output[0]
260+
assert output[1] is None
256261

257-
output = run_shell('renku run --name "intermediate-workflow" cp my_output_file intermediate')
262+
output = run_shell('renku run --name "intermediate-workflow" cp my_output_file intermediate')
258263

259-
assert b"" == output[0]
264+
assert b"" == output[0]
260265

261-
output = run_shell('renku run --name "final-workflow" cp intermediate final')
266+
output = run_shell('renku run --name "final-workflow" cp intermediate final')
262267

263-
assert b"" == output[0]
268+
assert b"" == output[0]
269+
270+
cache_test_project.save()
264271

265272
with with_injection():
266273
plan_gateway = PlanGateway()

0 commit comments

Comments
 (0)