Skip to content

Commit fd67477

Browse files
fix: condition multiple precede (#104)
1 parent db2a424 commit fd67477

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (e *innerExecutorImpl) sche_successors(node *innerNode) {
8282

8383
for _, n := range node.successors {
8484
n.mu.Lock()
85-
if (n.recyclable() && n.state.Load() == kNodeStateIdle) || n.Typ == nodeCondition {
85+
if n.recyclable() && n.state.Load() == kNodeStateIdle {
8686
// deps all done or condition node or task has been sched.
8787
n.state.Store(kNodeStateWaiting)
8888
candidate = append(candidate, n)

taskflow_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,57 @@ func TestTaskflowCondition(t *testing.T) {
432432

433433
})
434434

435+
t.Run("multiple tasks preceding condition", func(t *testing.T) {
436+
tf := gotaskflow.NewTaskFlow("G")
437+
438+
A, B, C :=
439+
tf.NewTask("A", func() {
440+
fmt.Println("A")
441+
q.Put("A")
442+
}),
443+
tf.NewTask("B", func() {
444+
fmt.Println("B")
445+
q.Put("B")
446+
}),
447+
tf.NewTask("C", func() {
448+
fmt.Println("C")
449+
q.Put("C")
450+
})
451+
452+
fail, success := tf.NewTask("failed", func() {
453+
fmt.Println("Failed")
454+
q.Put("failed")
455+
t.Fail()
456+
}), tf.NewTask("success", func() {
457+
fmt.Println("success")
458+
q.Put("success")
459+
})
460+
461+
cond := tf.NewCondition("cond", func() uint {
462+
q.Put("cond")
463+
return 0
464+
})
465+
A.Precede(cond)
466+
B.Precede(cond)
467+
C.Precede(cond)
468+
cond.Precede(success)
469+
cond.Precede(fail)
470+
471+
// success.Precede(suc)
472+
if err := tf.Dump(os.Stdout); err != nil {
473+
fmt.Errorf("%v", err)
474+
}
475+
executor.Run(tf).Wait()
476+
477+
executor.Profile(os.Stdout)
478+
chain.grouping("A", "B", "C")
479+
chain.grouping("cond")
480+
chain.grouping("success")
481+
482+
checkTopology(t, q, chain)
483+
484+
})
485+
435486
t.Run("start with condition node", func(t *testing.T) {
436487
i := 0
437488
tf := gotaskflow.NewTaskFlow("G")

0 commit comments

Comments
 (0)