1
0
Эх сурвалжийг харах

fix: JobConfigChecker should check the execution mode

trgiangdo 1 жил өмнө
parent
commit
1ba4371007

+ 9 - 0
taipy/core/config/checkers/_job_config_checker.py

@@ -30,6 +30,7 @@ class _JobConfigChecker(_ConfigChecker):
                 cast(JobConfig, job_config),
                 cast(Dict[str, DataNodeConfig], data_node_configs),
             )
+            self._check_job_execution_mode(cast(JobConfig, job_config))
         return self._collector
 
     def _check_multiprocess_mode(self, job_config: JobConfig, data_node_configs: Dict[str, DataNodeConfig]):
@@ -42,3 +43,11 @@ class _JobConfigChecker(_ConfigChecker):
                         f"DataNode `{cfg_id}`: In-memory storage type can ONLY be used in "
                         f"{JobConfig._DEVELOPMENT_MODE} mode.",
                     )
+
+    def _check_job_execution_mode(self, job_config: JobConfig):
+        if job_config.mode not in JobConfig._MODES:
+            self._error(
+                job_config._MODE_KEY,
+                job_config.mode,
+                f"`Job execution mode must be either {', '.join(JobConfig._MODES)}.",
+            )

+ 1 - 4
tests/core/_orchestrator/test_orchestrator_factory.py

@@ -105,10 +105,7 @@ def test_rebuild_standalone_dispatcher_and_force_restart():
 
 
 def test_build_unknown_dispatcher():
-    with pytest.raises(ModeNotAvailable):
-        Config.configure_job_executions(mode="UNKNOWN")
-
-    Config.job_config.mode = "UNKNOWN"
+    Config.configure_job_executions(mode="UNKNOWN")
     _OrchestratorFactory._build_orchestrator()
     with pytest.raises(ModeNotAvailable):
         _OrchestratorFactory._build_dispatcher()

+ 23 - 0
tests/core/config/checkers/test_job_config_checker.py

@@ -17,6 +17,29 @@ from taipy.core.config.job_config import JobConfig
 
 
 class TestJobConfigChecker:
+    def test_check_mode(self, caplog):
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        Config.configure_job_executions(mode=JobConfig._DEVELOPMENT_MODE)
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        Config.configure_job_executions(mode=JobConfig._STANDALONE_MODE, max_nb_of_workers=2)
+        Config._collector = IssueCollector()
+        Config.check()
+        assert len(Config._collector.errors) == 0
+
+        Config.configure_job_executions(mode="foo", max_nb_of_workers=2)
+        with pytest.raises(SystemExit):
+            Config._collector = IssueCollector()
+            Config.check()
+        assert len(Config._collector.errors) == 1
+        expected_error_message = "Job execution mode must be either development, standalone."
+        assert expected_error_message in caplog.text
+
     def test_check_standalone_mode(self, caplog):
         Config._collector = IssueCollector()
         Config.check()