@@ -54,7 +54,7 @@ extension PollingFailedError: CustomIssueRepresentable {
5454
5555/// A type defining when to stop polling early.
5656/// This also determines what happens if the duration elapses during polling.
57- public enum PollingStopCondition : Sendable {
57+ public enum PollingStopCondition : Sendable , Equatable {
5858 /// Evaluates the expression until the first time it returns true.
5959 /// If it does not pass once by the time the timeout is reached, then a
6060 /// failure will be reported.
@@ -78,17 +78,15 @@ public enum PollingStopCondition: Sendable {
7878/// This value may not correspond to the wall-clock time that polling lasts
7979/// for, especially on highly-loaded systems with a lot of tests running.
8080/// 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.
8483/// If no such trait has been added, then polling will be attempted for
8584/// about 1 second before recording an issue.
8685/// `duration` must be greater than 0.
8786/// - interval: The minimum amount of time to wait between polling attempts.
8887/// 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.
9290/// If no such trait has been added, then polling will wait at least
9391/// 1 millisecond between polling attempts.
9492/// `interval` must be greater than 0.
@@ -142,17 +140,15 @@ public func confirmation(
142140/// This value may not correspond to the wall-clock time that polling lasts
143141/// for, especially on highly-loaded systems with a lot of tests running.
144142/// 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.
148145/// If no such trait has been added, then polling will be attempted for
149146/// about 1 second before recording an issue.
150147/// `duration` must be greater than 0.
151148/// - interval: The minimum amount of time to wait between polling attempts.
152149/// 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.
156152/// If no such trait has been added, then polling will wait at least
157153/// 1 millisecond between polling attempts.
158154/// `interval` must be greater than 0.
@@ -221,11 +217,13 @@ public func confirmation<R>(
221217private func getValueFromTrait< TraitKind, Value> (
222218 providedValue: Value ? ,
223219 default: Value ,
224- _ keyPath: KeyPath < TraitKind , Value ? >
220+ _ keyPath: KeyPath < TraitKind , Value ? > ,
221+ where filter: @escaping ( TraitKind ) -> Bool
225222) -> Value {
226223 if let providedValue { return providedValue }
227224 guard let test = Test . current else { return `default` }
228225 let possibleTraits = test. traits. compactMap { $0 as? TraitKind }
226+ . filter ( filter)
229227 let traitValues = possibleTraits. compactMap { $0 [ keyPath: keyPath] }
230228 return traitValues. last ?? `default`
231229}
@@ -257,20 +255,12 @@ extension PollingStopCondition {
257255 /// ``PollingUntilFirstPassConfigurationTrait``.
258256 @available ( _clockAPI, * )
259257 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+ )
274264 }
275265
276266 /// Determine the polling interval to use for the given provided value.
@@ -279,20 +269,12 @@ extension PollingStopCondition {
279269 /// ``PollingUntilFirstPassConfigurationTrait``.
280270 @available ( _clockAPI, * )
281271 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+ )
296278 }
297279}
298280
0 commit comments