Reliable Async Tests: 🥹

Episode #241 • Jul 10, 2023 • Subscriber-Only

We continue our deep dive into advanced Swift concurrency by exploring the concept of “executors” to better understand its global enqueue hook. We will then put this hook to work and finally have reliable, 100% deterministic async tests.

🥹
Introduction
00:05
Understanding the hook
00:48
Deterministic async tests
05:56
Deterministic feature tests
17:39
A truly immediate countdown preview
31:52
Next time: reliable Combine tests
36:16

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Introduction

OK, so we have now seen that with a little bit of runtime hackery we can get access to a “task enqueue global hook” that is completely public and even apart of Swift’s ABI, but just isn’t easily accessible. But, once we do have a handle on the hook, then we have the opportunity to be notified anytime an async unit of work is scheduled to be performed.

So, what can we do with this?

Brandon: Well, we can completely alter the manner in which jobs are enqueued. Right now we are just turning around and feeding the job back to the original enqueuer, which means the behavior is unchanged from the default. But we do have the ability to send those jobs to a different executor, such as a custom executor, or even serialize all the jobs onto the main executor.

Let’s take a look.

This episode is for subscribers only.

Subscribe to Point-Free

Access this episode, plus all past and future episodes when you become a subscriber.

See plans and pricing

Already a subscriber? Log in

References

Reliably testing code that adopts Swift Concurrency?

Brandon Williams & Stephen Celis • Friday May 13, 2022

A Swift Forums post from yours truly about the difficulty of testing async code in Swift.

Concurrency Extras

Brandon Williams and Stephen Celis • Tuesday Jul 18, 2023

An open source Swift package that provides powerful tools for making async code easier to test.

Announcing Concurrency Extras: Useful, testable Swift concurrency.

Brandon Williams and Stephen Celis • Tuesday Jul 18, 2023

The announcement of our new Concurrency Extras library, which provides powerful tools for making async code easier to test.