Skip to content

std HashSet is not deterministic on repeated simulation runs #240

Description

@m-mueller678
#[test]
fn test_madsim(){
    for _ in 0..2{
        println!("check");
        madsim::runtime::Runtime::check_determinism(32, madsim::Config::default(),||async move {
            println!("{:?}", (1..5).collect::<HashSet<u64>>());
        });
    }
    for _ in 0..2{
        println!("simulation");
        madsim::runtime::Runtime::with_seed_and_config(32, madsim::Config::default()).block_on(async move {
            println!("{:?}", (1..5).collect::<HashSet<u64>>());
        });
    }
}

All invocations in check_determinism produce the same ordering of elements. The first call to block_on also produces this same ordering. The second call, however, produces a different order:

check
{2, 3, 4, 1}
{2, 3, 4, 1}
check
{2, 3, 4, 1}
{2, 3, 4, 1}
simulation
{2, 3, 4, 1}
simulation
{3, 1, 2, 4}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions