From 1e5ed864c9d3a298b89a1b859e8a7aaf21d1822e Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Mar 03 2020 19:48:47 +0000 Subject: Avoid to handle a late init message Signed-off-by: Chenxiong Qi --- diff --git a/module_build_service/scheduler/handlers/modules.py b/module_build_service/scheduler/handlers/modules.py index 72bf4da..35e44db 100644 --- a/module_build_service/scheduler/handlers/modules.py +++ b/module_build_service/scheduler/handlers/modules.py @@ -153,6 +153,16 @@ def init(msg_id, module_build_id, module_build_state): """ build = models.ModuleBuild.get_by_id(db_session, module_build_id) + state_init = models.BUILD_STATES["init"] + if module_build_state == state_init and build.state != state_init: + log.warning( + "Module build %r has moved to %s state already.", + build, models.INVERSE_BUILD_STATES[build.state]) + log.warning( + "Ignore this message %s. Is there something wrong with the frontend" + " that sends duplicate messages?", msg_id) + return + # for MockModuleBuilder, set build logs dir to mock results dir # before build_logs start if conf.system == "mock": diff --git a/tests/test_scheduler/test_module_init.py b/tests/test_scheduler/test_module_init.py index 3c1238f..6abb23b 100644 --- a/tests/test_scheduler/test_module_init.py +++ b/tests/test_scheduler/test_module_init.py @@ -6,7 +6,7 @@ import os from mock import patch, PropertyMock from module_build_service import build_logs, conf -from module_build_service.common.models import ModuleBuild +from module_build_service.common.models import BUILD_STATES, ModuleBuild from module_build_service.common.utils import load_mmd, mmd_to_str from module_build_service.scheduler.db_session import db_session import module_build_service.scheduler.handlers.modules @@ -180,3 +180,13 @@ class TestModuleInit: # Make sure the module entered the failed state assert build.state == 4, build.state assert "Failed to get the latest commit for" in build.state_reason + + def test_do_not_handle_a_duplicate_late_init_message(self): + build = db_session.query(ModuleBuild).filter( + ModuleBuild.name == "testmodule").one() + build.state = BUILD_STATES["wait"] + db_session.commit() + + with patch.object(module_build_service.scheduler.handlers.modules, "log") as log: + self.fn("msg-id-123", build.id, BUILD_STATES["init"]) + assert 2 == log.warning.call_count