Skip to content
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

Improve notify center tests. #28

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ end
end

@testset "notifications" begin
for center in [local_notify_center(), darwin_notify_center()]
for (center, synchronous) in [(local_notify_center(), true),
(darwin_notify_center(), false)]
foo_calls = 0
bar_calls = 0
foobar_calls = 0
Expand All @@ -308,33 +309,43 @@ end
add_observer!(center, foobar_observer; name="bar")

post_notification!(center, "foo")
run_loop(1; return_after_source_handled=true)
if !synchronous
run_loop(10; return_after_source_handled=true)
end
@test foo_calls == 1
@test foobar_calls == 1

post_notification!(center, "bar")
run_loop(1; return_after_source_handled=true)
if !synchronous
run_loop(10; return_after_source_handled=true)
end
@test bar_calls == 1
@test foobar_calls == 2

# test unsubscribing from a specific notification
remove_observer!(center, foobar_observer; name="foo")

post_notification!(center, "foo")
run_loop(1; return_after_source_handled=true)
if !synchronous
run_loop(10; return_after_source_handled=true)
end
@test foo_calls == 2
@test foobar_calls == 2

post_notification!(center, "bar")
run_loop(1; return_after_source_handled=true)
if !synchronous
run_loop(10; return_after_source_handled=true)
end
@test bar_calls == 2
@test foobar_calls == 3

# test unsubscribing from all notifications
remove_observer!(center, foobar_observer)

post_notification!(center, "bar")
run_loop(1; return_after_source_handled=true)
if !synchronous
run_loop(10; return_after_source_handled=true)
end
@test bar_calls == 3
@test foobar_calls == 3
finally
Expand Down
Loading