def testGetRerunInfo_remote(self): test = ndb_models.Test(context_file_dir='context/') # determine rerun info using parent ID prev_run_key, prev_test_context = test_kicker._GetRerunInfo( test, messages.RerunContext(context_filename='file', context_file_url='file_url')) # no test run key and test context contains provided file expected_context = ndb_models.TestContextObj(test_resources=[ ndb_models.TestResourceObj( name='context/file', url='file_url')]) self.assertIsNone(prev_run_key) self.assertEqual(expected_context, prev_test_context)
def testGetRerunInfo_local(self): # create local test run to rerun prev_test_run = self._CreateMockTestRun() prev_test_run.next_test_context = ndb_models.TestContextObj( test_resources=[ndb_models.TestResourceObj(name='bar', url='zzz')]) prev_test_run.put() # determine rerun info using parent ID prev_run_key, prev_test_context = test_kicker._GetRerunInfo( None, messages.RerunContext(test_run_id=prev_test_run.key.id())) # test run key found and next_test_context used self.assertEqual(prev_test_run.key, prev_run_key) self.assertEqual(prev_test_run.next_test_context, prev_test_context)
def testScheduleNextTestRun(self, mock_create_test_run): test = self._CreateMockTest() config1 = self._CreateMockTestRunConfig(test, 'rt1') config2 = self._CreateMockTestRunConfig(test, 'rt2;rt3') run1 = self._CreateMockTestRun(config1) sequence = self._CreateMockTestRunSequence('sequence_id', [config1, config2]) sequence_id = sequence.key.id() run1_id = str(run1.key.id()) config2.prev_test_run_key = run1.key rerun_context = mtt_messages.RerunContext() rerun_context.test_run_id = run1_id # Schedules next run successfully test_scheduler.ScheduleNextTestRun(sequence_id, run1.key) mock_create_test_run.assert_called_with(labels=['label'], test_run_config=config2, rerun_context=rerun_context, rerun_configs=[], sequence_id=sequence_id) updated_sequence = sequence.key.get() self.assertEqual(updated_sequence.finished_test_run_ids, [run1_id]) self.assertEqual(updated_sequence.state, ndb_models.TestRunSequenceState.RUNNING) # Ignores a call with a duplicate previous run id test_scheduler.ScheduleNextTestRun(sequence_id, run1.key) mock_create_test_run.assert_called_once() # Only called the first time updated_sequence = sequence.key.get() self.assertEqual(updated_sequence.finished_test_run_ids, [run1_id]) self.assertEqual(updated_sequence.state, ndb_models.TestRunSequenceState.RUNNING) # Does not schedule another run when no more configs left run2 = self._CreateMockTestRun(config2) run2_id = str(run2.key.id()) test_scheduler.ScheduleNextTestRun(sequence_id, run2.key) mock_create_test_run.assert_called_once() # Only called the first time updated_sequence2 = sequence.key.get() self.assertEqual(updated_sequence2.finished_test_run_ids, [run1_id, run2_id]) self.assertEqual(updated_sequence2.state, ndb_models.TestRunSequenceState.COMPLETED)
def ScheduleNextTestRun(sequence_id, previous_test_run_key): """Schedules the next run in sequence.""" previous_test_run = previous_test_run_key.get() next_run_config = _GetNextTestRunConfig(sequence_id, previous_test_run) if not next_run_config: return next_run_config.prev_test_run_key = previous_test_run_key rerun_context = mtt_messages.RerunContext() rerun_context.test_run_id = previous_test_run_key.id() logging.info('Scheduling rerun for sequence %s', sequence_id) test_kicker.CreateTestRun( # TODO: Move labels to TestRunConfig labels=previous_test_run.labels, test_run_config=next_run_config, rerun_context=rerun_context, rerun_configs=[], sequence_id=sequence_id)
def testGetRerunInfo_empty(self): # no rerun info without context self.assertEqual((None, None), test_kicker._GetRerunInfo(None, None)) # no rerun info for empty context self.assertEqual((None, None), test_kicker._GetRerunInfo(None, messages.RerunContext()))