@@ -21,11 +21,13 @@ internal let defaultPollingConfiguration = (
2121/// function.
2222/// - maxPollingIterations: The maximum amount of times to attempt polling.
2323/// If nil, this uses whatever value is specified under the last
24- /// ``ConfirmPassesEventuallyConfigurationTrait`` added to the test or suite.
24+ /// ``ConfirmPassesEventuallyConfigurationTrait`` added to the test or
25+ /// suite.
2526/// If no ``ConfirmPassesEventuallyConfigurationTrait`` has been added, then
2627/// polling will be attempted 1000 times before recording an issue.
2728/// `maxPollingIterations` must be greater than 0.
28- /// - pollingInterval: The minimum amount of time to wait between polling attempts.
29+ /// - pollingInterval: The minimum amount of time to wait between polling
30+ /// attempts.
2931/// If nil, this uses whatever value is specified under the last
3032/// ``ConfirmPassesEventuallyConfigurationTrait`` added to the test or suite.
3133/// If no ``ConfirmPassesEventuallyConfigurationTrait`` has been added, then
@@ -86,11 +88,13 @@ public struct PollingFailedError: Error {}
8688/// function.
8789/// - maxPollingIterations: The maximum amount of times to attempt polling.
8890/// If nil, this uses whatever value is specified under the last
89- /// ``ConfirmPassesEventuallyConfigurationTrait`` added to the test or suite.
91+ /// ``ConfirmPassesEventuallyConfigurationTrait`` added to the test or
92+ /// suite.
9093/// If no ``ConfirmPassesEventuallyConfigurationTrait`` has been added, then
9194/// polling will be attempted 1000 times before recording an issue.
9295/// `maxPollingIterations` must be greater than 0.
93- /// - pollingInterval: The minimum amount of time to wait between polling attempts.
96+ /// - pollingInterval: The minimum amount of time to wait between polling
97+ /// attempts.
9498/// If nil, this uses whatever value is specified under the last
9599/// ``ConfirmPassesEventuallyConfigurationTrait`` added to the test or suite.
96100/// If no ``ConfirmPassesEventuallyConfigurationTrait`` has been added, then
@@ -158,14 +162,15 @@ public func confirmPassesEventually<R>(
158162/// function.
159163/// - maxPollingIterations: The maximum amount of times to attempt polling.
160164/// If nil, this uses whatever value is specified under the last
161- /// ``ConfirmPassesAlwaysConfigurationTrait `` added to the test or suite.
162- /// If no ``ConfirmPassesAlwaysConfigurationTrait `` has been added, then
165+ /// ``ConfirmAlwaysPassesConfigurationTrait `` added to the test or suite.
166+ /// If no ``ConfirmAlwaysPassesConfigurationTrait `` has been added, then
163167/// polling will be attempted 1000 times before recording an issue.
164168/// `maxPollingIterations` must be greater than 0.
165- /// - pollingInterval: The minimum amount of time to wait between polling attempts.
169+ /// - pollingInterval: The minimum amount of time to wait between polling
170+ /// attempts.
166171/// If nil, this uses whatever value is specified under the last
167- /// ``ConfirmPassesAlwaysConfigurationTrait `` added to the test or suite.
168- /// If no ``ConfirmPassesAlwaysConfigurationTrait `` has been added, then
172+ /// ``ConfirmAlwaysPassesConfigurationTrait `` added to the test or suite.
173+ /// If no ``ConfirmAlwaysPassesConfigurationTrait `` has been added, then
169174/// polling will wait at least 1 millisecond between polling attempts.
170175/// `pollingInterval` must be greater than 0.
171176/// - isolation: The actor to which `body` is isolated, if any.
@@ -191,12 +196,12 @@ public func confirmAlwaysPasses(
191196 pollingIterations: getValueFromPollingTrait (
192197 providedValue: maxPollingIterations,
193198 default: defaultPollingConfiguration. maxPollingIterations,
194- \ConfirmPassesAlwaysConfigurationTrait . maxPollingIterations
199+ \ConfirmAlwaysPassesConfigurationTrait . maxPollingIterations
195200 ) ,
196201 pollingInterval: getValueFromPollingTrait (
197202 providedValue: pollingInterval,
198203 default: defaultPollingConfiguration. pollingInterval,
199- \ConfirmPassesAlwaysConfigurationTrait . pollingInterval
204+ \ConfirmAlwaysPassesConfigurationTrait . pollingInterval
200205 ) ,
201206 comment: comment,
202207 sourceLocation: sourceLocation
@@ -228,16 +233,13 @@ public func confirmAlwaysPasses(
228233private func getValueFromPollingTrait< TraitKind, Value> (
229234 providedValue: Value ? ,
230235 default: Value ,
231- _ keyPath: KeyPath < TraitKind , Value >
236+ _ keyPath: KeyPath < TraitKind , Value ? >
232237) -> Value {
233238 if let providedValue { return providedValue }
234239 guard let test = Test . current else { return `default` }
235- guard let trait = test. traits. compactMap ( { $0 as? TraitKind } ) . last else {
236- print ( " No traits of type \( TraitKind . self) found. Returning default. " )
237- print ( " Traits: \( test. traits) " )
238- return `default`
239- }
240- return trait [ keyPath: keyPath]
240+ let possibleTraits = test. traits. compactMap { $0 as? TraitKind }
241+ let traitValues = possibleTraits. compactMap { $0 [ keyPath: keyPath] }
242+ return traitValues. last ?? `default`
241243}
242244
243245/// A type to record the last value returned by a closure returning an optional
@@ -397,12 +399,16 @@ private struct Poller {
397399 isolation: isolated ( any Actor ) ? = #isolation,
398400 expression: @escaping ( ) async -> Bool
399401 ) async -> PollResult {
400- for _ in 0 ..< pollingIterations {
402+ for iteration in 0 ..< pollingIterations {
401403 if let result = await pollingBehavior. processFinishedExpression (
402404 expressionResult: expression ( )
403405 ) {
404406 return result
405407 }
408+ if iteration == ( pollingIterations - 1 ) {
409+ // don't bother sleeping if it's the last iteration.
410+ break
411+ }
406412 do {
407413 try await Task . sleep ( for: pollingInterval)
408414 } catch {
0 commit comments