Lifecycle Testing
Testing is key to building a high-quality subscription product. However, testing subscription states has historically been challenging due to the time-spanning nature of subscription lifecycles. For example, setting up a test subscription in the grace period state previously required either manually overriding multiple database records (fragile and error-prone), or creating a real subscription and waiting for payment results across two billing cycles (30+ days). Neither approach met our lifecycle testing requirement.
We built a generic lifecycle testing approach that allows us to test any subscription state within minutes. Since every subscription event is represented as a scheduled workflow, we can simulate time progression by executing workflows on demand rather than waiting for their scheduled time.
We implemented this through a test clock feature. Each test subscription has an associated test clock that testers can manipulate through our admin tool. We extended our Scanner Service to support the test clock: when a tester advances the test clock to a future date, the Scanner executes all workflows scheduled up to that test clock time instead of the current wall-clock time. This allows test subscriptions to progress through their natural lifecycle.
Now, testing the grace period scenario mentioned earlier takes just less than a minute: create a subscription, fast-forward the test clock 30 days to trigger renewal, mock a payment failure to enter the grace period, then fast-forward 4 more days to verify the payment retry logic in the grace period. The entire 34-day scenario could be tested in a minute.