Skip to content

Commit

Permalink
Add mongoose_cleanup_SUITE:cleaner_runs_hook_on_nodedown_for_host_typ…
Browse files Browse the repository at this point in the history
…e testcase
  • Loading branch information
arcusfelis committed Jul 20, 2023
1 parent 6e4e058 commit b1bc341
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/mongoose_cleanup_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2,
init_per_testcase/2, end_per_testcase/2]).
-export([cleaner_runs_hook_on_nodedown/1, notify_self_hook/3]).
-export([cleaner_runs_hook_on_nodedown/1,
cleaner_runs_hook_on_nodedown_for_host_type/1,
notify_self_hook/3,
notify_self_hook_for_host_type/3]).
-export([auth_anonymous/1,
last/1,
stream_management/1,
Expand All @@ -27,6 +30,7 @@
all() ->
[
cleaner_runs_hook_on_nodedown,
cleaner_runs_hook_on_nodedown_for_host_type,
auth_anonymous,
last,
stream_management,
Expand Down Expand Up @@ -125,10 +129,8 @@ cleaner_runs_hook_on_nodedown(_Config) ->
gen_hook:add_handler(node_cleanup, global,
fun ?MODULE:notify_self_hook/3,
#{self => self()}, 50),

FakeNode = fakename@fakehost,
Cleaner ! {nodedown, FakeNode},

receive
{got_nodedown, FakeNode} -> ok
after timer:seconds(1) ->
Expand All @@ -137,10 +139,28 @@ cleaner_runs_hook_on_nodedown(_Config) ->
?assertEqual(false, meck:called(gen_hook, error_running_hook,
['_', '_', '_', '_', '_'])).

cleaner_runs_hook_on_nodedown_for_host_type(_Config) ->
HostType = ?HOST,
{ok, Cleaner} = mongoose_cleaner:start_link(),
gen_hook:add_handler(node_cleanup_for_host_type, HostType,
fun ?MODULE:notify_self_hook_for_host_type/3,
#{self => self()}, 50),
FakeNode = fakename@fakehost,
Cleaner ! {nodedown, FakeNode},
receive
{got_nodedown_for_host_type, FakeNode, HostType} -> ok
after timer:seconds(1) ->
ct:fail({timeout, got_nodedown})
end.

notify_self_hook(Acc, #{node := Node}, #{self := Self}) ->
Self ! {got_nodedown, Node},
{ok, Acc}.

notify_self_hook_for_host_type(Acc, #{node := Node}, #{self := Self, host_type := HostType}) ->
Self ! {got_nodedown_for_host_type, Node, HostType},
{ok, Acc}.

auth_anonymous(_Config) ->
HostType = ?HOST,
{U, S, R, JID, SID} = get_fake_session(),
Expand Down

0 comments on commit b1bc341

Please sign in to comment.