diff --git a/pkg/bpmn_engine/jobs.go b/pkg/bpmn_engine/jobs.go index 23791140..e03117be 100644 --- a/pkg/bpmn_engine/jobs.go +++ b/pkg/bpmn_engine/jobs.go @@ -35,7 +35,7 @@ func (j job) Element() *BPMN20.BaseElement { func findOrCreateJob(jobs *[]*job, element *BPMN20.TaskElement, instance *processInstanceInfo, generateKey func() int64) *job { be := (*element).(BPMN20.BaseElement) for _, job := range *jobs { - if job.ElementId == be.GetId() { + if job.ElementId == be.GetId() && job.ProcessInstanceKey == instance.GetInstanceKey() { return job } } diff --git a/pkg/bpmn_engine/jobs_test.go b/pkg/bpmn_engine/jobs_test.go index 770c8acf..12460b38 100644 --- a/pkg/bpmn_engine/jobs_test.go +++ b/pkg/bpmn_engine/jobs_test.go @@ -339,3 +339,44 @@ func Test_missing_task_handlers_break_execution_and_can_be_continued_later(t *te then.AssertThat(t, err, is.Nil()) then.AssertThat(t, cp.CallPath, is.EqualTo("id-a-1,id-b-1,id-b-2")) } + +func Test_multiple_instances_with_same_user_task_ids(t *testing.T) { + // setup + bpmnEngine := New() + process, err := bpmnEngine.LoadFromFile("../../test-cases/user-tasks-with-parallel-gateways.bpmn") + then.AssertThat(t, err, is.Nil()) + + called := map[int64][]string{} + handler := func(taskId string) func(ActivatedJob) { + return func(job ActivatedJob) { + called[job.ProcessInstanceKey()] = append(called[job.ProcessInstanceKey()], taskId) + job.Complete() + } + } + + // given + bpmnEngine.NewTaskHandler().Id("assignee-task1").Handler(handler("assignee-task1")) + bpmnEngine.NewTaskHandler().Id("assignee-task2").Handler(handler("assignee-task2")) + bpmnEngine.NewTaskHandler().Id("assignee-task3").Handler(handler("assignee-task3")) + bpmnEngine.NewTaskHandler().Id("assignee-task4").Handler(handler("assignee-task4")) + + instance1, err1 := bpmnEngine.CreateAndRunInstance(process.ProcessKey, nil) + then.AssertThat(t, err1, is.Nil()) + then.AssertThat(t, instance1, is.Not(is.Nil())) + + instance2, err2 := bpmnEngine.CreateAndRunInstance(process.ProcessKey, nil) + then.AssertThat(t, err2, is.Nil()) + then.AssertThat(t, instance2, is.Not(is.Nil())) + + // when + _, err1c := bpmnEngine.RunOrContinueInstance(instance1.GetInstanceKey()) + _, err2c := bpmnEngine.RunOrContinueInstance(instance2.GetInstanceKey()) + + // then + then.AssertThat(t, err1c, is.Nil()) + then.AssertThat(t, err2c, is.Nil()) + then.AssertThat(t, instance1.GetState(), is.EqualTo(Completed)) + then.AssertThat(t, instance2.GetState(), is.EqualTo(Completed)) + then.AssertThat(t, called[instance1.GetInstanceKey()], has.Length(4)) + then.AssertThat(t, called[instance2.GetInstanceKey()], has.Length(4)) +} diff --git a/test-cases/user-tasks-with-parallel-gateways.bpmn b/test-cases/user-tasks-with-parallel-gateways.bpmn new file mode 100644 index 00000000..f0ac938d --- /dev/null +++ b/test-cases/user-tasks-with-parallel-gateways.bpmn @@ -0,0 +1,126 @@ + + + + + Flow_0xt1d7q + + + + + + + + Flow_05og6fe + Flow_1yi8zvd + + + + Flow_1qo8x2a + + + + + + + Flow_1yi8zvd + Flow_1nvo18e + + + + + + + Flow_1qupj9f + Flow_0wdizhy + + + + + + + Flow_0wdizhy + Flow_1xqmkxd + + + + + + + + Flow_1nvo18e + Flow_1xqmkxd + Flow_1qo8x2a + + + Flow_0xt1d7q + Flow_05og6fe + Flow_1qupj9f + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +