File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -384,7 +384,11 @@ private struct Poller {
384384 precondition ( interval > Duration . zero)
385385 precondition ( duration > interval)
386386
387- let iterations = max ( Int ( duration. seconds ( ) / interval. seconds ( ) ) , 1 )
387+ let iterations = Int ( exactly:
388+ max ( duration. seconds ( ) / interval. seconds ( ) , 1 ) . rounded ( )
389+ ) ?? Int . max
390+ // if Int(exactly:) returns nil, then that generally means the value is too
391+ // large. In which case, we should fall back to Int.max.
388392
389393 let failureReason : PollingFailureReason
390394 switch await poll ( iterations: iterations, expression: body) {
Original file line number Diff line number Diff line change @@ -210,6 +210,18 @@ struct PollingConfirmationTests {
210210 ) { true }
211211 }
212212 }
213+
214+ @available ( _clockAPI, * )
215+ @Test ( " Handles extremely large polling iterations " )
216+ func handlesLargePollingIterations( ) async throws {
217+ await #expect( processExitsWith: . success) {
218+ try await confirmation (
219+ until: . firstPass,
220+ within: . seconds( Int . max) ,
221+ pollingEvery: . nanoseconds( 1 )
222+ ) { true }
223+ }
224+ }
213225#endif
214226 }
215227 }
You can’t perform that action at this time.
0 commit comments