diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2019-01-24 06:13:57 +0000 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2019-01-24 06:13:57 +0000 |
commit | 341b131b35c16f1224249559c73bc525b8116d44 (patch) | |
tree | 30e51257047370c2ebe2b0ec0b6947a239022587 /tests | |
parent | 3a6e953fe5b51c76bb6ebb0881eaf181267112ed (diff) | |
parent | 46eb301831f205abbee7408c0e37df92b0991ac5 (diff) | |
download | buildstream-341b131b35c16f1224249559c73bc525b8116d44.tar.gz |
Merge branch 'tristan/test-element-states' into 'master'
Reduce number of calls to `bst show` in tests
See merge request BuildStream/buildstream!1103
Diffstat (limited to 'tests')
-rw-r--r-- | tests/artifactcache/expiry.py | 53 | ||||
-rw-r--r-- | tests/elements/filter.py | 10 | ||||
-rw-r--r-- | tests/frontend/pull.py | 8 | ||||
-rw-r--r-- | tests/frontend/push.py | 15 | ||||
-rw-r--r-- | tests/frontend/track.py | 24 | ||||
-rw-r--r-- | tests/frontend/workspace.py | 28 | ||||
-rw-r--r-- | tests/sources/remote.py | 19 | ||||
-rw-r--r-- | tests/testutils/runcli.py | 5 |
8 files changed, 94 insertions, 68 deletions
diff --git a/tests/artifactcache/expiry.py b/tests/artifactcache/expiry.py index 1292e50ea..2bdca0d12 100644 --- a/tests/artifactcache/expiry.py +++ b/tests/artifactcache/expiry.py @@ -66,8 +66,9 @@ def test_artifact_expires(cli, datafiles, tmpdir): res.assert_success() # Check that the correct element remains in the cache - assert cli.get_element_state(project, 'target.bst') != 'cached' - assert cli.get_element_state(project, 'target2.bst') == 'cached' + states = cli.get_element_states(project, ['target.bst', 'target2.bst']) + assert states['target.bst'] != 'cached' + assert states['target2.bst'] == 'cached' # Ensure that we don't end up deleting the whole cache (or worse) if @@ -144,9 +145,11 @@ def test_expiry_order(cli, datafiles, tmpdir): # have been removed. # Note that buildstream will reduce the cache to 50% of the # original size - we therefore remove multiple elements. - - assert (tuple(cli.get_element_state(project, element) for element in - ('unrelated.bst', 'target.bst', 'target2.bst', 'dep.bst', 'expire.bst')) == + check_elements = [ + 'unrelated.bst', 'target.bst', 'target2.bst', 'dep.bst', 'expire.bst' + ] + states = cli.get_element_states(project, check_elements) + assert (tuple(states[element] for element in check_elements) == ('buildable', 'buildable', 'buildable', 'cached', 'cached', )) @@ -176,8 +179,9 @@ def test_keep_dependencies(cli, datafiles, tmpdir): res.assert_success() # Check that the correct element remains in the cache - assert cli.get_element_state(project, 'dependency.bst') == 'cached' - assert cli.get_element_state(project, 'unrelated.bst') == 'cached' + states = cli.get_element_states(project, ['dependency.bst', 'unrelated.bst']) + assert states['dependency.bst'] == 'cached' + assert states['unrelated.bst'] == 'cached' # We try to build an element which depends on the LRU artifact, # and could therefore fail if we didn't make sure dependencies @@ -192,9 +196,10 @@ def test_keep_dependencies(cli, datafiles, tmpdir): res = cli.run(project=project, args=['build', 'target.bst']) res.assert_success() - assert cli.get_element_state(project, 'unrelated.bst') != 'cached' - assert cli.get_element_state(project, 'dependency.bst') == 'cached' - assert cli.get_element_state(project, 'target.bst') == 'cached' + states = cli.get_element_states(project, ['target.bst', 'unrelated.bst']) + assert states['target.bst'] == 'cached' + assert states['dependency.bst'] == 'cached' + assert states['unrelated.bst'] != 'cached' # Assert that we never delete a dependency required for a build tree @@ -239,11 +244,11 @@ def test_never_delete_required(cli, datafiles, tmpdir): # life there may potentially be N-builders cached artifacts # which exceed the quota # - assert cli.get_element_state(project, 'dep1.bst') == 'cached' - assert cli.get_element_state(project, 'dep2.bst') == 'cached' - - assert cli.get_element_state(project, 'dep3.bst') != 'cached' - assert cli.get_element_state(project, 'target.bst') != 'cached' + states = cli.get_element_states(project, ['target.bst']) + assert states['dep1.bst'] == 'cached' + assert states['dep2.bst'] == 'cached' + assert states['dep3.bst'] != 'cached' + assert states['target.bst'] != 'cached' # Assert that we never delete a dependency required for a build tree, @@ -275,10 +280,11 @@ def test_never_delete_required_track(cli, datafiles, tmpdir): res.assert_success() # They should all be cached - assert cli.get_element_state(project, 'dep1.bst') == 'cached' - assert cli.get_element_state(project, 'dep2.bst') == 'cached' - assert cli.get_element_state(project, 'dep3.bst') == 'cached' - assert cli.get_element_state(project, 'target.bst') == 'cached' + states = cli.get_element_states(project, ['target.bst']) + assert states['dep1.bst'] == 'cached' + assert states['dep2.bst'] == 'cached' + assert states['dep3.bst'] == 'cached' + assert states['target.bst'] == 'cached' # Now increase the size of all the elements # @@ -296,10 +302,11 @@ def test_never_delete_required_track(cli, datafiles, tmpdir): # Expect the same result that we did in test_never_delete_required() # - assert cli.get_element_state(project, 'dep1.bst') == 'cached' - assert cli.get_element_state(project, 'dep2.bst') == 'cached' - assert cli.get_element_state(project, 'dep3.bst') != 'cached' - assert cli.get_element_state(project, 'target.bst') != 'cached' + states = cli.get_element_states(project, ['target.bst']) + assert states['dep1.bst'] == 'cached' + assert states['dep2.bst'] == 'cached' + assert states['dep3.bst'] != 'cached' + assert states['target.bst'] != 'cached' # Ensure that only valid cache quotas make it through the loading diff --git a/tests/elements/filter.py b/tests/elements/filter.py index 6c0a3ee1c..a63ef29e1 100644 --- a/tests/elements/filter.py +++ b/tests/elements/filter.py @@ -389,8 +389,9 @@ def test_filter_track_multi(datafiles, cli, tmpdir): _yaml.dump(filter2_config, filter2_file) # Assert that a fetch is needed - assert cli.get_element_state(project, input_name) == 'no reference' - assert cli.get_element_state(project, input2_name) == 'no reference' + states = cli.get_element_states(project, [input_name, input2_name]) + assert states[input_name] == 'no reference' + assert states[input2_name] == 'no reference' # Now try to track it result = cli.run(project=project, args=["source", "track", "filter1.bst", "filter2.bst"]) @@ -450,8 +451,9 @@ def test_filter_track_multi_exclude(datafiles, cli, tmpdir): _yaml.dump(filter2_config, filter2_file) # Assert that a fetch is needed - assert cli.get_element_state(project, input_name) == 'no reference' - assert cli.get_element_state(project, input2_name) == 'no reference' + states = cli.get_element_states(project, [input_name, input2_name]) + assert states[input_name] == 'no reference' + assert states[input2_name] == 'no reference' # Now try to track it result = cli.run(project=project, args=["source", "track", "filter1.bst", "filter2.bst", "--except", input_name]) diff --git a/tests/frontend/pull.py b/tests/frontend/pull.py index 254b6d584..f0d6fbf4e 100644 --- a/tests/frontend/pull.py +++ b/tests/frontend/pull.py @@ -66,16 +66,16 @@ def test_push_pull_all(cli, tmpdir, datafiles): shutil.rmtree(artifacts) # Assert that nothing is cached locally anymore - for element_name in all_elements: - assert cli.get_element_state(project, element_name) != 'cached' + states = cli.get_element_states(project, all_elements) + assert not any(states[e] == 'cached' for e in all_elements) # Now try bst pull result = cli.run(project=project, args=['artifact', 'pull', '--deps', 'all', 'target.bst']) result.assert_success() # And assert that it's again in the local cache, without having built - for element_name in all_elements: - assert cli.get_element_state(project, element_name) == 'cached' + states = cli.get_element_states(project, all_elements) + assert not any(states[e] != 'cached' for e in all_elements) # Tests that: diff --git a/tests/frontend/push.py b/tests/frontend/push.py index 6ed163a93..f3f9b52f1 100644 --- a/tests/frontend/push.py +++ b/tests/frontend/push.py @@ -250,9 +250,10 @@ def test_artifact_expires(cli, datafiles, tmpdir): result.assert_success() # check that element's 1 and 2 are cached both locally and remotely - assert cli.get_element_state(project, 'element1.bst') == 'cached' + states = cli.get_element_states(project, ['element1.bst', 'element2.bst']) + assert states['element1.bst'] == 'cached' + assert states['element2.bst'] == 'cached' assert_shared(cli, share, project, 'element1.bst') - assert cli.get_element_state(project, 'element2.bst') == 'cached' assert_shared(cli, share, project, 'element2.bst') # Create and build another element of 5 MB (This will exceed the free disk space available) @@ -298,11 +299,12 @@ def test_artifact_too_large(cli, datafiles, tmpdir): result.assert_success() # Ensure that the small artifact is still in the share - assert cli.get_element_state(project, 'small_element.bst') == 'cached' + states = cli.get_element_states(project, ['small_element.bst', 'large_element.bst']) + states['small_element.bst'] == 'cached' assert_shared(cli, share, project, 'small_element.bst') # Ensure that the artifact is cached locally but NOT remotely - assert cli.get_element_state(project, 'large_element.bst') == 'cached' + states['large_element.bst'] == 'cached' assert_not_shared(cli, share, project, 'large_element.bst') @@ -334,8 +336,9 @@ def test_recently_pulled_artifact_does_not_expire(cli, datafiles, tmpdir): result.assert_success() # Ensure they are cached locally - assert cli.get_element_state(project, 'element1.bst') == 'cached' - assert cli.get_element_state(project, 'element2.bst') == 'cached' + states = cli.get_element_states(project, ['element1.bst', 'element2.bst']) + assert states['element1.bst'] == 'cached' + assert states['element2.bst'] == 'cached' # Ensure that they have been pushed to the cache assert_shared(cli, share, project, 'element1.bst') diff --git a/tests/frontend/track.py b/tests/frontend/track.py index d149bd050..8857294ac 100644 --- a/tests/frontend/track.py +++ b/tests/frontend/track.py @@ -123,7 +123,7 @@ def test_track_recurse(cli, tmpdir, datafiles, kind, amount): last_element_name = element_name # Assert that a fetch is needed - states = cli.get_element_states(project, last_element_name) + states = cli.get_element_states(project, [last_element_name]) for element_name in element_names: assert states[element_name] == 'no reference' @@ -143,7 +143,7 @@ def test_track_recurse(cli, tmpdir, datafiles, kind, amount): result.assert_success() # Assert that the base is buildable and the rest are waiting - states = cli.get_element_states(project, last_element_name) + states = cli.get_element_states(project, [last_element_name]) for element_name in element_names: if element_name == element_names[0]: assert states[element_name] == 'buildable' @@ -171,8 +171,9 @@ def test_track_single(cli, tmpdir, datafiles): dep_name=element_dep_name) # Assert that tracking is needed for both elements - assert cli.get_element_state(project, element_dep_name) == 'no reference' - assert cli.get_element_state(project, element_target_name) == 'no reference' + states = cli.get_element_states(project, [element_target_name]) + assert states[element_dep_name] == 'no reference' + assert states[element_target_name] == 'no reference' # Now first try to track only one element result = cli.run(project=project, args=[ @@ -187,8 +188,9 @@ def test_track_single(cli, tmpdir, datafiles): result.assert_success() # Assert that the dependency is waiting and the target has still never been tracked - assert cli.get_element_state(project, element_dep_name) == 'no reference' - assert cli.get_element_state(project, element_target_name) == 'waiting' + states = cli.get_element_states(project, [element_target_name]) + assert states[element_dep_name] == 'no reference' + assert states[element_target_name] == 'waiting' @pytest.mark.datafiles(DATA_DIR) @@ -212,8 +214,9 @@ def test_track_recurse_except(cli, tmpdir, datafiles, kind): dep_name=element_dep_name) # Assert that a fetch is needed - assert cli.get_element_state(project, element_dep_name) == 'no reference' - assert cli.get_element_state(project, element_target_name) == 'no reference' + states = cli.get_element_states(project, [element_target_name]) + assert states[element_dep_name] == 'no reference' + assert states[element_target_name] == 'no reference' # Now first try to track it result = cli.run(project=project, args=[ @@ -231,8 +234,9 @@ def test_track_recurse_except(cli, tmpdir, datafiles, kind): result.assert_success() # Assert that the dependency is buildable and the target is waiting - assert cli.get_element_state(project, element_dep_name) == 'no reference' - assert cli.get_element_state(project, element_target_name) == 'waiting' + states = cli.get_element_states(project, [element_target_name]) + assert states[element_dep_name] == 'no reference' + assert states[element_target_name] == 'waiting' @pytest.mark.datafiles(os.path.join(TOP_DIR)) diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py index d08225353..d73bb1c70 100644 --- a/tests/frontend/workspace.py +++ b/tests/frontend/workspace.py @@ -107,15 +107,17 @@ class WorkspaceCreater(): element_name, element_path, workspace_dir = \ self.create_workspace_element(kind, track, suffix, workspace_dir_usr, element_attrs) - - # Assert that there is no reference, a track & fetch is needed - state = self.cli.get_element_state(self.project_path, element_name) - if track: - assert state == 'no reference' - else: - assert state == 'fetch needed' element_tuples.append((element_name, workspace_dir)) + # Assert that there is no reference, a track & fetch is needed + states = self.cli.get_element_states(self.project_path, [ + e for e, _ in element_tuples + ]) + if track: + assert not any(states[e] != 'no reference' for e, _ in element_tuples) + else: + assert not any(states[e] != 'fetch needed' for e, _ in element_tuples) + return element_tuples def open_workspaces(self, kinds, track, suffixs=None, workspace_dir=None, @@ -140,12 +142,14 @@ class WorkspaceCreater(): result.assert_success() - for element_name, workspace_dir in element_tuples: - # Assert that we are now buildable because the source is - # now cached. - assert self.cli.get_element_state(self.project_path, element_name) == 'buildable' + # Assert that we are now buildable because the source is now cached. + states = self.cli.get_element_states(self.project_path, [ + e for e, _ in element_tuples + ]) + assert not any(states[e] != 'buildable' for e, _ in element_tuples) - # Check that the executable hello file is found in the workspace + # Check that the executable hello file is found in each workspace + for element_name, workspace_dir in element_tuples: filename = os.path.join(workspace_dir, 'usr', 'bin', 'hello') assert os.path.exists(filename) diff --git a/tests/sources/remote.py b/tests/sources/remote.py index b8cf049b3..1d7727302 100644 --- a/tests/sources/remote.py +++ b/tests/sources/remote.py @@ -136,18 +136,25 @@ def test_unique_key(cli, tmpdir, datafiles): ''' project = os.path.join(datafiles.dirname, datafiles.basename) generate_project(project, tmpdir) - assert cli.get_element_state(project, 'target.bst') == "fetch needed" - assert cli.get_element_state(project, 'target-custom.bst') == "fetch needed" - assert cli.get_element_state(project, 'target-custom-executable.bst') == "fetch needed" + states = cli.get_element_states(project, [ + 'target.bst', 'target-custom.bst', 'target-custom-executable.bst' + ]) + assert states['target.bst'] == "fetch needed" + assert states['target-custom.bst'] == "fetch needed" + assert states['target-custom-executable.bst'] == "fetch needed" + # Try to fetch it result = cli.run(project=project, args=[ 'source', 'fetch', 'target.bst' ]) # We should download the file only once - assert cli.get_element_state(project, 'target.bst') == 'buildable' - assert cli.get_element_state(project, 'target-custom.bst') == 'buildable' - assert cli.get_element_state(project, 'target-custom-executable.bst') == 'buildable' + states = cli.get_element_states(project, [ + 'target.bst', 'target-custom.bst', 'target-custom-executable.bst' + ]) + assert states['target.bst'] == 'buildable' + assert states['target-custom.bst'] == 'buildable' + assert states['target-custom-executable.bst'] == 'buildable' # But the cache key is different because the 'filename' is different. assert cli.get_element_key(project, 'target.bst') != \ diff --git a/tests/testutils/runcli.py b/tests/testutils/runcli.py index 7cd81e0a6..b051dec21 100644 --- a/tests/testutils/runcli.py +++ b/tests/testutils/runcli.py @@ -398,13 +398,12 @@ class Cli(): # # Returns a dictionary with the element names as keys # - def get_element_states(self, project, target, deps='all'): + def get_element_states(self, project, targets, deps='all'): result = self.run(project=project, silent=True, args=[ 'show', '--deps', deps, '--format', '%{name}||%{state}', - target - ]) + ] + targets) result.assert_success() lines = result.output.splitlines() states = {} |