Beispiel #1
0
    def test_successful_job_lifecycle(self):
        def test_status_running_and_succeed(*args):
            self.assertEquals("running", self._calculation_status())

            return []

        def patch_job_launch(*args, **kwargs):
            self.job = self.job_from_file(*args, **kwargs)

            self.assertEquals("pending", self._calculation_status())

            return self.job

        before_launch = engine._launch_calculation
        try:
            engine._launch_calculation = mock.Mock(side_effect=test_status_running_and_succeed)

            with patch("openquake.engine._job_from_file") as from_file:
                from_file.side_effect = patch_job_launch

                with patch("os.fork", mocksignature=False) as fork:
                    fork.return_value = 0
                    engine.run_calculation(self.calc_proxy, self.params, self.sections)

            self.assertEquals(1, engine._launch_calculation.call_count)
            self.assertEquals("succeeded", self._calculation_status())
        finally:
            engine._launch_calculation = before_launch
Beispiel #2
0
    def test_run_calculation_deletes_job_counters(self):
        """This test ensures that
        :function:`openquake.utils.stats.delete_job_counters` is called"""
        cfg_path = demo_file('HazardMapTest/config.gem')

        job_profile, params, sections = engine.import_job_profile(cfg_path)

        # We don't want any of the supervisor/executor forking to happen; it's
        # not necessary. Also, forking should not happen in the context of a
        # test run.
        with patch('os.fork', mocksignature=False) as fork_mock:
            # Fake return val for fork:
            fork_mock.return_value = 0
            # And we don't actually want to run the calculation.
            with patch('openquake.engine._launch_calculation'):
                with patch(
                    'openquake.utils.stats.delete_job_counters') as djc_mock:
                    engine.run_calculation(job_profile, params, sections)

                    self.assertEquals(1, djc_mock.call_count)
Beispiel #3
0
    def test_supervisor_is_spawned(self):
        with patch("openquake.engine._job_from_file"):

            before_launch = engine._launch_calculation
            try:
                engine._launch_calculation = mock.Mock()
                with patch("os.fork", mocksignature=False) as fork:

                    def fork_side_effect():
                        fork.side_effect = lambda: 0
                        return 1234

                    fork.side_effect = fork_side_effect
                    superv_func = "openquake.supervising.supervisor.supervise"
                    with patch(superv_func) as supervise:
                        engine.run_calculation(self.calc_proxy, self.params, self.sections)
                        calculation = OqCalculation.objects.latest(field_name="last_update")

                        self.assertEquals(1, supervise.call_count)
                        self.assertEquals(((1234, calculation.id), {}), supervise.call_args)
            finally:
                engine._launch_calculation = before_launch