Skip to content

Commit 3ab257e

Browse files
committed
Add a Future Directions section, discussing tracking task execution time
Minor grammar improvements
1 parent f82780f commit 3ab257e

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

proposals/testing/NNNN-polling-confirmations.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,43 @@ For this initial implementation, I wanted to keep this simple. As such, while
548548
a curve is promising, I think it is better considered on its own as a separate
549549
proposal.
550550

551+
### Use Task execution time to determine how long to poll
552+
553+
As currently proposed, polling confirmations do not take into account how long
554+
it takes to run the given task.
555+
`confirmation(until: .stopsPassing, within: .seconds(1))`, in the success case,
556+
will spend 1 second just waiting between polling attempts. The time spent
557+
setting up polling and the time spent running the closure is not accounted for
558+
whatsoever. On average, this means that test authors can expect the wall-clock
559+
time spent running the polling confirmation for the full iteration count to be
560+
around twice as long as the timeout duration specified.
561+
562+
As part of discussing this, the testing workgroup has started exploring
563+
[adding the ability to track Task execution time](
564+
https://forums.swift.org/t/possible-feature-inspect-task-execution-time/83396).
565+
This would allow the testing library to directly track how long a polling
566+
confirmation has ran for, allowing it to incorporate how long it has spent
567+
polling as part of testing. This would noticeably improve the speed of polling
568+
confirmations, without any of the reliability issues noted in discussion around
569+
why timeouts aren't directly used.
570+
571+
Additionally, tracking task execution time would enable the testing library
572+
to add a watchdog timer to catch stalled polling closures, and even improve the
573+
current watchdog timer for stalled tests. A watchdog timer for polling
574+
confirmations is not included in this proposal because of the issues surrounding
575+
parallel test execution. Instead, test authors will have to rely on the much
576+
coarser-grained watchdog timer for the overall test.
577+
578+
Furthermore, tracking task execution time would also enable for other forms of
579+
`confirmation` to use a time-based tracking method, instead of just the lifespan
580+
of the running function. Similar to XCTest's XCTestExpectation API.
581+
582+
Tracking Task execution time is not included with this proposal because such a
583+
feature is a major feature request in and of itself, and the testing workgroup
584+
feels there is benefit to offering polling confirmations without tracking task
585+
execution time. In the future, we might reimplement polling confirmations to use
586+
task execution time if it becomes available.
587+
551588
## Alternatives considered
552589

553590
### Use separate functions instead of the `PollingStopCondition` enum
@@ -585,10 +622,10 @@ tests are executed serially, the concurrent test runner the testing library uses
585622
means that timeouts are inherently unreliable. Importantly, timeouts become more
586623
unreliable the more tests in the test suite.
587624

588-
### Use polling iterations
625+
### Directly use polling iterations
589626

590-
Another option considered was using polling iterations, either solely or
591-
combined with the interval value.
627+
Another option considered was directly using polling iterations, either solely
628+
or combined with the interval value.
592629

593630
While this works and is resistant to many of the issues timeouts face
594631
in concurrent testing environments - which is why polling is implemented using
@@ -600,7 +637,7 @@ iteration count from a duration value anyway.
600637

601638
### Take in a `Clock` instance
602639

603-
Polling confirmations could take in and use an custom Clock by test authors.
640+
Polling confirmations could take in and use a custom Clock by test authors.
604641
This is not supported because Polling is often used to wait out other delays,
605642
which may or may not use the specified Clock. By staying with the default
606643
continuous clock, Polling confirmations will continue to work even if a test

0 commit comments

Comments
 (0)