diff options
author | Phil Dawson <phil.dawson@codethink.co.uk> | 2018-06-20 11:03:23 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-08-14 05:33:23 +0000 |
commit | b82d67938d984f52dd9f24cd0f6fc0874df3639c (patch) | |
tree | 0a83f9a1ab5410668a60cd344ae281d18a220c90 /tests/frontend | |
parent | d6714dc2ea79f1012f24960651f993ec9b47071c (diff) | |
download | buildstream-b82d67938d984f52dd9f24cd0f6fc0874df3639c.tar.gz |
tests/frontend/show.py: Add test case for maximum recursion depth being exceeded
Add test to ensure gracefull handling of exception thrown while loading
a pipeline due the python's max recursion depth being exceeded.
This is part of the work for issue #203
Diffstat (limited to 'tests/frontend')
-rw-r--r-- | tests/frontend/show.py | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/frontend/show.py b/tests/frontend/show.py index b21569426..a7d71dc42 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -1,6 +1,8 @@ import os -import pytest +import sys +import shutil import itertools +import pytest from tests.testutils import cli, generate_junction from buildstream import _yaml @@ -232,3 +234,58 @@ def test_fetched_junction(cli, tmpdir, datafiles, element_name): results = result.output.strip().splitlines() assert 'junction.bst:import-etc.bst-buildable' in results + + +############################################################### +# Testing recursion depth # +############################################################### +@pytest.mark.parametrize("dependency_depth", [100, 500, 1200]) +def test_exceed_max_recursion_depth(cli, tmpdir, dependency_depth): + project_name = "recursion-test" + path = str(tmpdir) + project_path = os.path.join(path, project_name) + + def setup_test(): + """ + Creates a bst project with dependencydepth + 1 elements, each of which + depends of the previous element to be created. Each element created + is of type import and has an empty source file. + """ + os.mkdir(project_path) + + result = cli.run(project=project_path, silent=True, + args=['init', '--project-name', project_name]) + result.assert_success() + + sourcefiles_path = os.path.join(project_path, "files") + os.mkdir(sourcefiles_path) + + element_path = os.path.join(project_path, "elements") + for i in range(0, dependency_depth + 1): + element = { + 'kind': 'import', + 'sources': [{'kind': 'local', + 'path': 'files/source{}'.format(str(i))}], + 'depends': ['element{}.bst'.format(str(i - 1))] + } + if i == 0: + del element['depends'] + _yaml.dump(element, os.path.join(element_path, "element{}.bst".format(str(i)))) + + source = os.path.join(sourcefiles_path, "source{}".format(str(i))) + open(source, 'x').close() + assert os.path.exists(source) + + setup_test() + result = cli.run(project=project_path, silent=True, + args=['show', "element{}.bst".format(str(dependency_depth))]) + + recursion_limit = sys.getrecursionlimit() + if dependency_depth <= recursion_limit: + result.assert_success() + else: + # Assert exception is thown and handled + assert not result.unhandled_exception + assert result.exit_code == -1 + + shutil.rmtree(project_path) |