Skip to content

Commit 454cca8

Browse files
committed
PR Feedback
Mark defaultPollingConfiguration as private Add polling files to CMakeLists Move Polling and Confirmations.swift to a new Confirmations directory Rename PollingFailureReason to PallingFailedError.Reason
1 parent 635cac6 commit 454cca8

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

Sources/Testing/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ add_library(Testing
2929
Attachments/Attachable.swift
3030
Attachments/AttachableWrapper.swift
3131
Attachments/Attachment.swift
32+
Confirmations/Confirmation.swift
33+
Confirmations/Polling.swift
3234
Events/Clock.swift
3335
Events/Event.swift
3436
Events/Recorder/Event.AdvancedConsoleOutputRecorder.swift
@@ -47,7 +49,6 @@ add_library(Testing
4749
Expectations/Expectation.swift
4850
Expectations/Expectation+Macro.swift
4951
Expectations/ExpectationChecking+Macro.swift
50-
Issues/Confirmation.swift
5152
Issues/ErrorSnapshot.swift
5253
Issues/Issue.swift
5354
Issues/Issue+Recording.swift
@@ -109,6 +110,7 @@ add_library(Testing
109110
Traits/HiddenTrait.swift
110111
Traits/IssueHandlingTrait.swift
111112
Traits/ParallelizationTrait.swift
113+
Traits/PollingConfigurationTrait.swift
112114
Traits/Tags/Tag.Color.swift
113115
Traits/Tags/Tag.Color+Loading.swift
114116
Traits/Tags/Tag.List.swift

Sources/Testing/Polling/Polling.swift renamed to Sources/Testing/Confirmations/Polling.swift

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/// Default values for polling confirmations.
1212
@available(_clockAPI, *)
13-
internal let defaultPollingConfiguration = (
13+
private let _defaultPollingConfiguration = (
1414
pollingDuration: Duration.seconds(1),
1515
pollingInterval: Duration.milliseconds(1)
1616
)
@@ -33,24 +33,23 @@ public enum PollingStopCondition: Sendable, Equatable, Codable {
3333
case stopsPassing
3434
}
3535

36-
/// A type describing why polling failed
37-
@_spi(Experimental)
38-
public enum PollingFailureReason: Sendable, Codable {
39-
/// The polling failed because it was cancelled using `Task.cancel`.
40-
case cancelled
41-
42-
/// The polling failed because the stop condition failed.
43-
case stopConditionFailed(PollingStopCondition)
44-
}
45-
4636
/// A type describing an error thrown when polling fails.
4737
@_spi(Experimental)
4838
public struct PollingFailedError: Error, Sendable, Codable {
39+
/// A type describing why polling failed
40+
public enum Reason: Sendable, Codable {
41+
/// The polling failed because it was cancelled using `Task.cancel`.
42+
case cancelled
43+
44+
/// The polling failed because the stop condition failed.
45+
case stopConditionFailed(PollingStopCondition)
46+
}
47+
4948
/// A user-specified comment describing this confirmation
5049
public var comment: Comment?
5150

5251
/// Why polling failed, either cancelled, or because the stop condition failed.
53-
public var reason: PollingFailureReason
52+
public var reason: Reason
5453

5554
/// A ``SourceContext`` indicating where and how this confirmation was called
5655
@_spi(ForToolsIntegrationOnly)
@@ -66,7 +65,7 @@ public struct PollingFailedError: Error, Sendable, Codable {
6665
/// confirmation was called.
6766
init(
6867
comment: Comment? = nil,
69-
reason: PollingFailureReason,
68+
reason: Reason,
7069
sourceContext: SourceContext,
7170
) {
7271
self.comment = comment
@@ -229,7 +228,7 @@ public func confirmation<R>(
229228
/// - providedValue: The value provided by the test author when calling
230229
/// `confirmPassesEventually` or `confirmAlwaysPasses`.
231230
/// - default: The harded coded default value, as defined in
232-
/// `defaultPollingConfiguration`.
231+
/// `_defaultPollingConfiguration`.
233232
/// - keyPath: The keyPath mapping from `TraitKind` to the value type.
234233
///
235234
/// - Returns: The value to use.
@@ -293,27 +292,27 @@ extension PollingStopCondition {
293292

294293
/// Determine the polling duration to use for the given provided value.
295294
/// Based on ``getValueFromTrait``, this falls back using
296-
/// ``defaultPollingConfiguration.pollingInterval`` and
295+
/// ``_defaultPollingConfiguration.pollingInterval`` and
297296
/// ``PollingUntilFirstPassConfigurationTrait``.
298297
@available(_clockAPI, *)
299298
fileprivate func duration(with provided: Duration?) -> Duration {
300299
getValueFromTrait(
301300
providedValue: provided,
302-
default: defaultPollingConfiguration.pollingDuration,
301+
default: _defaultPollingConfiguration.pollingDuration,
303302
\PollingConfirmationConfigurationTrait.duration,
304303
where: { $0.stopCondition == self }
305304
)
306305
}
307306

308307
/// Determine the polling interval to use for the given provided value.
309308
/// Based on ``getValueFromTrait``, this falls back using
310-
/// ``defaultPollingConfiguration.pollingInterval`` and
309+
/// ``_defaultPollingConfiguration.pollingInterval`` and
311310
/// ``PollingUntilFirstPassConfigurationTrait``.
312311
@available(_clockAPI, *)
313312
fileprivate func interval(with provided: Duration?) -> Duration {
314313
getValueFromTrait(
315314
providedValue: provided,
316-
default: defaultPollingConfiguration.pollingInterval,
315+
default: _defaultPollingConfiguration.pollingInterval,
317316
\PollingConfirmationConfigurationTrait.interval,
318317
where: { $0.stopCondition == self }
319318
)
@@ -390,7 +389,7 @@ private struct Poller {
390389
// if Int(exactly:) returns nil, then that generally means the value is too
391390
// large. In which case, we should fall back to Int.max.
392391

393-
let failureReason: PollingFailureReason
392+
let failureReason: PollingFailedError.Reason
394393
switch await poll(iterations: iterations, expression: body) {
395394
case let .succeeded(value):
396395
return value

Sources/Testing/Issues/Issue.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ public struct Issue: Sendable {
4141
/// An issue due to a polling confirmation having failed.
4242
///
4343
/// - Parameters:
44-
/// - reason: The ``PollingFailureReason`` behind why the polling
44+
/// - reason: The ``PollingFailedError.Reason`` behind why the polling
4545
/// confirmation failed.
4646
///
4747
/// This issue can occur when calling ``confirmation(_:until:within:pollingEvery:isolation:sourceLocation:_:)-455gr``
4848
/// or
4949
/// ``confirmation(_:until:within:pollingEvery:isolation:sourceLocation:_:)-5tnlk``
5050
/// whenever the polling fails, as described in ``PollingStopCondition``.
5151
@_spi(Experimental)
52-
case pollingConfirmationFailed(reason: PollingFailureReason)
52+
case pollingConfirmationFailed(reason: PollingFailedError.Reason)
5353

5454
/// An issue due to an `Error` being thrown by a test function and caught by
5555
/// the testing library.

0 commit comments

Comments
 (0)