Skip to content

test(apollo_network): unit tests for the EventWakerManager struct #6647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

guyf-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

guyf-starkware commented May 21, 2025

Copy link

github-actions bot commented May 21, 2025

@guyf-starkware guyf-starkware marked this pull request as ready for review May 21, 2025 13:46
Copy link

github-actions bot commented May 21, 2025

Benchmark movements: No major performance changes detected.

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @guyf-starkware)


Cargo.toml line 313 at r1 (raw file):

validator = "0.12"
void = "1.0.2"
waker-fn = "1"

I think we don't usually write versions with just the major. I'm not sure but I think the meaning of this is to bring any version of the form 1..
Please change this to the version you want (e.g 1.0.0)


crates/apollo_network/src/discovery/behaviours/event_waker_manager_test.rs line 16 at r1 (raw file):

#[test]
fn wakes_all_wakers() {
    let waker_1_was_called = Arc::new(AtomicBool::new(false));

I remember today's talk on "sometimes it's worth not extracting code to function in unit tests", but IMO this is not the case and you should create a struct called MockWaker and have 3 functions for it: waker, is_woken, reset


crates/apollo_network/src/discovery/behaviours/event_waker_manager_test.rs line 55 at r1 (raw file):

    assert!(waker_was_called.load(Ordering::SeqCst));
    // Set the value back to false to see it doesn't get set to true by the waker call.

Wouldn't it be easier to use integer instead of boolean and to do increments instead of setting to true?

@guyf-starkware guyf-starkware force-pushed the 05-21-test_apollo_netowrk_unit_tests_for_the_eventwakermanager_struct branch 2 times, most recently from 4fc229f to f85937c Compare May 21, 2025 14:39
Copy link
Contributor Author

@guyf-starkware guyf-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 6 files reviewed, 3 unresolved discussions (waiting on @ShahakShama)


crates/apollo_network/src/discovery/behaviours/event_waker_manager_test.rs line 16 at r1 (raw file):

Previously, ShahakShama wrote…

I remember today's talk on "sometimes it's worth not extracting code to function in unit tests", but IMO this is not the case and you should create a struct called MockWaker and have 3 functions for it: waker, is_woken, reset

Done except the reset, it's not needed once we moved to counting


crates/apollo_network/src/discovery/behaviours/event_waker_manager_test.rs line 55 at r1 (raw file):

Previously, ShahakShama wrote…

Wouldn't it be easier to use integer instead of boolean and to do increments instead of setting to true?

Done

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 4 files at r2, all commit messages.
Reviewable status: 5 of 6 files reviewed, 2 unresolved discussions


crates/apollo_network/src/discovery/behaviours/test_util.rs line 1 at r2 (raw file):

use std::sync::atomic::{AtomicUsize, Ordering};

Consider moving this to crates/apollo_network/src/test_utils/mod.rs


crates/apollo_network/src/discovery/behaviours/test_util.rs line 17 at r2 (raw file):

        let times_woken_clone = times_woken.clone();
        let waker = waker_fn(move || {
            times_woken_clone.fetch_add(1, Ordering::SeqCst);

Move the ordering to a constant

@guyf-starkware guyf-starkware force-pushed the 05-21-test_apollo_netowrk_unit_tests_for_the_eventwakermanager_struct branch from f85937c to f3dc2a5 Compare May 22, 2025 06:41
Copy link
Contributor Author

@guyf-starkware guyf-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 5 of 6 files reviewed, 2 unresolved discussions (waiting on @ShahakShama)


Cargo.toml line 313 at r1 (raw file):

Previously, ShahakShama wrote…

I think we don't usually write versions with just the major. I'm not sure but I think the meaning of this is to bring any version of the form 1..
Please change this to the version you want (e.g 1.0.0)

Not sure if this is a new comment or I somehow forgot to say Done on the previous one, Eiter way it's now 1.2.0 (not jsut hte major)


crates/apollo_network/src/discovery/behaviours/test_util.rs line 1 at r2 (raw file):

Previously, ShahakShama wrote…

Consider moving this to crates/apollo_network/src/test_utils/mod.rs

I'm going to use it in the other event manager test as well, do you still want me to move it?


crates/apollo_network/src/discovery/behaviours/test_util.rs line 17 at r2 (raw file):

Previously, ShahakShama wrote…

Move the ordering to a constant

This is considered the default for tests but i dont mind moving it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants