@@ -54,7 +54,7 @@ extension PollingFailedError: CustomIssueRepresentable {
54
54
55
55
/// A type defining when to stop polling early.
56
56
/// This also determines what happens if the duration elapses during polling.
57
- public enum PollingStopCondition : Sendable {
57
+ public enum PollingStopCondition : Sendable , Equatable {
58
58
/// Evaluates the expression until the first time it returns true.
59
59
/// If it does not pass once by the time the timeout is reached, then a
60
60
/// failure will be reported.
@@ -78,17 +78,15 @@ public enum PollingStopCondition: Sendable {
78
78
/// This value may not correspond to the wall-clock time that polling lasts
79
79
/// for, especially on highly-loaded systems with a lot of tests running.
80
80
/// If nil, this uses whatever value is specified under the last
81
- /// ``PollingUntilFirstPassConfigurationTrait`` or
82
- /// ``PollingUntilStopsPassingConfigurationTrait`` added to the test or
83
- /// suite.
81
+ /// ``PollingConfirmationConfigurationTrait`` added to the test or suite
82
+ /// with a matching stopCondition.
84
83
/// If no such trait has been added, then polling will be attempted for
85
84
/// about 1 second before recording an issue.
86
85
/// `duration` must be greater than 0.
87
86
/// - interval: The minimum amount of time to wait between polling attempts.
88
87
/// If nil, this uses whatever value is specified under the last
89
- /// ``PollingUntilFirstPassConfigurationTrait`` or
90
- /// ``PollingUntilStopsPassingConfigurationTrait`` added to the test or
91
- /// suite.
88
+ /// ``PollingConfirmationConfigurationTrait`` added to the test or suite
89
+ /// with a matching stopCondition.
92
90
/// If no such trait has been added, then polling will wait at least
93
91
/// 1 millisecond between polling attempts.
94
92
/// `interval` must be greater than 0.
@@ -142,17 +140,15 @@ public func confirmation(
142
140
/// This value may not correspond to the wall-clock time that polling lasts
143
141
/// for, especially on highly-loaded systems with a lot of tests running.
144
142
/// If nil, this uses whatever value is specified under the last
145
- /// ``PollingUntilFirstPassConfigurationTrait`` or
146
- /// ``PollingUntilStopsPassingConfigurationTrait`` added to the test or
147
- /// suite.
143
+ /// ``PollingConfirmationConfigurationTrait`` added to the test or suite
144
+ /// with a matching stopCondition.
148
145
/// If no such trait has been added, then polling will be attempted for
149
146
/// about 1 second before recording an issue.
150
147
/// `duration` must be greater than 0.
151
148
/// - interval: The minimum amount of time to wait between polling attempts.
152
149
/// If nil, this uses whatever value is specified under the last
153
- /// ``PollingUntilFirstPassConfigurationTrait`` or
154
- /// ``PollingUntilStopsPassingConfigurationTrait`` added to the test or
155
- /// suite.
150
+ /// ``PollingConfirmationConfigurationTrait`` added to the test or suite
151
+ /// with a matching stopCondition.
156
152
/// If no such trait has been added, then polling will wait at least
157
153
/// 1 millisecond between polling attempts.
158
154
/// `interval` must be greater than 0.
@@ -221,11 +217,13 @@ public func confirmation<R>(
221
217
private func getValueFromTrait< TraitKind, Value> (
222
218
providedValue: Value ? ,
223
219
default: Value ,
224
- _ keyPath: KeyPath < TraitKind , Value ? >
220
+ _ keyPath: KeyPath < TraitKind , Value ? > ,
221
+ where filter: @escaping ( TraitKind ) -> Bool
225
222
) -> Value {
226
223
if let providedValue { return providedValue }
227
224
guard let test = Test . current else { return `default` }
228
225
let possibleTraits = test. traits. compactMap { $0 as? TraitKind }
226
+ . filter ( filter)
229
227
let traitValues = possibleTraits. compactMap { $0 [ keyPath: keyPath] }
230
228
return traitValues. last ?? `default`
231
229
}
@@ -257,20 +255,12 @@ extension PollingStopCondition {
257
255
/// ``PollingUntilFirstPassConfigurationTrait``.
258
256
@available ( _clockAPI, * )
259
257
fileprivate func duration( with provided: Duration ? ) -> Duration {
260
- switch self {
261
- case . firstPass:
262
- getValueFromTrait (
263
- providedValue: provided,
264
- default: defaultPollingConfiguration. pollingDuration,
265
- \PollingUntilFirstPassConfigurationTrait . duration
266
- )
267
- case . stopsPassing:
268
- getValueFromTrait (
269
- providedValue: provided,
270
- default: defaultPollingConfiguration. pollingDuration,
271
- \PollingUntilStopsPassingConfigurationTrait . duration
272
- )
273
- }
258
+ getValueFromTrait (
259
+ providedValue: provided,
260
+ default: defaultPollingConfiguration. pollingDuration,
261
+ \PollingConfirmationConfigurationTrait . duration,
262
+ where: { $0. stopCondition == self }
263
+ )
274
264
}
275
265
276
266
/// Determine the polling interval to use for the given provided value.
@@ -279,20 +269,12 @@ extension PollingStopCondition {
279
269
/// ``PollingUntilFirstPassConfigurationTrait``.
280
270
@available ( _clockAPI, * )
281
271
fileprivate func interval( with provided: Duration ? ) -> Duration {
282
- switch self {
283
- case . firstPass:
284
- getValueFromTrait (
285
- providedValue: provided,
286
- default: defaultPollingConfiguration. pollingInterval,
287
- \PollingUntilFirstPassConfigurationTrait . interval
288
- )
289
- case . stopsPassing:
290
- getValueFromTrait (
291
- providedValue: provided,
292
- default: defaultPollingConfiguration. pollingInterval,
293
- \PollingUntilStopsPassingConfigurationTrait . interval
294
- )
295
- }
272
+ getValueFromTrait (
273
+ providedValue: provided,
274
+ default: defaultPollingConfiguration. pollingInterval,
275
+ \PollingConfirmationConfigurationTrait . interval,
276
+ where: { $0. stopCondition == self }
277
+ )
296
278
}
297
279
}
298
280
0 commit comments