class ReplayDeciderDestroyTest(TestCase): def setUp(self) -> None: self.workflow_task = Mock() self.decider = ReplayDecider(execution_id="", workflow_type=Mock(), worker=Mock()) self.decider.workflow_task = self.workflow_task def test_destroy(self): self.decider.destroy() self.workflow_task.destroy.assert_called()
class TestReplayDecider(TestCase): def setUp(self) -> None: worker: Worker = Mock() worker.get_workflow_method = MagicMock( return_value=(DummyWorkflow, lambda *args: None)) self.decider = ReplayDecider(execution_id="", workflow_type=Mock(), worker=worker) def test_get_and_increment_next_id(self): self.assertEqual("0", self.decider.get_and_increment_next_id()) self.assertEqual("1", self.decider.get_and_increment_next_id()) def test_get_decisions(self): decision = Decision() state_machine: DecisionStateMachine = Mock() state_machine.get_decision = MagicMock(return_value=decision) self.decider.decisions[DecisionId(DecisionTarget.ACTIVITY, 10)] = state_machine decisions = self.decider.get_decisions() self.assertEqual(1, len(decisions)) self.assertIs(decision, decisions[0]) def test_get_decisions_none(self): state_machine: DecisionStateMachine = Mock() state_machine.get_decision = MagicMock(return_value=None) self.decider.decisions[DecisionId(DecisionTarget.ACTIVITY, 10)] = state_machine decisions = self.decider.get_decisions() self.assertEqual(0, len(decisions)) def test_get_decision(self): state_machine = DecisionStateMachine() decision_id = DecisionId(DecisionTarget.ACTIVITY, 20) self.decider.decisions[decision_id] = state_machine self.assertIs(state_machine, self.decider.get_decision(decision_id)) def test_get_decision_not_found(self): decision_id = DecisionId(DecisionTarget.ACTIVITY, 20) with self.assertRaises(NonDeterministicWorkflowException): self.decider.get_decision(decision_id) def test_notify_decision_sent(self): state_machine: DecisionStateMachine = Mock() self.decider.decisions[DecisionId(DecisionTarget.ACTIVITY, 10)] = state_machine self.decider.notify_decision_sent() state_machine.handle_decision_task_started_event.assert_called_once() def test_process_decision_events_notifies_when_replay(self): self.decider.event_loop = Mock() events = [ HistoryEvent(event_type=EventType.WorkflowExecutionStarted, workflow_execution_started_event_attributes= WorkflowExecutionStartedEventAttributes()), HistoryEvent(event_type=EventType.DecisionTaskScheduled) ] decision_events = DecisionEvents(events, [], replay=True, replay_current_time_milliseconds=0, next_decision_event_id=5) self.decider.notify_decision_sent = MagicMock() self.decider.process_decision_events(decision_events) self.decider.notify_decision_sent.assert_called_once() def test_activity_task_closed(self): state_machine: DecisionStateMachine = Mock() state_machine.is_done = MagicMock(return_value=True) self.decider.decisions[DecisionId(DecisionTarget.ACTIVITY, 10)] = state_machine ret = self.decider.handle_activity_task_closed(10) self.assertTrue(ret) state_machine.handle_completion_event.assert_called_once() state_machine.is_done.assert_called_once() def test_handle_activity_task_scheduled(self): state_machine: DecisionStateMachine = Mock() self.decider.decisions[DecisionId(DecisionTarget.ACTIVITY, 10)] = state_machine event = HistoryEvent(event_id=10) self.decider.handle_activity_task_scheduled(event) state_machine.handle_initiated_event.assert_called() args, kwargs = state_machine.handle_initiated_event.call_args_list[0] self.assertIn(event, args) def test_handle_activity_task_started(self): state_machine: DecisionStateMachine = Mock() self.decider.decisions[DecisionId(DecisionTarget.ACTIVITY, 10)] = state_machine event = HistoryEvent(event_id=15) event.activity_task_started_event_attributes = ActivityTaskStartedEventAttributes( ) event.activity_task_started_event_attributes.scheduled_event_id = 10 self.decider.handle_activity_task_started(event) state_machine.handle_started_event.assert_called() args, kwargs = state_machine.handle_started_event.call_args_list[0] self.assertIn(event, args) def tearDown(self) -> None: self.decider.destroy()