[Pitch 2] Polling Confirmations in the Testing Library

Hello all! Here is a refined pitch originally posted to the Development > Swift Testing subcategory.

Original Pitch

Read the full proposal here.

There is a full implementation available here. To try it out, follow these steps:

  • Add my fork of Swift Testing as a dependency, specifying the polling-expectations branch.
    • Add .package(url: "https://github.com/younata/swift-testing.git", branch: "polling-expectations") to the dependencies list in your Package.swift.
  • When importing, use the Experimental spi.
    • Import testing as @_spi(Experimental) import Testing.

Polling confirmations adds the ability to repeatedly poll a closure until a given condition is reached. This is extremely useful for checking the state of something that happens in a background thread when you don’t have some better mechanism to get notified by it. I think it’ll be a very welcome addition to the Testing library.

8 Likes

Hey there, I followed the previous pitch thread (as an enthusiastic user of Quick and Nimble, thanks Rachel!) then some Life happened and I’ve been out of touch for a bit.

This looks great! I like the solution you’ve found for the high-load/high-concurrency situation (section “Duration and Concurrent Execution”). Also that the defaults traits are separate and independent.

I’m sorry to say I don’t have time to take it for a spin, but reading it carefully I think it will be very nice.

2 Likes

@younata I saw your additions to the Motivation and ‘when not to use polling’ parts of the pitch. Very clear guidance! Pitch looks great. :raising_hands: