Skip to content

Compatibility with simulated time in tokio tests #29

Open
@Ralith

Description

@Ralith

When tokio::time::pause is called in a current-thread runtime, tokio will automatically skip time ahead to the next timer when all tasks are blocked. I want to use this to test whether some complex code does not issue a HTTP request over a long period, without making a test very slow and/or racy.

Unfortunately, httptest in its current form spawns a separate tokio runtime on a background thread. This prevents a test current_thread runtime from accurately judging whether any progress is being made, leading to premature advancement of the simulated clock. Could run be revised to, or grow an option to, spawn tasks in the caller's runtime instead?

See also https://docs.rs/tokio/latest/tokio/time/fn.pause.html#auto-advance, https://tokio.rs/tokio/topics/testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions