From fcd662468ffbde17637ae55458dc18bea03f8b8d Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Jun 15 2021 19:05:06 +0000 Subject: fix unit tests --- diff --git a/tests/__init__.py b/tests/__init__.py index ca188fa..c995d6b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -409,7 +409,7 @@ def _populate_data(data_size=10, contexts=False, scratch=False): db_session.commit() -def scheduler_init_data(tangerine_state=None, scratch=False): +def scheduler_init_data(tangerine_state=None, scratch=False, module_state="build"): """ Creates a testmodule in the building state with all the components in the same batch """ clean_database() @@ -421,7 +421,7 @@ def scheduler_init_data(tangerine_state=None, scratch=False): name="testmodule", stream="master", version='20170109091357', - state=BUILD_STATES["build"], + state=BUILD_STATES[module_state], scratch=scratch, build_context="ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0", runtime_context="ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0", diff --git a/tests/test_build/test_build.py b/tests/test_build/test_build.py index 809e3e0..104c49d 100644 --- a/tests/test_build/test_build.py +++ b/tests/test_build/test_build.py @@ -1152,16 +1152,24 @@ class TestBuild(BaseTestBuild): from module_build_service.scheduler.db_session import db_session + # module should be in wait state for this test + module_build = models.ModuleBuild.get_by_id(db_session, 3) + module_build.state = models.BUILD_STATES["wait"] + db_session.commit() + # Create a dedicated database session for scheduler to avoid hang self.run_scheduler( msgs=[{ "msg_id": "local module build", "event": events.MBS_MODULE_STATE_CHANGE, - "module_build_id": 3, - "module_build_state": 1 + "module_build_id": module_build.id, + "module_build_state": module_build.state, }] ) + # commit so that our assertions see the updates + db_session.commit() + reused_component_ids = { "module-build-macros": None, "tangerine": 3, @@ -1239,6 +1247,11 @@ class TestBuild(BaseTestBuild): FakeModuleBuilder.on_buildroot_add_artifacts_cb = on_buildroot_add_artifacts_cb + # module should be in wait state for this test + module_build = models.ModuleBuild.get_by_id(db_session, 3) + module_build.state = models.BUILD_STATES["wait"] + db_session.commit() + self.run_scheduler( msgs=[{ "msg_id": "local module build", @@ -1248,6 +1261,9 @@ class TestBuild(BaseTestBuild): }] ) + # commit so that our assertions see the updates + db_session.commit() + # All components should be built and module itself should be in "done" # or "ready" state. for build in models.ModuleBuild.get_by_id(db_session, 3).component_builds: diff --git a/tests/test_scheduler/test_module_wait.py b/tests/test_scheduler/test_module_wait.py index 4a31d71..7257c7b 100644 --- a/tests/test_scheduler/test_module_wait.py +++ b/tests/test_scheduler/test_module_wait.py @@ -21,7 +21,7 @@ base_dir = os.path.dirname(os.path.dirname(__file__)) class TestModuleWait: def setup_method(self, test_method): - scheduler_init_data() + scheduler_init_data(module_state="wait") self.config = conf self.session = mock.Mock()