Skip to content

Check the result of the function in check_determinism #203

Description

@tomasol

This is just an idea / feature request, it's totally fine to close the issue if it does not spark any interest.

Currently check_determinism verifies that the randomness state after running the input function twice is the same.
If the input function is truly deterministic, it must return the same result.
Here is how I currently check that a function is deterministic:

#[test]
fn ulid_generation_should_be_deterministic() {
    let mut builder_a = madsim::runtime::Builder::from_env();
    builder_a.check = true;
    let mut builder_b = madsim::runtime::Builder::from_env(); // Builder: Clone would be useful
    builder_b.check = true;
    builder_b.seed = builder_a.seed;
    assert_eq!(
        builder_a.run(|| async { ulid::Ulid::new() }),
        builder_b.run(|| async { ulid::Ulid::new() })
    );
}

It would be nice to have less boilerplate, given that the function returns a value implementing Debug and PartialEq

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