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:19:24 +0900 |
commit | fa127a5c02e0793e8ccf95bbae1f13dde4a54d7d (patch) | |
tree | 2aacc2b55bf32a866831cd366d188647614009db | |
parent | 5ab0aa9b72b4d5a950a3e6f0f50e6ed5d2d50012 (diff) | |
download | buildstream-fa127a5c02e0793e8ccf95bbae1f13dde4a54d7d.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 2569d4611..8bb0bab3f 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -320,3 +320,54 @@ def test_exceed_max_recursion_depth(cli, tmpdir, dependency_depth): assert result.exit_code == -1 shutil.rmtree(project_path) + + +# 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(DATA_DIR) +@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) |