Skip to content

Futures polling can block #30

@idletea

Description

@idletea

An example test which will fail (or more accurately: block infinitely)

#[test]
fn futures_do_not_block() {
    let (tx, rx) = multiqueue::broadcast_fut_queue::<i32>(16);
    let mut rt = tokio::runtime::Runtime::new().unwrap();
    rt.block_on(
        rx
        .for_each(|_| {
            futures::future::ok(())
        })
        .into_future()
        .timeout(Duration::from_millis(100))
        .then(|result| {
            match result {
                Ok(_) => Err("this never has a change to even come up - the above blocks forever"),
                Err(_) => Ok("timed out as expected"),
            }
        })
    ).unwrap();
}

This test will hang because this loop has a case in which it'll keep spinning on the recv attempt and never returns control to the event loop.

As such the timeout never has a chance to be considered reached and the future never resolves even with the timeout on it.

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