Repository: leptos-rs/leptos
File: reactive_graph/tests/memo.rs (Rust)

Code before:
}

#[cfg(feature = "effects")]
#[tokio::test]
async fn test_memo_read_guard_held() {
    // Test for issue https://github.com/leptos-rs/leptos/issues/3252
    let owner = Owner::new();
    owner.set();
    use imports::*;

    _ = Executor::init_tokio();
    let owner = Owner::new();
    owner.set();
    task::LocalSet::new()
        .run_until(async {
            let source = RwSignal::new(0);

            let directly_derived =
                Memo::new_with_compare(move |_| source.get(), |_, _| true);
            let indirect = Memo::new_with_compare(
                move |_| directly_derived.get(),
                |_, _| true,
            );

            Effect::new(move |_| {
                let direct_value = directly_derived.read(); // <!!!=== This seems to break it
                let indirect_value = indirect.get();
                assert_eq!(direct_value, indirect_value);
            });

            Executor::tick().await;
            source.set(1);
            Executor::tick().await;
            source.set(2);
            Executor::tick().await;
        })
        .await
}

#[test]
fn memo_updates_even_if_not_read_until_later() {
    #![allow(clippy::bool_assert_comparison)]

    let owner = Owner::new();
    owner.set();

    // regression test for https://github.com/leptos-rs/leptos/issues/3339

    let input = RwSignal::new(0);
    let first_memo = Memo::new(move |_| input.get() == 1);
    let second_memo = Memo::new(move |_| first_memo.get());

Review comment (bug):
> `// <!!!=== This seems to break it`

This comment should probably be removed, as it gives the impression that the test is broken. I assume this is just copy-pasted from the issue.

Code after:
}

#[cfg(feature = "effects")]
#[tokio::test]
async fn test_memo_read_guard_held() {
    // regression test for https://github.com/leptos-rs/leptos/issues/3252
    let owner = Owner::new();
    owner.set();
    use imports::*;

    _ = Executor::init_tokio();
    let owner = Owner::new();
    owner.set();
    task::LocalSet::new()
        .run_until(async {
            let source = RwSignal::new(0);

            let directly_derived =
                Memo::new_with_compare(move |_| source.get(), |_, _| true);
            let indirect = Memo::new_with_compare(
                move |_| directly_derived.get(),
                |_, _| true,
            );

            Effect::new(move |_| {
                let direct_value = directly_derived.read();
                let indirect_value = indirect.get();
                assert_eq!(direct_value, indirect_value);
            });

            Executor::tick().await;
            source.set(1);
            Executor::tick().await;
            source.set(2);
            Executor::tick().await;
        })
        .await
}

#[test]
fn memo_updates_even_if_not_read_until_later() {
    #![allow(clippy::bool_assert_comparison)]

    let owner = Owner::new();
    owner.set();

    // regression test for https://github.com/leptos-rs/leptos/issues/3339

    let input = RwSignal::new(0);
    let first_memo = Memo::new(move |_| input.get() == 1);
    let second_memo = Memo::new(move |_| first_memo.get());