diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-07-14 19:58:08 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-07-15 23:30:40 +0900 |
commit | 35ecd21e9449988d54826de6234be343fb1a3f37 (patch) | |
tree | 19a98320807174033ec9cb12f98b3da6235a1923 | |
parent | 4dc5b116e6d8cbdf124af28aa1eeea078f485400 (diff) | |
download | buildstream-35ecd21e9449988d54826de6234be343fb1a3f37.tar.gz |
tests/frontend/show.py: Test proper resolution of max-jobs
This tests that the resolution of the `max-jobs` automatic variable
is properly controlled by the new user configuration and command
line option, including the default automatic '0' value.
Regression test for #1033
-rw-r--r-- | tests/frontend/show.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/frontend/show.py b/tests/frontend/show.py index d138b3693..174ddb7dd 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -464,3 +464,54 @@ def test_format_deps(cli, datafiles, dep_kind, expected_deps): if result.output.strip() != expected: raise AssertionError("Expected output:\n{}\nInstead received output:\n{}" .format(expected, result.output)) + + +# This tests the resolved value of the 'max-jobs' variable, +# ensuring at least that the variables are resolved according +# to how the user has configured max-jobs +# +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project')) +@pytest.mark.parametrize("cli_value, config_value", [ + (None, None), + (None, '16'), + ('16', None), + ('5', '16'), + ('0', '16'), + ('16', '0'), +]) +def test_max_jobs(cli, datafiles, cli_value, config_value): + project = str(datafiles) + target = 'target.bst' + + # Specify `--max-jobs` if this test sets it + args = [] + if cli_value is not None: + args += ['--max-jobs', cli_value] + args += ['show', '--deps', 'none', '--format', '%{vars}', target] + + # Specify `max-jobs` in user configuration if this test sets it + if config_value is not None: + cli.configure({ + 'build': { + 'max-jobs': config_value + } + }) + + result = cli.run(project=project, silent=True, args=args) + result.assert_success() + loaded = _yaml.load_data(result.output) + loaded_value = _yaml.node_get(loaded, int, 'max-jobs') + + # We expect the value provided on the command line to take + # precedence over the configuration file value, if specified. + # + # If neither are specified then we expect the default + expected_value = cli_value or config_value or '0' + + if expected_value == '0': + # If we are expecting the automatic behavior of using the maximum + # number of cores available, just check that it is a value > 0 + assert loaded_value > 0, "Automatic setting of max-jobs didnt work" + else: + # Check that we got the explicitly set value + assert loaded_value == int(expected_value) |