Time travel testing
Time travel testing means running software at a date other than today - next month, the last second of the year, 29 February, 2038 - to see what it does when that day comes. It finds the bugs that wait for a date: the report that closes the wrong month, the licence that never expires, the token accepted a day too long.
Why it needs a technique at all
A great deal of behaviour depends on the date: trial periods and licence expiry, subscription renewals, certificate and token lifetimes, cache expiry, month-end and year-end reports, interest, reminders. None of it can be tested by waiting, and all of it reads the same thing - the current time - from somewhere. Time travel testing is the practice of controlling that somewhere.
It is sometimes called time machine testing. Whatever the name, there are four places the time can be moved, and each one moves a different amount of the world.
Four ways to move time
| Where the time moves | What sees the new date | Good for | What it costs |
|---|---|---|---|
| The system clock of a machine | Everything on that machine | Testing the operating system itself, scheduled tasks, services. On a throwaway virtual machine, anything | Domain logon, certificates and time sync break, and changing it needs administrator rights |
| A clock inside the code | The code that asks that clock | Unit tests of code you can change - an injected clock, or the fake timers of a test framework | Needs the source and a design that passes the clock in. Does nothing for an application you only have as a program |
| The clock of one process | One application and the processes it starts | Testing a built application end to end, on the machine you work on | An application can read the time some other way, so you need to know which reads were covered |
| The time of a server | Everything that asks that server | Client and server applications where the server decides what time it is | Needs control of the server, which no local tool gives you |
On Linux the third way is libfaketime. On Windows it has been RunAsDate, and it is what Chrono Mock does. The first way, and what it breaks on a machine you work on, has a page of its own →
What to test once time moves
- Boundaries - the last day of a month, a quarter and a fiscal year, and the moment a year rolls over while the application is running.
- The calendar - 29 February, a date before 1970, the 32-bit limit in 2038.
- Your own licensing - the last day of a trial, the first day after it, a licence that expired long ago.
- Elapsed time - countdowns, session timeouts and anything measured between two moments, which only shows its bugs when time runs faster than real.
- Time zones - the customer five zones away whose day ends before yours.
Time travel testing a Windows application
Chrono Mock starts the application with its own clock and leaves the system clock alone, so the rest of the machine keeps the real date. The clock can start at any moment, hold still, run faster, or jump while the application is open.
# The application sees the last ten seconds of 2027 and crosses into 2028 on its own chrono run "C:\apps\test.exe" --at 2027-12-31T23:59:50 # A day a minute: a 30-day period ends in half an hour chrono run "C:\apps\test.exe" --mode x1440 # A named scenario instead of a date, with the evidence written to a file chrono run "C:\apps\test.exe" --preset month-end --report session.txt # Start today and jump to 2038 a few seconds in, while the application is open chrono run "C:\apps\test.exe" --jump-after 5:2038-01-19T03:14:05 --zone +00:00
The same in the window: pick the application, pick a scenario or type a date, choose a speed, press Start.
Knowing that the time travel happened
The weak spot of every technique is the same: the application may read the time some way the technique did not move. A test that passes because the application never saw the new date is worse than no test. Every Chrono Mock session ends with a verdict, the time channels the application really read with a count for each, and the ones it missed. How the audit works →
What this does not cover
- Phones and other systems. Chrono Mock runs Windows applications. Time travel testing of an Android or iOS app, or of a program on Linux or macOS, needs a tool for that platform.
- The server side. A date the application gets from a server stays the server's date. The session says when it sees the application open a network connection, so you know to check.