~/qa-guides

~/qa-guides/future-date-testing

>_ Future Date Testing: How to Test Expiry and Scheduled Jobs

Walk a 14-day trial through its final second. Use API responses, worker attempts, and captured emails to check expiry, late reminders, and duplicate delivery.

Future date testingScheduled jobsTest clocksExpiry testing

Published

Short answer

Future date testing advances a controlled clock to exercise behavior that would otherwise take hours, days, or months to reach. To test an expiry, make a fresh request at the deadline and inspect the service's decision. To test a scheduled job, also give the scheduler and worker an opportunity to run, then check the result a user would see.

Consider a 14-day trial that sends a reminder one day before it ends. At the end of the trial, two test accounts can both show "Trial ended" and still have different correct inbox counts. One account's reminder went out on time. The other account's worker was offline until the message was already out of date. A test that jumps straight to the final screen misses that difference.

Define what should happen at each deadline

The example uses a fictional planning app. A signed-in trial user can open a weekly forecast. The trial lasts 14 elapsed days. The fixture uses UTC and one-second precision. The trial is the account's only entitlement to the forecast.

  • Trial starts at 2030-04-01T10:00:00Z. The forecast API returns 200 with forecast ID F-7 while the trial is active.
  • Reminder becomes due at 2030-04-14T10:00:00Z, 24 hours before expiry. A worker processing the reminder from this instant until expiry sends it once. If the worker first handles it at or after expiry, it skips the stale message.
  • Access expires at 2030-04-15T10:00:00Z, exactly 336 hours after the start. A forecast request received by the service at this instant returns 403 with the application reason trial_expired. Access changes even if the reminder worker is stopped.

These are product rules for the exercise. A grace period, a reminder that must arrive at least six hours before expiry, or a trial that runs through the customer's last local calendar day would each change the expected results. For a local-date promise, establish the business time zone and resolve the deadline to an instant before building the timeline. Date and time testing checklist

Prepare the clocks and the evidence

  1. Set the test application's clock to April 1 at 10:00 UTC before creating trial T-41. Read back its start and expiry. Creating it first under today's date and then moving the clock changes the age of a different trial.
  2. Trace how the scheduler finds due work and how the worker decides it can still send. A scheduler that compares a due time with the database's current time can stay on today's date while the application moves ahead. Run one real scheduler scan under the fixture clock and record its evaluation time. A direct call to the worker exercises only the delivery decision.
  3. Use an isolated test inbox. Give the run a unique recipient, start with zero captured reminders, and keep the trial ID on the job and message. Send a control message with a different subject to establish that the inbox can receive mail. Count only trial reminders in the results.
  4. Arrange to pause and resume the reminder worker independently. Identify how to observe a completed scan, the disposition of a specific job, and a message accepted by the test inbox. A blank inbox during an unfinished scan cannot tell you whether the reminder was suppressed.

Hold each simulated instant until its expected work has settled. Use a bounded wait measured by the test runner's elapsed time while the application clock is frozen. If the wait expires, record the last completed stage. A job stuck in the queue and a job explicitly skipped as stale need different investigations.

Run the trial from the first reminder to the last second

Use one trial and one inbox throughout this table. At each row, issue a fresh request for the forecast and inspect the indicated worker evidence. The inbox column is the cumulative number of captured trial reminders. For this run the scheduler scans at the reminder's due time. All rows use April 2030 UTC.

ClockForecast responseWorker evidenceInbox total
Apr 1 10:00:00200, F-7Reminder due Apr 14 at 10:000
Apr 14 09:59:59200, F-7Scan completes before the job is due0
Apr 14 10:00:00200, F-7Scheduler selects the reminder and the worker sends it1
Same instant, retry200, F-7A second attempt handles the same reminder1
Apr 15 09:59:59200, F-7Pause the reminder worker1
Apr 15 10:00:00403, trial_expiredWorker remains paused1
Apr 15 10:00:01403, trial_expiredResume processing and complete a scan1

At the cutoff, retain the request ID, the service's evaluation time, and the response reason. A generic error page could also appear if the test session expired. A successful control request for the signed-in user's profile helps distinguish those cases. Keep the precision aligned with the product. A millisecond-based comparison has a different last valid instant. Boundary value analysis

Check the browser countdown against the service

Use a fresh trial with the same expiry for a deliberate disagreement between clocks. Hold the service at April 15 09:59:59 and set the browser to 10:00:00. Reload the forecast. A locally calculated countdown can reach zero a second early. The fresh server response should still include F-7. In this example the forecast view follows the service decision, so a "Trial ended" screen hiding that returned forecast is a display defect.

Now move the service to 10:00:00. Repeat the request and match its ID to the service log. If the response now says 403 with trial_expired and the screen still offers the forecast, inspect whether the view reused the previous response. A screenshot alone cannot distinguish an early countdown from a stale result.

For a browser test, Playwright's page.clock.setFixedTime makes browser date reads return a chosen instant while timers continue running. Set the service clock through the application's test setup. Playwright Clock guide

Resume a worker inside and outside the reminder window

Create two independent trials with the original April 1 start and separate empty inboxes. Pause their delivery workers before the reminder is due. Allow the scheduler to select both reminders at April 14 10:00 and confirm that both jobs are waiting. Each job should carry its original due time. The worker evaluates whether its message is still useful at the time it resumes.

TrialFirst attempt (UTC)Worker resultInbox total
T-42Apr 14 12:00:00Send the overdue reminder with 22 hours left1 reminder
T-43Apr 15 10:00:00Skip the reminder because the trial has expired0 reminders

Compare both accounts at April 15 10:00. The forecast API should report trial_expired for both. Inspect the recipient and text of the message that reached T-42. If it claims a full 24 hours remain, the delivery decision passed and the message content is stale. Giving the actual expiry instant in the message makes that check unambiguous.

For T-43, follow the waiting job through its final disposition. An empty inbox plus a recorded decision to skip the expired trial supports a pass. An empty inbox plus a job still waiting for a worker leaves the recovery case unresolved. If a message arrives, compare the time used for the eligibility decision with the job's original due time. Both runs had the same due time, but their workers needed different answers.

Count deliveries when a job runs twice

The retry row exercises a failure that a second scheduler scan can easily miss. Once the first delivery has completed, arrange for the same logical reminder to reach the worker again. Preserve its trial ID and reminder identity. Give the second processing attempt a distinct attempt ID so you can prove it ran.

For example, attempts A-6 and A-7 both handle the one-day reminder for T-41. The test inbox records message M-301 after the first attempt. After the second attempt settles, list every matching inbox record. A single M-301 satisfies the delivery count. If the inbox also contains M-302, the recipient received two messages even if both carry the same business event ID. Counting distinct event IDs would hide the defect.

For a stronger recovery test, let the test mail service accept the first message, then interrupt the worker before it acknowledges the job. Resume the worker and observe the retry. This checks the interval in which a sender can be unsure whether delivery succeeded. Record what the mail service accepted and what the inbox captured. If your setup can observe only queue acknowledgments, report the narrower result. For delivery receipts, bounces, and message-content checks, use the transactional email testing checklist.

Change the deadline while the old reminder is pending

Some products let a support team extend an active trial. For this separate case, assume a two-day extension moves the outstanding reminder to one day before the new expiry. Apply the extension on April 13, before any reminder has been sent. The old due time is April 14 at 10:00. The revised reminder is due April 16 at 10:00 and access ends April 17 at 10:00.

  1. Move to the old reminder time and complete a scheduler scan. If an old job is already queued, let it run. The test inbox stays empty under the revised schedule.
  2. Make a fresh forecast request at the original April 15 cutoff. It returns 200 and F-7. This catches a service that saved the extension for display but still enforces the old deadline.
  3. Run the scheduler and worker at the revised reminder time. Capture one message with the April 17 expiry. At the revised cutoff the forecast response becomes 403 with trial_expired and the inbox total remains one.

Preserve both the original and revised timestamps in a failure report. An obsolete queue row can be harmless if processing it produces no user-visible effect. A message that reaches the inbox on April 14 shows exactly which old obligation survived the edit.

FAQ

Yes, when the question is how an expired trial looks on first load. A seeded record also makes a useful control for the API response and reason. To check whether an earlier reminder ran or a pending job survived a schedule change, create the trial before those events and preserve its history through the run.

Record the scan schedule alongside the due time. A reminder due at 10:00 is eligible at 10:00. With scans at 09:58 and 10:03, the 10:03 scan is the first one that can select it. Measure delivery delay through to the inbox. A message arriving at 10:03 fits a five-minute target and misses a one-minute target.

In the example, a forecast request received at 09:59:59 can complete successfully at 10:00:01 because the contract uses receipt time. For a product that evaluates at commit, pause the operation before commit, advance the clock through the cutoff, and resume. Include both timestamps so the expected outcome can be reviewed against the correct rule.

Use the provider's supported sandbox control for the objects it manages. For example, Stripe Billing can advance simulated time for a sandbox subscription so you can observe a trial ending or an invoice being generated. If your application consumes the resulting event, match its ID to the local processing result before declaring the end-to-end case complete. Stripe Billing testing guide

Create a fresh trial period and a fresh inbox or recipient for the next independent run. Moving a clock backwards leaves the previous message, job acknowledgments, and delivery history in place. If you reuse a test environment, finish or isolate its pending jobs before restoring the clock so a message from the previous run cannot satisfy the next check.

Ready to turn this guide into a working QA project with statuses, comments, and CSV export?