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

Fix flaky test in service_domain_db_SUITE #4072

Merged
merged 1 commit into from
Aug 3, 2023
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
24 changes: 20 additions & 4 deletions src/domain/service_domain_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
-export([start_link/0]).
-export([enabled/0]).
-export([force_check_for_updates/0]).
-export([sync_local/0]).
-export([sync_local/0, ping/1]).

-ignore_xref([start_link/0, sync_local/0,
-ignore_xref([start_link/0, sync_local/0, ping/1,
init/1, handle_call/3, handle_cast/2, handle_info/2,
code_change/3, terminate/2]).

Expand Down Expand Up @@ -73,18 +73,34 @@
enabled() ->
mongoose_service:is_loaded(?MODULE).

all_members() ->
pg:get_members(?SCOPE, ?GROUP).

Check warning on line 77 in src/domain/service_domain_db.erl

View check run for this annotation

Codecov / codecov/patch

src/domain/service_domain_db.erl#L77

Added line #L77 was not covered by tests

force_check_for_updates() ->
%% Send a broadcast message.
case pg:get_members(?SCOPE, ?GROUP) of
case all_members() of

Check warning on line 81 in src/domain/service_domain_db.erl

View check run for this annotation

Codecov / codecov/patch

src/domain/service_domain_db.erl#L81

Added line #L81 was not covered by tests
[_|_] = Pids ->
[Pid ! check_for_updates || Pid <- Pids],
ok;
_ ->
ok
end.

%% Ensure that all pending check_for_updates messages are received by this node,
%% even if they are sent by other nodes in the cluster.
%% We have to do an RPC to ensure there is nothing pending in the distributed communication buffers.
%% Used in tests.
sync_local() ->
gen_server:call(?MODULE, ping).
LocalPid = whereis(?MODULE),
true = is_pid(LocalPid),
Nodes = [node(Pid) || Pid <- all_members()],

Check warning on line 96 in src/domain/service_domain_db.erl

View check run for this annotation

Codecov / codecov/patch

src/domain/service_domain_db.erl#L94-L96

Added lines #L94 - L96 were not covered by tests
%% Ping from all nodes in the cluster
[pong = rpc:call(Node, ?MODULE, ping, [LocalPid]) || Node <- Nodes],
Copy link
Collaborator

@NelsonVides NelsonVides Aug 3, 2023

Choose a reason for hiding this comment

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

Why not erpc:multicall/4 instead maybe? Just a suggestion, otherwise I can merge as is.

Copy link
Contributor Author

@arcusfelis arcusfelis Aug 3, 2023

Choose a reason for hiding this comment

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

just to keep it simple.
It is basically 2 nodes (mim and mim2) in the tests anyway.
And this function is used only in tests :D

And one of the nodes is local :)

pong.

Check warning on line 99 in src/domain/service_domain_db.erl

View check run for this annotation

Codecov / codecov/patch

src/domain/service_domain_db.erl#L98-L99

Added lines #L98 - L99 were not covered by tests

-spec ping(pid()) -> pong.
ping(Pid) ->
gen_server:call(Pid, ping).

Check warning on line 103 in src/domain/service_domain_db.erl

View check run for this annotation

Codecov / codecov/patch

src/domain/service_domain_db.erl#L103

Added line #L103 was not covered by tests

%% ---------------------------------------------------------------------------
%% Server callbacks
Expand Down