From 5464d33eef3caa5897e08ecef548c1e9622995d1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 15 May 2026 22:14:13 +0000 Subject: [PATCH] fix: Return if executors length is zero in ParallelExecutor (#960) It displayed an unused log and start an unused go routine. We should check the executors number before continue. ``` INFO[2026-05-12T21:01:04-07:00] Running job with maxParallel=1 for 1 matrix combinations INFO[2026-05-12T21:01:04-07:00] NewParallelExecutor: Creating 1 workers for 1 executors INFO[2026-05-12T21:01:04-07:00] NewParallelExecutor: Creating 1 workers for 0 executors INFO[2026-05-12T21:01:04-07:00] NewParallelExecutor: Creating 1 workers for 0 executors ``` Reviewed-on: https://gitea.com/gitea/runner/pulls/960 Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com> Reviewed-by: Nicolas Co-authored-by: Lunny Xiao Co-committed-by: Lunny Xiao --- act/common/executor.go | 6 ++++++ act/common/executor_test.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/act/common/executor.go b/act/common/executor.go index 08de6faa..90fed4d1 100644 --- a/act/common/executor.go +++ b/act/common/executor.go @@ -97,6 +97,12 @@ func NewErrorExecutor(err error) Executor { // NewParallelExecutor creates a new executor from a parallel of other executors func NewParallelExecutor(parallel int, executors ...Executor) Executor { + if len(executors) == 0 { + return func(ctx context.Context) error { + return ctx.Err() + } + } + return func(ctx context.Context) error { work := make(chan Executor, len(executors)) errs := make(chan error, len(executors)) diff --git a/act/common/executor_test.go b/act/common/executor_test.go index b0771863..41b988c9 100644 --- a/act/common/executor_test.go +++ b/act/common/executor_test.go @@ -12,6 +12,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewWorkflow(t *testing.T) { @@ -119,6 +120,19 @@ func TestNewParallelExecutor(t *testing.T) { assert.NoError(errSingle) } +func TestNewParallelExecutorEmpty(t *testing.T) { + assert := assert.New(t) + + ctx := context.Background() + require.NoError(t, NewParallelExecutor(2)(ctx)) + + canceledCtx, cancel := context.WithCancel(context.Background()) + cancel() + + err := NewParallelExecutor(2)(canceledCtx) + assert.ErrorIs(err, context.Canceled) +} + func TestNewParallelExecutorFailed(t *testing.T) { assert := assert.New(t)