Example #1
0
    def test_job_retry_status(self):
        job_spec = JobSpec()
        job_spec.augmentations = {}
        job_spec.finalize()

        self.job = Job_force_retry(2, job_spec, 1, self.context)
        self.job.workload = Mock()

        self.context.cm._joblist = [self.job]
        self.context.run_state.add_job(self.job)

        runner = Runner(self.context, MockProcessorManager())
        runner.run()
Example #2
0
class TestRunState(TestCase):

    def setUp(self):
        self.path = tempfile.mkstemp()[1]
        os.remove(self.path)
        self.initialise_signals()

        config = MockConfigManager()
        output = init_run_output(self.path, config)

        self.context = ExecutionContext(config, Mock(), output)

        self.job_spec = JobSpec()
        self.job_spec.augmentations = {}
        self.job_spec.finalize()

    def tearDown(self):
        signal.disconnect(self._verify_serialized_state, signal.RUN_INITIALIZED)
        signal.disconnect(self._verify_serialized_state, signal.JOB_STARTED)
        signal.disconnect(self._verify_serialized_state, signal.JOB_RESTARTED)
        signal.disconnect(self._verify_serialized_state, signal.JOB_COMPLETED)
        signal.disconnect(self._verify_serialized_state, signal.JOB_FAILED)
        signal.disconnect(self._verify_serialized_state, signal.JOB_ABORTED)
        signal.disconnect(self._verify_serialized_state, signal.RUN_FINALIZED)

    def test_job_state_transitions_pass(self):
        '''Tests state equality when the job passes first try'''
        job = Job(self.job_spec, 1, self.context)
        job.workload = Mock()

        self.context.cm._joblist = [job]
        self.context.run_state.add_job(job)

        runner = Runner(self.context, MockProcessorManager())
        runner.run()

    def test_job_state_transitions_fail(self):
        '''Tests state equality when job fails completely'''
        job = Job_force_retry(3, self.job_spec, 1, self.context)
        job.workload = Mock()

        self.context.cm._joblist = [job]
        self.context.run_state.add_job(job)

        runner = Runner(self.context, MockProcessorManager())
        runner.run()

    def test_job_state_transitions_retry(self):
        '''Tests state equality when job fails initially'''
        job = Job_force_retry(1, self.job_spec, 1, self.context)
        job.workload = Mock()

        self.context.cm._joblist = [job]
        self.context.run_state.add_job(job)

        runner = Runner(self.context, MockProcessorManager())
        runner.run()

    def initialise_signals(self):
        signal.connect(self._verify_serialized_state, signal.RUN_INITIALIZED)
        signal.connect(self._verify_serialized_state, signal.JOB_STARTED)
        signal.connect(self._verify_serialized_state, signal.JOB_RESTARTED)
        signal.connect(self._verify_serialized_state, signal.JOB_COMPLETED)
        signal.connect(self._verify_serialized_state, signal.JOB_FAILED)
        signal.connect(self._verify_serialized_state, signal.JOB_ABORTED)
        signal.connect(self._verify_serialized_state, signal.RUN_FINALIZED)

    def _verify_serialized_state(self, _):
        fs_state = RunOutput(self.path).state
        ex_state = self.context.run_output.state

        assert_equal(fs_state.status, ex_state.status)
        fs_js_zip = zip(
            [value for key, value in fs_state.jobs.items()],
            [value for key, value in ex_state.jobs.items()]
        )
        for fs_jobstate, ex_jobstate in fs_js_zip:
            assert_equal(fs_jobstate.iteration, ex_jobstate.iteration)
            assert_equal(fs_jobstate.retries, ex_jobstate.retries)
            assert_equal(fs_jobstate.status, ex_jobstate.status)
def get_jobspec():
    job_spec = JobSpec()
    job_spec.augmentations = {}
    job_spec.finalize()
    return job_spec