| |
@@ -1059,6 +1059,198 @@
|
| |
@pytest.mark.usefixtures("reuse_component_init_data")
|
| |
@patch("module_build_service.auth.get_user", return_value=user)
|
| |
@patch("module_build_service.scm.SCM")
|
| |
+ def test_submit_build_run_new_repo_once(
|
| |
+ self, mocked_scm, mocked_get_user, conf_system, dbg, hmsc, db_session
|
| |
+ ):
|
| |
+ """
|
| |
+ Tests how many times the newRepo is run with change-and-after strategy when we
|
| |
+ have to rebuild only the 3rd batch and reuse the second
|
| |
+ """
|
| |
+
|
| |
+ # make the component in the last batch un-reusable
|
| |
+ db_session.query(models.ComponentBuild).filter_by(
|
| |
+ id=7).update({"ref": "1fbed359411a1baa08d4a88e0d12d426fbf8f602c"})
|
| |
+ db_session.commit()
|
| |
+
|
| |
+ # need to fake a running build task for the module
|
| |
+ def on_get_task_info_cb(cls, task_id):
|
| |
+ # new repo task_id
|
| |
+ if int(task_id) == 123:
|
| |
+ return {"state": koji.TASK_STATES["FREE"]}
|
| |
+ else:
|
| |
+ return {"state": koji.TASK_STATES["CLOSED"]}
|
| |
+
|
| |
+ FakeModuleBuilder.on_get_task_info_cb = on_get_task_info_cb
|
| |
+
|
| |
+ # we need to fake the message on _sent_repo_done, so we can measure how
|
| |
+ # many times was newRepo called
|
| |
+ mock_koji_repo_change = Mock()
|
| |
+ mock_msg = module_build_service.messaging.KojiRepoChange(
|
| |
+ msg_id="a faked internal message",
|
| |
+ repo_tag="module-testmodule-master-20170219191323-c40c156c-build")
|
| |
+
|
| |
+ mock_koji_repo_change.return_value = mock_msg
|
| |
+
|
| |
+ @patch("module_build_service.messaging.KojiRepoChange", mock_koji_repo_change)
|
| |
+ def _send_repo_done(self):
|
| |
+ msg = module_build_service.messaging.KojiRepoChange(
|
| |
+ msg_id="a faked internal message", repo_tag=self.tag_name + "-build")
|
| |
+ module_build_service.scheduler.consumer.work_queue_put(msg)
|
| |
+
|
| |
+ FakeModuleBuilder._send_repo_done = _send_repo_done
|
| |
+
|
| |
+ with models.make_db_session(conf) as scheduler_db_session:
|
| |
+ self.run_scheduler(scheduler_db_session, msgs=[MBSModule("local module build", 3, 1)])
|
| |
+
|
| |
+ reused_component_ids = {
|
| |
+ "module-build-macros": None,
|
| |
+ "perl-Tangerine": 1,
|
| |
+ "perl-List-Compare": 2,
|
| |
+ }
|
| |
+
|
| |
+ assert mock_koji_repo_change.call_count == 1
|
| |
+
|
| |
+ for build in models.ModuleBuild.get_by_id(db_session, 3).component_builds:
|
| |
+ assert build.state == koji.BUILD_STATES["COMPLETE"]
|
| |
+ assert build.module_build.state in [
|
| |
+ models.BUILD_STATES["done"],
|
| |
+ models.BUILD_STATES["ready"],
|
| |
+ ]
|
| |
+ if build.package in ["tangerine", "module-build-macros"]:
|
| |
+ assert not build.reused_component_id
|
| |
+ else:
|
| |
+ assert build.reused_component_id == reused_component_ids[build.package]
|
| |
+
|
| |
+ @pytest.mark.usefixtures("reuse_component_init_data")
|
| |
+ @patch("module_build_service.auth.get_user", return_value=user)
|
| |
+ @patch("module_build_service.scm.SCM")
|
| |
+ def test_submit_build_run_new_repo_three_times(
|
| |
+ self, mocked_scm, mocked_get_user, conf_system, dbg, hmsc, db_session
|
| |
+ ):
|
| |
+ """
|
| |
+ Tests how many times the newRepo is run with change-and-after strategy when we
|
| |
+ have to rebuild one component from the 2nd batch and reuse the 3rd.
|
| |
+ """
|
| |
+ db_session.query(models.ComponentBuild).filter_by(
|
| |
+ id=5).update({"ref": "1fbed359411a1baa08d4a88e0d12d426fbf8f602c"})
|
| |
+ db_session.commit()
|
| |
+
|
| |
+ def on_get_task_info_cb(cls, task_id):
|
| |
+ if cls.module_str.batch == 1:
|
| |
+ return {"state": koji.TASK_STATES["FREE"]}
|
| |
+ elif cls.module_str.batch == 2:
|
| |
+ return {"state": koji.TASK_STATES["CLOSED"]}
|
| |
+ else:
|
| |
+ return {"state": koji.TASK_STATES["FREE"]}
|
| |
+
|
| |
+ FakeModuleBuilder.on_get_task_info_cb = on_get_task_info_cb
|
| |
+
|
| |
+ # we need to fake the message on _sent_repo_done, so we can measure how
|
| |
+ # many times was newRepo called
|
| |
+ mock_koji_repo_change = Mock()
|
| |
+ mock_msg = module_build_service.messaging.KojiRepoChange(
|
| |
+ msg_id="a faked internal message",
|
| |
+ repo_tag="module-testmodule-master-20170219191323-c40c156c-build")
|
| |
+
|
| |
+ mock_koji_repo_change.return_value = mock_msg
|
| |
+
|
| |
+ @patch("module_build_service.messaging.KojiRepoChange", mock_koji_repo_change)
|
| |
+ def _send_repo_done(self):
|
| |
+ msg = module_build_service.messaging.KojiRepoChange(
|
| |
+ msg_id="a faked internal message", repo_tag=self.tag_name + "-build")
|
| |
+ module_build_service.scheduler.consumer.work_queue_put(msg)
|
| |
+
|
| |
+ FakeModuleBuilder._send_repo_done = _send_repo_done
|
| |
+
|
| |
+ with models.make_db_session(conf) as scheduler_db_session:
|
| |
+ self.run_scheduler(scheduler_db_session, msgs=[MBSModule("local module build", 3, 1)])
|
| |
+
|
| |
+ reused_component_ids = {
|
| |
+ "module-build-macros": None,
|
| |
+ "perl-Tangerine": 1,
|
| |
+ "perl-List-Compare": 2,
|
| |
+ "tangerine": 3,
|
| |
+ }
|
| |
+
|
| |
+ assert mock_koji_repo_change.call_count == 3
|
| |
+
|
| |
+ for build in models.ModuleBuild.get_by_id(db_session, 3).component_builds:
|
| |
+ assert build.state == koji.BUILD_STATES["COMPLETE"]
|
| |
+ assert build.module_build.state in [
|
| |
+ models.BUILD_STATES["done"],
|
| |
+ models.BUILD_STATES["ready"],
|
| |
+ ]
|
| |
+ if build.package in ["module-build-macros", "perl-Tangerine", "tangerine"]:
|
| |
+ assert not build.reused_component_id
|
| |
+ else:
|
| |
+ assert build.reused_component_id == reused_component_ids[build.package]
|
| |
+
|
| |
+ @pytest.mark.usefixtures("reuse_component_init_data")
|
| |
+ @patch("module_build_service.auth.get_user", return_value=user)
|
| |
+ @patch("module_build_service.scm.SCM")
|
| |
+ def test_submit_build_run_new_repo_two_times(
|
| |
+ self, mocked_scm, mocked_get_user, conf_system, dbg, hmsc, db_session
|
| |
+ ):
|
| |
+ """
|
| |
+ Tests how many times the newRepo is run with only-changed strategy when we
|
| |
+ have to rebuild one component from the 2nd batch and reuse the 3rd.
|
| |
+ """
|
| |
+ db_session.query(models.ModuleBuild).filter_by(id=3).update(
|
| |
+ {"rebuild_strategy": "only-changed"}
|
| |
+ )
|
| |
+ db_session.query(models.ComponentBuild).filter_by(
|
| |
+ id=5).update({"ref": "1fbed359411a1baa08d4a88e0d12d426fbf8f602c"})
|
| |
+ db_session.commit()
|
| |
+
|
| |
+ def on_get_task_info_cb(cls, task_id):
|
| |
+ if cls.module_str.batch in [1, 2]:
|
| |
+ return {"state": koji.TASK_STATES["FREE"]}
|
| |
+ else:
|
| |
+ return {"state": koji.TASK_STATES["CLOSED"]}
|
| |
+
|
| |
+ FakeModuleBuilder.on_get_task_info_cb = on_get_task_info_cb
|
| |
+
|
| |
+ # we need to fake the message on _sent_repo_done, so we can measure how
|
| |
+ # many times was newRepo called
|
| |
+ mock_koji_repo_change = Mock()
|
| |
+ mock_msg = module_build_service.messaging.KojiRepoChange(
|
| |
+ msg_id="a faked internal message",
|
| |
+ repo_tag="module-testmodule-master-20170219191323-c40c156c-build")
|
| |
+
|
| |
+ mock_koji_repo_change.return_value = mock_msg
|
| |
+
|
| |
+ @patch("module_build_service.messaging.KojiRepoChange", mock_koji_repo_change)
|
| |
+ def _send_repo_done(self):
|
| |
+ msg = module_build_service.messaging.KojiRepoChange(
|
| |
+ msg_id="a faked internal message", repo_tag=self.tag_name + "-build")
|
| |
+ module_build_service.scheduler.consumer.work_queue_put(msg)
|
| |
+
|
| |
+ FakeModuleBuilder._send_repo_done = _send_repo_done
|
| |
+
|
| |
+ with models.make_db_session(conf) as scheduler_db_session:
|
| |
+ self.run_scheduler(scheduler_db_session, msgs=[MBSModule("local module build", 3, 1)])
|
| |
+
|
| |
+ reused_component_ids = {
|
| |
+ "perl-List-Compare": 2,
|
| |
+ "tangerine": 3,
|
| |
+ }
|
| |
+
|
| |
+ assert mock_koji_repo_change.call_count == 1
|
| |
+
|
| |
+ for build in models.ModuleBuild.get_by_id(db_session, 3).component_builds:
|
| |
+ assert build.state == koji.BUILD_STATES["COMPLETE"]
|
| |
+ assert build.module_build.state in [
|
| |
+ models.BUILD_STATES["done"],
|
| |
+ models.BUILD_STATES["ready"],
|
| |
+ ]
|
| |
+ if build.package in ["module-build-macros", "perl-Tangerine"]:
|
| |
+ assert not build.reused_component_id
|
| |
+ else:
|
| |
+ assert build.reused_component_id == reused_component_ids[build.package]
|
| |
+
|
| |
+ @pytest.mark.usefixtures("reuse_component_init_data")
|
| |
+ @patch("module_build_service.auth.get_user", return_value=user)
|
| |
+ @patch("module_build_service.scm.SCM")
|
| |
def test_submit_build_reuse_all_without_build_macros(
|
| |
self, mocked_scm, mocked_get_user, conf_system, dbg, hmsc, db_session
|
| |
):
|
| |
Don't we need to iterate by batch? The bit later on that advances the module.batch to the highest reusable component.batch would have unintended consequences otherwise.