From b41b6b9cc1f91e8770b45f2e0a0cb18563770af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hunor=20Csomort=C3=A1ni?= Date: Wed, 20 Nov 2019 13:56:39 +0100 Subject: [PATCH] Tests: allow reusing an existing module build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Module builds take a long time to run, which can be a pain to wait for during integration test development. Instead of requiring developers to locally tweak the test code to be able to reuse module builds, allow specifying the build ID of the module build to be reused in test.env.yaml . Signed-off-by: Hunor Csomortáni --- tests/integration/README.rst | 9 +++++++-- tests/integration/example.test.env.yaml | 4 ++++ tests/integration/test_failed_build.py | 8 +++++++- tests/integration/test_scratch_build.py | 8 +++++++- tests/integration/utils.py | 17 ++++++++++++----- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/tests/integration/README.rst b/tests/integration/README.rst index 921cf4be..ceffd64a 100644 --- a/tests/integration/README.rst +++ b/tests/integration/README.rst @@ -11,8 +11,13 @@ The tests should be configured by a ``test.env.yaml`` file placed in the top-level directory of this repository. This can be changed to a different path by setting ``MBS_TEST_CONFIG``. -See `tests/integration/example.test.env.yaml`_ for the list of configuration -options and examples. +Usually each test will trigger a new module build, and potentially wait until +it completes before doing the checks. In order to avoid waiting for this +during test development, an existing module build can be reused by specifying +a ``build_id`` for the test case. + +See `tests/integration/example.test.env.yaml`_ for a complete list of +configuration options and examples. Running the tests ================= diff --git a/tests/integration/example.test.env.yaml b/tests/integration/example.test.env.yaml index 3f5c385e..38d53a49 100644 --- a/tests/integration/example.test.env.yaml +++ b/tests/integration/example.test.env.yaml @@ -13,6 +13,10 @@ koji: # For example test_scratch_build will use scratch_build. testdata: scratch_build: + # MBS build id to be reused for this test. + # When specified no new build is started for this test, + # but the existing one reused. + build_id: 1234 # Name of the module. module: testmodule # Branch which is going to be built for this test. diff --git a/tests/integration/test_failed_build.py b/tests/integration/test_failed_build.py index 61a6fa19..a9c41f75 100644 --- a/tests/integration/test_failed_build.py +++ b/tests/integration/test_failed_build.py @@ -14,7 +14,13 @@ def test_failed_build(test_env, repo, koji): cancelled, if not completed. """ build = utils.Build(test_env["packaging_utility"], test_env["mbs_api"]) - build.run("--watch", "--scratch", "--optional", "rebuild_strategy=all") + build.run( + "--watch", + "--scratch", + "--optional", + "rebuild_strategy=all", + reuse=test_env["testdata"]["failed_build"].get("build_id"), + ) assert build.state_name == "failed" batch = test_env["testdata"]["failed_build"]["batch"] diff --git a/tests/integration/test_scratch_build.py b/tests/integration/test_scratch_build.py index addc0ac0..b53d56ef 100644 --- a/tests/integration/test_scratch_build.py +++ b/tests/integration/test_scratch_build.py @@ -15,7 +15,13 @@ def test_scratch_build(test_env, repo, koji): * no content generator builds are created in Koji """ build = utils.Build(test_env["packaging_utility"], test_env["mbs_api"]) - build.run("--watch", "--scratch", "--optional", "rebuild_strategy=all") + build.run( + "--watch", + "--scratch", + "--optional", + "rebuild_strategy=all", + reuse=test_env["testdata"]["scratch_build"].get("build_id"), + ) assert build.state_name == "done" assert sorted(build.components(state="COMPLETE")) == sorted( diff --git a/tests/integration/utils.py b/tests/integration/utils.py index efaaa27d..14fe3415 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -85,15 +85,22 @@ class Build: self._component_data = None self._build_id = None - def run(self, *args): + def run(self, *args, reuse=None): """Run a module build :param args: Options and arguments for the build command - :return: MBS API URL for the build created - :rtype: string + :param int reuse: Optional MBS build id to be reused for this run. + When specified, the corresponding module build will be used, + instead of triggering and waiting for a new one to finish. + Intended to be used while developing the tests. + :return: MBS build id of the build created + :rtype: int """ - stdout = self._packaging_utility("module-build", *args).stdout.decode("utf-8") - self._build_id = re.search(self._mbs_api + r"module-builds/(\d+)", stdout).group(1) + if reuse is not None: + self._build_id = int(reuse) + else: + stdout = self._packaging_utility("module-build", *args).stdout.decode("utf-8") + self._build_id = int(re.search(self._mbs_api + r"module-builds/(\d+)", stdout).group(1)) return self._build_id @property