예제 #1
0
 def test_simple_session(self):
     """
     verify that _restore_SessionState_jobs_and_results() works when
     faced with a representation of a simple session (no generated jobs
     or anything "exotic").
     """
     job = make_job(name='job')
     session_repr = {
         'jobs': {
             job.name: job.get_checksum(),
         },
         'results': {
             job.name: [{
                 'outcome': 'pass',
                 'comments': None,
                 'execution_duration': None,
                 'return_code': None,
                 'io_log': [],
             }]
         }
     }
     helper = SessionResumeHelper([job])
     session = SessionState([job])
     helper._restore_SessionState_jobs_and_results(session, session_repr)
     # Session still has one job in it
     self.assertEqual(session.job_list, [job])
     # Resources don't have anything (no resource jobs)
     self.assertEqual(session.resource_map, {})
     # The result was restored correctly. This is just a smoke test
     # as specific tests for restoring results are written elsewhere
     self.assertEqual(
         session.job_state_map[job.name].result.outcome, 'pass')
예제 #2
0
 def test_empty_session(self):
     """
     verify that _restore_SessionState_jobs_and_results() works when
     faced with a representation of an empty session. This is mostly
     to do sanity checking on the 'easy' parts of the code before
     testing specific cases in the rest of the code.
     """
     session_repr = {
         'jobs': {},
         'results': {}
     }
     helper = SessionResumeHelper([])
     session = SessionState([])
     helper._restore_SessionState_jobs_and_results(session, session_repr)
     self.assertEqual(session.job_list, [])
     self.assertEqual(session.resource_map, {})
     self.assertEqual(session.job_state_map, {})
예제 #3
0
 def test_session_with_generated_jobs(self):
     """
     verify that _restore_SessionState_jobs_and_results() works when
     faced with a representation of a non-trivial session where one
     job generates another one.
     """
     parent = make_job(name='parent', plugin='local')
     # The child job is only here so that we can get the checksum.
     # We don't actually introduce it into the resume machinery
     # caveat: make_job() has a default value for
     # plugin='dummy' which we don't want here
     child = make_job(name='child', plugin=None)
     session_repr = {
         'jobs': {
             parent.name: parent.get_checksum(),
             child.name: child.get_checksum(),
         },
         'results': {
             parent.name: [{
                 'outcome': 'pass',
                 'comments': None,
                 'execution_duration': None,
                 'return_code': None,
                 'io_log': [
                     # This record will generate a job identical
                     # to the 'child' job defined above.
                     [0.0, 'stdout', base64.standard_b64encode(
                         b'name: child\n'
                     ).decode('ASCII')]
                 ],
             }],
             child.name: [],
         }
     }
     # We only pass the parent to the helper! Child will be re-created
     helper = SessionResumeHelper([parent])
     session = SessionState([parent])
     helper._restore_SessionState_jobs_and_results(session, session_repr)
     # We should now have two jobs, parent and child
     self.assertEqual(session.job_list, [parent, child])
     # Resources don't have anything (no resource jobs)
     self.assertEqual(session.resource_map, {})
예제 #4
0
 def test_unknown_jobs_get_reported(self):
     """
     verify that _restore_SessionState_jobs_and_results() reports
     all unresolved jobs (as CorruptedSessionError exception)
     """
     session_repr = {
         'jobs': {
             'job-name': 'job-checksum',
         },
         'results': {
             'job-name': []
         }
     }
     helper = SessionResumeHelper([])
     session = SessionState([])
     with self.assertRaises(CorruptedSessionError) as boom:
         helper._restore_SessionState_jobs_and_results(
             session, session_repr)
     self.assertEqual(
         str(boom.exception), "Unknown jobs remaining: job-name")
예제 #5
0
    def test_session_with_generated_jobs2(self):
        """
        verify that _restore_SessionState_jobs_and_results() works when
        faced with a representation of a non-trivial session where one
        job generates another one and that one generates one more.
        """
        # XXX: Important information about this test.
        # This test uses a very subtle ordering of jobs to achieve
        # the desired testing effect. This does not belong in this test case
        # and should be split into a dedicated, very well documented method
        # The only information I'll leave here now is that
        # _restore_SessionState_jobs_and_results() is processing jobs
        # in alphabetical order. This coupled with ordering:
        # a_grandparent (generated)
        # b_child (generated)
        # c_parent
        # creates the most pathological case possible.
        parent = make_job(name='c_parent', plugin='local')
        # The child job is only here so that we can get the checksum.
        # We don't actually introduce it into the resume machinery
        child = make_job(name='b_child', plugin='local')
        # caveat: make_job() has a default value for
        # plugin='dummy' which we don't want here
        grandchild = make_job(name='a_grandchild', plugin=None)
        session_repr = {
            'jobs': {
                parent.name: parent.get_checksum(),
                child.name: child.get_checksum(),
                grandchild.name: grandchild.get_checksum(),
            },
            'results': {
                parent.name: [{
                    'outcome': 'pass',
                    'comments': None,
                    'execution_duration': None,
                    'return_code': None,
                    'io_log': [
                        # This record will generate a job identical
                        # to the 'child' job defined above.
                        [0.0, 'stdout', base64.standard_b64encode(
                            b'name: b_child\n'
                        ).decode('ASCII')],
                        [0.1, 'stdout', base64.standard_b64encode(
                            b'plugin: local\n'
                        ).decode('ASCII')]

                    ],
                }],
                child.name: [{
                    'outcome': 'pass',
                    'comments': None,
                    'execution_duration': None,
                    'return_code': None,
                    'io_log': [
                        # This record will generate a job identical
                        # to the 'child' job defined above.
                        [0.0, 'stdout', base64.standard_b64encode(
                            b'name: a_grandchild\n'
                        ).decode('ASCII')]
                    ],
                }],
                grandchild.name: [],
            }
        }
        # We only pass the parent to the helper!
        # The 'child' and 'grandchild' jobs will be re-created
        helper = SessionResumeHelper([parent])
        session = SessionState([parent])
        helper._restore_SessionState_jobs_and_results(session, session_repr)
        # We should now have two jobs, parent and child
        self.assertEqual(session.job_list, [parent, child, grandchild])
        # Resources don't have anything (no resource jobs)
        self.assertEqual(session.resource_map, {})