From 42547c81d9bcf6b18232cf367624c16d683e6e85 Mon Sep 17 00:00:00 2001 From: Raphael Vigee Date: Sun, 17 Mar 2024 11:37:03 +0000 Subject: [PATCH] Fix cancel test --- worker2/action_test.go | 8 ++++++-- worker2/engine.go | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/worker2/action_test.go b/worker2/action_test.go index 63ca9ecd..e7c535ee 100644 --- a/worker2/action_test.go +++ b/worker2/action_test.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/stretchr/testify/assert" "testing" - "time" ) func TestExecSimple(t *testing.T) { @@ -191,6 +190,8 @@ func TestExecCancel(t *testing.T) { }, } + errCh := a.ErrorCh() + e := NewEngine() ctx, cancel := context.WithCancel(context.Background()) @@ -200,10 +201,13 @@ func TestExecCancel(t *testing.T) { e.Schedule(a) - time.Sleep(time.Second) cancel() e.Wait() + + err := <-errCh + + assert.ErrorIs(t, err, context.Canceled) } func TestExecDeps(t *testing.T) { diff --git a/worker2/engine.go b/worker2/engine.go index 859e1f54..a1778093 100644 --- a/worker2/engine.go +++ b/worker2/engine.go @@ -274,7 +274,8 @@ func (e *Execution) Start(ctx context.Context) error { e.suspendCh = make(chan struct{}) go func() { - e.errCh <- e.safeExec(ctx) + err := e.safeExec(ctx) + e.errCh <- err }() } else { e.resumeAckCh <- struct{}{}