Skip to content

Commit a70a6b7

Browse files
committed
Improves grouped condition trait preparation swiftlang#1034
Updates the `GroupedConditionTrait` to prepare for tests concurrently, improving performance. Also adds a check to ensure there are at least two condition traits before attempting to operate on them, preventing potential errors.
1 parent cfd5075 commit a70a6b7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Sources/Testing/Traits/ConditionTrait.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,23 @@ public struct GroupedConditionTrait: TestTrait, SuiteTrait {
239239
var operations: [Operation] = []
240240

241241
public func prepare(for test: Test) async throws {
242-
for (index, operation) in operations.enumerated() {
243-
try await operation.operate(conditionTraits[index], conditionTraits[index + 1], includeSkipInfo: true)
244-
}
242+
let traitCount = conditionTraits.count
243+
guard traitCount >= 2 else { return }
244+
245+
try await withThrowingTaskGroup(of: Void.self) { group in
246+
for (index, operation) in operations.enumerated() where index < traitCount - 1 {
247+
let trait1 = conditionTraits[index]
248+
let trait2 = conditionTraits[index + 1]
249+
group.addTask {
250+
try await operation.operate(trait1, trait2, includeSkipInfo: true)
251+
}
252+
}
253+
254+
try await group.waitForAll()
255+
}
245256
}
246257

258+
@_spi(Experimental)
247259
public func evaluate() async throws -> Bool {
248260
var result: Bool = true
249261
for (index, operation) in operations.enumerated() {

0 commit comments

Comments
 (0)