@@ -21,11 +21,13 @@ internal let defaultPollingConfiguration = (
21
21
/// function.
22
22
/// - maxPollingIterations: The maximum amount of times to attempt polling.
23
23
/// 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.
25
26
/// If no ``ConfirmPassesEventuallyConfigurationTrait`` has been added, then
26
27
/// polling will be attempted 1000 times before recording an issue.
27
28
/// `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.
29
31
/// If nil, this uses whatever value is specified under the last
30
32
/// ``ConfirmPassesEventuallyConfigurationTrait`` added to the test or suite.
31
33
/// If no ``ConfirmPassesEventuallyConfigurationTrait`` has been added, then
@@ -86,11 +88,13 @@ public struct PollingFailedError: Error {}
86
88
/// function.
87
89
/// - maxPollingIterations: The maximum amount of times to attempt polling.
88
90
/// 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.
90
93
/// If no ``ConfirmPassesEventuallyConfigurationTrait`` has been added, then
91
94
/// polling will be attempted 1000 times before recording an issue.
92
95
/// `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.
94
98
/// If nil, this uses whatever value is specified under the last
95
99
/// ``ConfirmPassesEventuallyConfigurationTrait`` added to the test or suite.
96
100
/// If no ``ConfirmPassesEventuallyConfigurationTrait`` has been added, then
@@ -158,14 +162,15 @@ public func confirmPassesEventually<R>(
158
162
/// function.
159
163
/// - maxPollingIterations: The maximum amount of times to attempt polling.
160
164
/// 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
163
167
/// polling will be attempted 1000 times before recording an issue.
164
168
/// `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.
166
171
/// 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
169
174
/// polling will wait at least 1 millisecond between polling attempts.
170
175
/// `pollingInterval` must be greater than 0.
171
176
/// - isolation: The actor to which `body` is isolated, if any.
@@ -191,12 +196,12 @@ public func confirmAlwaysPasses(
191
196
pollingIterations: getValueFromPollingTrait (
192
197
providedValue: maxPollingIterations,
193
198
default: defaultPollingConfiguration. maxPollingIterations,
194
- \ConfirmPassesAlwaysConfigurationTrait . maxPollingIterations
199
+ \ConfirmAlwaysPassesConfigurationTrait . maxPollingIterations
195
200
) ,
196
201
pollingInterval: getValueFromPollingTrait (
197
202
providedValue: pollingInterval,
198
203
default: defaultPollingConfiguration. pollingInterval,
199
- \ConfirmPassesAlwaysConfigurationTrait . pollingInterval
204
+ \ConfirmAlwaysPassesConfigurationTrait . pollingInterval
200
205
) ,
201
206
comment: comment,
202
207
sourceLocation: sourceLocation
@@ -228,16 +233,13 @@ public func confirmAlwaysPasses(
228
233
private func getValueFromPollingTrait< TraitKind, Value> (
229
234
providedValue: Value ? ,
230
235
default: Value ,
231
- _ keyPath: KeyPath < TraitKind , Value >
236
+ _ keyPath: KeyPath < TraitKind , Value ? >
232
237
) -> Value {
233
238
if let providedValue { return providedValue }
234
239
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`
241
243
}
242
244
243
245
/// A type to record the last value returned by a closure returning an optional
@@ -397,12 +399,16 @@ private struct Poller {
397
399
isolation: isolated ( any Actor ) ? = #isolation,
398
400
expression: @escaping ( ) async -> Bool
399
401
) async -> PollResult {
400
- for _ in 0 ..< pollingIterations {
402
+ for iteration in 0 ..< pollingIterations {
401
403
if let result = await pollingBehavior. processFinishedExpression (
402
404
expressionResult: expression ( )
403
405
) {
404
406
return result
405
407
}
408
+ if iteration == ( pollingIterations - 1 ) {
409
+ // don't bother sleeping if it's the last iteration.
410
+ break
411
+ }
406
412
do {
407
413
try await Task . sleep ( for: pollingInterval)
408
414
} catch {
0 commit comments