Skip to main content

Module time_control

Module time_control 

Source
Expand description

Time control utilities for durable execution testing.

This module provides the TimeControl struct for managing fake time during tests, enabling instant advancement of wait operations without blocking.

§Overview

When testing durable functions that include wait operations, you typically don’t want to wait for actual time to pass. The TimeControl utilities integrate with Tokio’s time manipulation features to enable instant time advancement.

§Examples

use durable_execution_sdk_testing::TimeControl;
use std::time::Duration;

#[tokio::test]
async fn test_with_time_control() {
    // Enable time skipping
    TimeControl::enable().await.unwrap();

    // Advance time by 5 seconds instantly
    TimeControl::advance(Duration::from_secs(5)).await;

    // Disable time skipping when done
    TimeControl::disable().await.unwrap();
}

§Requirements

  • 2.1: WHEN time skipping is enabled, THE Local_Test_Runner SHALL use Tokio’s time manipulation to skip wait durations
  • 2.2: WHEN a wait operation is encountered with time skipping enabled, THE Local_Test_Runner SHALL advance time instantly without blocking
  • 2.3: WHEN time skipping is disabled, THE Local_Test_Runner SHALL execute wait operations with real timing
  • 2.4: WHEN teardown_test_environment() is called, THE Local_Test_Runner SHALL restore normal time behavior

Structs§

TimeControl
Utilities for controlling time during durable execution tests.
TimeControlGuard
A guard that automatically disables time control when dropped.

Functions§

is_time_paused
Checks if Tokio’s time is currently paused.