Skip to content
Snippets Groups Projects
Commit 5419216d authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

tests/frontend/buildorder.py: Adding tests ensuring expected build order

For each sample project and expected result order, this test ensures that:

  * bst show --deps plan: Always shows the expected build order.

  * bst build: Always builds in the expected order.
parent 630e26f1
No related branches found
No related tags found
No related merge requests found
Pipeline #42915695 failed
import os
import pytest
from tests.testutils import cli, create_repo
from buildstream import _yaml
# Project directory
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"project",
)
def create_element(repo, name, path, dependencies, ref=None):
element = {
'kind': 'import',
'sources': [
repo.source_config(ref=ref)
],
'depends': dependencies
}
_yaml.dump(element, os.path.join(path, name))
# This tests a variety of scenarios and checks that the order in
# which things are processed remains stable.
#
# This is especially important in order to ensure that our
# depth sorting and optimization of which elements should be
# processed first is doing it's job right, and that we are
# promoting elements to the build queue as soon as possible
#
# Parameters:
# targets (target elements): The targets to invoke bst with
# template (dict): The project template dictionary, for create_element()
# expected (list): A list of element names in the expected order
#
@pytest.mark.datafiles(os.path.join(DATA_DIR))
@pytest.mark.parametrize("target,template,expected", [
# First simple test
('3.bst', {
'0.bst': ['1.bst'],
'1.bst': [],
'2.bst': ['0.bst'],
'3.bst': ['0.bst', '1.bst', '2.bst']
},
['1.bst', '0.bst', '2.bst', '3.bst']),
# A more complicated test with build of build dependencies
('target.bst', {
'a.bst': [],
'base.bst': [],
'timezones.bst': [],
'middleware.bst': [{'filename': 'base.bst', 'type': 'build'}],
'app.bst': [{'filename': 'middleware.bst', 'type': 'build'}],
'target.bst': ['a.bst', 'base.bst', 'middleware.bst', 'app.bst', 'timezones.bst']
},
['base.bst', 'middleware.bst', 'a.bst', 'app.bst', 'timezones.bst', 'target.bst']),
])
def test_build_order(cli, datafiles, tmpdir, target, template, expected):
project = os.path.join(datafiles.dirname, datafiles.basename)
dev_files_path = os.path.join(project, 'files', 'dev-files')
element_path = os.path.join(project, 'elements')
# Configure to only allow one fetcher at a time, make it easy to
# determine what is being planned in what order.
cli.configure({
'scheduler': {
'fetchers': 1,
'builders': 1
}
})
# Build the project from the template, make import elements
# all with the same repo
#
repo = create_repo('git', str(tmpdir))
ref = repo.create(dev_files_path)
for element, dependencies in template.items():
create_element(repo, element, element_path, dependencies, ref=ref)
repo.add_commit()
# Show it for debugging purposes
result = cli.run(args=['show', '--deps', 'plan', '--format', '%{name}', target], project=project, silent=True)
elements = result.output.splitlines()
print("Show reported the following order: {}".format(elements))
# Run the build
result = cli.run(args=['build', target], project=project, silent=True)
result.assert_success()
# Check the order of elements which passed through the build queue
builds = result.get_start_order('build')
print("Builds started in the following order: {}".format(builds))
# First check that we are building in the order we planned to build,
# by asserting that the `bst show` results are in the same order
# as the observed build order.
assert elements == builds
# Now assert that this order is the same as that we expected
assert elements == expected
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment