[Notes] [Git][BuildStream/buildstream][tristan/element-processing-order] tests/frontend/buildorder.py: Adding tests ensuring expected build order



Title: GitLab

Tristan Van Berkom pushed to branch tristan/element-processing-order at BuildStream / buildstream

Commits:

1 changed file:

Changes:

  • tests/frontend/buildorder.py
    1
    +import os
    
    2
    +
    
    3
    +import pytest
    
    4
    +from tests.testutils import cli, create_repo
    
    5
    +
    
    6
    +from buildstream import _yaml
    
    7
    +
    
    8
    +# Project directory
    
    9
    +DATA_DIR = os.path.join(
    
    10
    +    os.path.dirname(os.path.realpath(__file__)),
    
    11
    +    "project",
    
    12
    +)
    
    13
    +
    
    14
    +
    
    15
    +def create_element(repo, name, path, dependencies, ref=None):
    
    16
    +    element = {
    
    17
    +        'kind': 'import',
    
    18
    +        'sources': [
    
    19
    +            repo.source_config(ref=ref)
    
    20
    +        ],
    
    21
    +        'depends': dependencies
    
    22
    +    }
    
    23
    +    _yaml.dump(element, os.path.join(path, name))
    
    24
    +
    
    25
    +
    
    26
    +# This tests a variety of scenarios and checks that the order in
    
    27
    +# which things are processed remains stable.
    
    28
    +#
    
    29
    +# This is especially important in order to ensure that our
    
    30
    +# depth sorting and optimization of which elements should be
    
    31
    +# processed first is doing it's job right, and that we are
    
    32
    +# promoting elements to the build queue as soon as possible
    
    33
    +#
    
    34
    +# Parameters:
    
    35
    +#    targets (target elements): The targets to invoke bst with
    
    36
    +#    template (dict): The project template dictionary, for create_element()
    
    37
    +#    expected (list): A list of element names in the expected order
    
    38
    +#
    
    39
    +@pytest.mark.datafiles(os.path.join(DATA_DIR))
    
    40
    +@pytest.mark.parametrize("target,template,expected", [
    
    41
    +    # First simple test
    
    42
    +    ('3.bst', {
    
    43
    +        '0.bst': ['1.bst'],
    
    44
    +        '1.bst': [],
    
    45
    +        '2.bst': ['0.bst'],
    
    46
    +        '3.bst': ['0.bst', '1.bst', '2.bst']
    
    47
    +    }, ['1.bst', '0.bst', '2.bst', '3.bst']),
    
    48
    +
    
    49
    +    # A more complicated test with build of build dependencies
    
    50
    +    ('target.bst', {
    
    51
    +        'a.bst': [],
    
    52
    +        'base.bst': [],
    
    53
    +        'timezones.bst': [],
    
    54
    +        'middleware.bst': [{'filename': 'base.bst', 'type': 'build'}],
    
    55
    +        'app.bst': [{'filename': 'middleware.bst', 'type': 'build'}],
    
    56
    +        'target.bst': ['a.bst', 'base.bst', 'middleware.bst', 'app.bst', 'timezones.bst']
    
    57
    +    }, ['base.bst', 'middleware.bst', 'a.bst', 'app.bst', 'timezones.bst', 'target.bst']),
    
    58
    +])
    
    59
    +def test_build_order(cli, datafiles, tmpdir, target, template, expected):
    
    60
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    61
    +    dev_files_path = os.path.join(project, 'files', 'dev-files')
    
    62
    +    element_path = os.path.join(project, 'elements')
    
    63
    +
    
    64
    +    # Configure to only allow one fetcher at a time, make it easy to
    
    65
    +    # determine what is being planned in what order.
    
    66
    +    cli.configure({
    
    67
    +        'scheduler': {
    
    68
    +            'fetchers': 1,
    
    69
    +            'builders': 1
    
    70
    +        }
    
    71
    +    })
    
    72
    +
    
    73
    +    # Build the project from the template, make import elements
    
    74
    +    # all with the same repo
    
    75
    +    #
    
    76
    +    repo = create_repo('git', str(tmpdir))
    
    77
    +    ref = repo.create(dev_files_path)
    
    78
    +    for element, dependencies in template.items():
    
    79
    +        create_element(repo, element, element_path, dependencies, ref=ref)
    
    80
    +        repo.add_commit()
    
    81
    +
    
    82
    +    # Show it for debugging purposes
    
    83
    +    result = cli.run(args=['show', '--deps', 'plan', '--format', '%{name}', target], project=project, silent=True)
    
    84
    +    elements = result.output.splitlines()
    
    85
    +    print("Show reported the following order: {}".format(elements))
    
    86
    +
    
    87
    +    # Run the build
    
    88
    +    result = cli.run(args=['build', target], project=project, silent=True)
    
    89
    +    result.assert_success()
    
    90
    +
    
    91
    +    # Check the order of elements which passed through the build queue
    
    92
    +    builds = result.get_start_order('build')
    
    93
    +    print("Builds started in the following order: {}".format(builds))
    
    94
    +
    
    95
    +    # First check that we are building in the order we planned to build,
    
    96
    +    # by asserting that the `bst show` results are in the same order
    
    97
    +    # as the observed build order.
    
    98
    +    assert elements == builds
    
    99
    +
    
    100
    +    # Now assert that this order is the same as that we expected
    
    101
    +    assert elements == expected



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]