Skip to content

Commit

Permalink
Implement clear_table function for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Jul 31, 2023
1 parent 3c12479 commit 660d2b0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion big_tests/tests/mongoose_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ stop_online_rooms() ->
false -> ct:fail({ejabberd_mod_muc_sup_not_found, Supervisor, HostType})
end,
rpc(mim(), erlang, exit, [SupervisorPid, kill]),
rpc(mim(), mnesia, clear_table, [muc_online_room]),
%% That's a pretty dirty way
rpc(mim(), mongoose_muc_online_backend, clear_table, [HostType]),
ok.

forget_persistent_rooms() ->
Expand Down
8 changes: 7 additions & 1 deletion src/muc/mongoose_muc_online_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
room_destroyed/4,
find_room_pid/3,
get_online_rooms/2,
node_cleanup/2]).
node_cleanup/2,
clear_table/1]).

-define(MAIN_MODULE, mongoose_muc_online).

Expand All @@ -29,6 +30,8 @@

-callback node_cleanup(mongooseim:host_type(), node()) -> ok.

-callback clear_table(mongooseim:host_type()) -> ok.

%% API Functions

-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> any().
Expand Down Expand Up @@ -72,3 +75,6 @@ get_online_rooms(HostType, MucHost) ->
node_cleanup(HostType, Node) ->
Args = [HostType, Node],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

clear_table(HostType) ->
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, [HostType]).
12 changes: 11 additions & 1 deletion src/muc/mongoose_muc_online_cets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
room_destroyed/4,
find_room_pid/3,
get_online_rooms/2,
node_cleanup/2]).
node_cleanup/2,
clear_table/1]).

-export([handle_conflict/2]).

Expand Down Expand Up @@ -101,3 +102,12 @@ node_cleanup(HostType, Node) ->
Guard = {'==', {node, '$1'}, Node},
ets:select_delete(Tab, [{Pattern, [Guard], [true]}]),
ok.

%% Clear table for tests
-spec clear_table(mongooseim:host_type()) -> ok.
clear_table(HostType) ->
Tab = table_name(HostType),
ets:match_delete(Tab, '_'),
Nodes = cets:other_nodes(Tab),
[rpc:call(Node, ets, match_delete, [Tab, '_']) || Node <- Nodes],
ok.
9 changes: 8 additions & 1 deletion src/muc/mongoose_muc_online_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
room_destroyed/4,
find_room_pid/3,
get_online_rooms/2,
node_cleanup/2]).
node_cleanup/2,
clear_table/1]).

-include_lib("mod_muc.hrl").

Expand Down Expand Up @@ -85,3 +86,9 @@ node_cleanup(HostType, Node) ->
end,
mnesia:async_dirty(F),
ok.

%% Clear table for tests
-spec clear_table(mongooseim:host_type()) -> ok.
clear_table(_HostType) ->
mnesia:clear_table(muc_online_room),
ok.

0 comments on commit 660d2b0

Please sign in to comment.