From f74e8e1ebcb995a1a328d8a146cf2f9c968bdcf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hil=C3=A1rio=20Coelho?= Date: Tue, 6 Jan 2026 16:49:36 +0000 Subject: [PATCH] fix: condition multiple precede --- executor.go | 2 +- taskflow_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/executor.go b/executor.go index dea9aeb..5c35ea6 100644 --- a/executor.go +++ b/executor.go @@ -82,7 +82,7 @@ func (e *innerExecutorImpl) sche_successors(node *innerNode) { for _, n := range node.successors { n.mu.Lock() - if (n.recyclable() && n.state.Load() == kNodeStateIdle) || n.Typ == nodeCondition { + if n.recyclable() && n.state.Load() == kNodeStateIdle { // deps all done or condition node or task has been sched. n.state.Store(kNodeStateWaiting) candidate = append(candidate, n) diff --git a/taskflow_test.go b/taskflow_test.go index fcd52c6..70b9384 100644 --- a/taskflow_test.go +++ b/taskflow_test.go @@ -432,6 +432,57 @@ func TestTaskflowCondition(t *testing.T) { }) + t.Run("multiple tasks preceding condition", func(t *testing.T) { + tf := gotaskflow.NewTaskFlow("G") + + A, B, C := + tf.NewTask("A", func() { + fmt.Println("A") + q.Put("A") + }), + tf.NewTask("B", func() { + fmt.Println("B") + q.Put("B") + }), + tf.NewTask("C", func() { + fmt.Println("C") + q.Put("C") + }) + + fail, success := tf.NewTask("failed", func() { + fmt.Println("Failed") + q.Put("failed") + t.Fail() + }), tf.NewTask("success", func() { + fmt.Println("success") + q.Put("success") + }) + + cond := tf.NewCondition("cond", func() uint { + q.Put("cond") + return 0 + }) + A.Precede(cond) + B.Precede(cond) + C.Precede(cond) + cond.Precede(success) + cond.Precede(fail) + + // success.Precede(suc) + if err := tf.Dump(os.Stdout); err != nil { + fmt.Errorf("%v", err) + } + executor.Run(tf).Wait() + + executor.Profile(os.Stdout) + chain.grouping("A", "B", "C") + chain.grouping("cond") + chain.grouping("success") + + checkTopology(t, q, chain) + + }) + t.Run("start with condition node", func(t *testing.T) { i := 0 tf := gotaskflow.NewTaskFlow("G")