mobile menu icon

Sleeping is not the best option

Published by Manuel Rivero on 17/10/2020

Async Testing, PHP, Connascence, Refactoring, Integration Testing


Introduction.

Some time ago we were developing a code that stored some data with a given TTL. We wanted to check not only that the data was stored correctly but also that it expired after the given TTL. This is an example of testing asynchronous code.

When testing asynchronous code we need to carefully coordinate the test with the system it is testing to avoid running the assertion before the tested action has completed[1]. For example, the following test will always fail because the assertion in line 30 is checked before the data has expired: