mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-10 22:29:44 +08:00
Tests: allow reusing an existing module build
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 <csomh@redhat.com>
This commit is contained in:
@@ -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
|
||||
=================
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user