Skip to content

Commit 6d42409

Browse files
authored
🐛 [parallelisation] Revert the behaviour change of close stores introduced in previous releases (#688)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description Fix a change of behaviour ### 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 6e63bb8 commit 6d42409

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

changes/20250828111444.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:bug: [parallelisation] Revert the behaviour change of close stores introduced in recent release

utils/parallelisation/group.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ func (o *StoreOptions) MergeWithOptions(opt ...StoreOption) *StoreOptions {
5252
return o.Merge(WithOptions(opt...))
5353
}
5454

55+
func (o *StoreOptions) Apply(opt StoreOption) *StoreOptions {
56+
if opt == nil {
57+
return o
58+
}
59+
return opt(o)
60+
}
61+
5562
func (o *StoreOptions) Overwrite(opts *StoreOptions) *StoreOptions {
5663
return o.Default().Merge(opts)
5764
}

utils/parallelisation/onclose.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ func (s *CloserStore) Len() int {
2525

2626
// NewCloserStore returns a store of io.Closer object which will all be closed concurrently on Close(). The first error received will be returned
2727
func NewCloserStore(stopOnFirstError bool) *CloserStore {
28-
option := ExecuteAll
29-
if stopOnFirstError {
30-
option = StopOnFirstError
31-
}
32-
return NewCloserStoreWithOptions(option, Parallel, OnlyOnce, RetainAfterExecution)
28+
return NewCloserStoreWithOptions(closeDefaultOptions(stopOnFirstError).Options()...)
29+
}
30+
31+
// NewCloserOnceStore is similar to NewCloserStore but only close the closers once.
32+
func NewCloserOnceStore(stopOnFirstError bool) *CloserStore {
33+
return NewCloserStoreWithOptions(closeDefaultOptions(stopOnFirstError).Apply(OnlyOnce).Options()...)
3334
}
3435

3536
// NewCloserStoreWithOptions returns a store of io.Closer object which will all be closed on Close(). The first error received if any will be returned
@@ -177,11 +178,22 @@ func NewCloseFunctionStoreStore(stopOnFirstError bool) *CloseFunctionStore {
177178
// NewConcurrentCloseFunctionStore returns a store closing functions which will all be called concurrently on Close(). The first error received will be returned.
178179
// Prefer using NewCloseFunctionStore where possible
179180
func NewConcurrentCloseFunctionStore(stopOnFirstError bool) *CloseFunctionStore {
180-
option := ExecuteAll
181+
return NewCloseFunctionStore(closeDefaultOptions(stopOnFirstError).Options()...)
182+
}
183+
184+
// NewConcurrentCloseOnceFunctionStore returns a store closing functions once on Close(). It is similar to NewConcurrentCloseFunctionStore otherwise.
185+
func NewConcurrentCloseOnceFunctionStore(stopOnFirstError bool) *CloseFunctionStore {
186+
return NewCloseFunctionStore(closeDefaultOptions(stopOnFirstError).Apply(OnlyOnce).Options()...)
187+
}
188+
189+
func closeDefaultOptions(stopOnFirstError bool) *StoreOptions {
190+
opts := WithOptions(Parallel, RetainAfterExecution)
181191
if stopOnFirstError {
182-
option = StopOnFirstError
192+
opts = opts.Apply(StopOnFirstError)
193+
} else {
194+
opts = opts.Apply(ExecuteAll)
183195
}
184-
return NewCloseFunctionStore(option, Parallel, RetainAfterExecution, OnlyOnce)
196+
return opts
185197
}
186198

187199
// NewCloseOnceGroup is the same as NewCloseFunctionStore but ensures any closing functions are only executed once.

0 commit comments

Comments
 (0)