diff options
author | Phil Dawson <phil.dawson@codethink.co.uk> | 2018-06-20 11:03:23 +0100 |
---|---|---|
committer | Jim MacArthur <jim.macarthur@codethink.co.uk> | 2018-07-25 14:03:23 +0100 |
commit | a0ad985f7b342d68a19803ae23319eac3b895550 (patch) | |
tree | b1f62a30de246278d1c823965e53183ebe989aff | |
parent | 4a637d631814b0d3e20fd2d4ffb8b9d2f60d04a6 (diff) | |
download | buildstream-a0ad985f7b342d68a19803ae23319eac3b895550.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
-rw-r--r-- | tests/frontend/show.py | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/tests/frontend/show.py b/tests/frontend/show.py index 0276961ab..80c48381a 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -1,8 +1,9 @@ import os -import pytest +import sys +import shutil import itertools +import pytest from tests.testutils import cli - from buildstream import _yaml from buildstream._exceptions import ErrorDomain, LoadErrorReason @@ -232,3 +233,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) |