Re:Smart Programmers Write STUPID Code
by speed_spread on Sunday October 08, 2023 @09:57AM
(#37810478)
Clock decoupling is one of the few patterns that's actually required for reproducible tests. Using the real clock makes test run in realtime (slow) and puts them at the mercy of the OS timing and other exterior factors.
[ Parent
| on HN ]
Re:Smart Programmers Write STUPID Code
by MoreQARespect on Sunday October 08, 2023 @12:09PM
(#37811699)
Not necessarily. This is exactly the kind of thing I mean, in fact.
I once had a bug scenario I wanted to reproduce with a test where the time was grabbed from a system call in the first half of the scenario and via postgres in the second half (with a time delimited query).
With libfaketime I injected a new running service time and postgres service via the test runner. It let me do TDD to create a reproducible test - what you thought was impossible.
I could have jumped straight to dependency injection on that mess of a code base but that would have meant a risky architectural change that I would have to have done without tests. That is not good practice. That is bad practice.
This sort of thing was not possible in 2001 but it's possible now.