Comment 2 for bug 1779071

Revision history for this message
Istvan Imre (istvan.imre) wrote :

Generally it is hard to reproduce in live system, due to it caused by some race condition.

But I'm able to reproduce similar issue in unit test with very small workflows: (It is not too clean, but I had not better idea to reproduce the symptom)

mistral.tests.unit.engine.test_set_state.TestSetState: (slightly copy of previous test in same test class)

    def test_cancel_set_state(self):
        wf1_text = """
        version: '2.0'
        wf1:
          tasks:
            task1:
              workflow: wf2
        """

        wf2_text = """
        version: '2.0'
        wf2:
          tasks:
            task1:
              action: std.noop
              wait-before: 5
        """

        wf_service.create_workflows(wf1_text)
        wf_service.create_workflows(wf2_text)

        wf_ex = self.engine.start_workflow('wf1')

        def wait_for_subworkflow_start():
            try:
                with db_api.transaction():
                    db_api.get_workflow_execution(wf_ex.id).task_executions[0].executions[0]
                    return True
            except Exception:
                return False

        self._await(
            predicate=wait_for_subworkflow_start,
            delay=0.1,
            timeout=20,
            fail_message="Sub workflow not started in time."
        )
        with db_api.transaction():
             sub_wf_ex = db_api.get_workflow_execution(wf_ex.id).task_executions[0].executions[0]

        self.await_workflow_success(wf_ex.id)

        # The state in db is SUCCESS, but wf_ex still contains outdated info.
        self.assertEqual(states.RUNNING, sub_wf_ex.state)

        wf = workflows.Workflow(sub_wf_ex)

        # Trying to change the status of succeed execution. There is no error,
        # only warning message that state has been changed in db.
        wf.stop(states.CANCELLED)

        with db_api.transaction():
            wf_ex = db_api.get_workflow_execution(sub_wf_ex.id)

        self.assertEqual(states.SUCCESS, wf_ex.state)