mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-05-15 04:13:24 +02:00
fix: preserve empty parallel executor context
- hoist the empty executor guard out of the inner closure to match NewPipelineExecutor - preserve canceled context semantics when no executors are provided - add coverage for the empty executor case
This commit is contained in:
@@ -97,6 +97,12 @@ func NewErrorExecutor(err error) Executor {
|
|||||||
|
|
||||||
// NewParallelExecutor creates a new executor from a parallel of other executors
|
// NewParallelExecutor creates a new executor from a parallel of other executors
|
||||||
func NewParallelExecutor(parallel int, executors ...Executor) Executor {
|
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 {
|
return func(ctx context.Context) error {
|
||||||
work := make(chan Executor, len(executors))
|
work := make(chan Executor, len(executors))
|
||||||
errs := make(chan error, len(executors))
|
errs := make(chan error, len(executors))
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewWorkflow(t *testing.T) {
|
func TestNewWorkflow(t *testing.T) {
|
||||||
@@ -119,6 +120,19 @@ func TestNewParallelExecutor(t *testing.T) {
|
|||||||
assert.NoError(errSingle)
|
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) {
|
func TestNewParallelExecutorFailed(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user