Skip to content

Commit 11d0530

Browse files
🐛 parallelisation Ensure that execution options are propagated to compound execution group when creating a PriorityExecutionGroup (#745)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description <!-- Please add any detail or context that would be useful to a reviewer. --> Ensure that execution options are propagated to compound execution group when creating a PriorityExecutionGroup. This solves issues where passing `StopOnFirstError` wasn't stopping the rest of the commands running. ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [x] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update).
1 parent daf88a9 commit 11d0530

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

changes/20251112110252.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:bug: `parallelisation` Ensure that execution options are propagated to compound execution group when creating a PriorityExecutionGroup

utils/parallelisation/priority_group.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ func (g *PriorityExecutionGroup[T]) executors() (executor *CompoundExecutionGrou
9595
g.mu.RLock()
9696
defer g.mu.RUnlock()
9797

98-
executor = NewCompoundExecutionGroup(DefaultOptions().MergeWithOptions(Sequential).Options()...)
98+
opts := DefaultOptions().MergeWithOptions(g.options...)
99+
opts.MergeWithOptions(Sequential)
100+
executor = NewCompoundExecutionGroup(opts.Options()...)
99101
for _, key := range slices.Sorted(maps.Keys(g.groups)) {
100102
executor.RegisterExecutor(g.groups[key])
101103
}

utils/parallelisation/priority_group_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,32 @@ func TestPriority(t *testing.T) {
392392
err := priorityGroup.Execute(ctx)
393393
errortest.AssertError(t, err, commonerrors.ErrTimeout)
394394
})
395+
396+
t.Run("stop on first error propagates properly across priorities", func(t *testing.T) {
397+
defer goleak.VerifyNone(t)
398+
399+
var lowerPriorityCalled, samePriorityCalledAfter atomic.Bool
400+
401+
priorityGroup := NewPriorityExecutionGroup(Sequential, StopOnFirstError)
402+
403+
priorityGroup.RegisterFunctionWithPriority(0, testExecutorFunc(func(ctx context.Context) (err error) {
404+
err = commonerrors.ErrConflict
405+
return
406+
}))
407+
408+
priorityGroup.RegisterFunctionWithPriority(0, testExecutorFunc(func(ctx context.Context) (err error) {
409+
samePriorityCalledAfter.Store(true)
410+
return
411+
}))
412+
413+
priorityGroup.RegisterFunctionWithPriority(1, testExecutorFunc(func(ctx context.Context) (err error) {
414+
lowerPriorityCalled.Store(true)
415+
return
416+
}))
417+
418+
err := priorityGroup.Execute(context.Background())
419+
errortest.AssertError(t, err, commonerrors.ErrConflict)
420+
assert.False(t, samePriorityCalledAfter.Load())
421+
assert.False(t, lowerPriorityCalled.Load())
422+
})
395423
}

0 commit comments

Comments
 (0)