Skip to content

Commit

Permalink
Merge pull request #146 from uwiger/uw-t_sync_cand_dies
Browse files Browse the repository at this point in the history
t_sync_cand_dies() must consider all three nodes. Increased timeout
  • Loading branch information
uwiger committed Oct 6, 2017
2 parents 848774b + 65398be commit 0357bc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/gproc_dist.erl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ reset_counter(_) ->
%% @end
%%
sync() ->
leader_call(sync).
%% Increase timeout since gen_leader can take some time ...
leader_call(sync, 10000).

%% @spec get_leader() -> node()
%% @doc Returns the node of the current gproc leader.
Expand Down Expand Up @@ -910,6 +911,12 @@ leader_call(Req) ->
Reply -> Reply
end.

leader_call(Req, Timeout) ->
case gen_leader:leader_call(?MODULE, Req, Timeout) of
badarg -> ?THROW_GPROC_ERROR(badarg);
Reply -> Reply
end.

leader_cast(Msg) ->
gen_leader:leader_cast(?MODULE, Msg).

Expand Down
15 changes: 10 additions & 5 deletions test/gproc_dist_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
-define(f(E), fun() -> ?debugVal(E) end).

dist_test_() ->
{timeout, 120,
{timeout, 180,
[
%% {setup,
%% fun dist_setup/0,
Expand All @@ -49,7 +49,7 @@ dist_test_() ->
tests(Ns, [?f(t_fail_node(Ns))])
end,
fun(Ns) ->
tests(Ns, [?f(t_master_dies(Ns))])
tests(Ns, [{timeout, 15, ?f(t_master_dies(Ns))}])
end
]}
]}.
Expand Down Expand Up @@ -557,11 +557,12 @@ t_subscribe([A,B|_] = Ns) ->
%% Verify that the gproc_dist:sync() call returns true even if a candidate dies
%% while the sync is underway. This test makes use of sys:suspend() to ensure that
%% the other candidate doesn't respond too quickly.
t_sync_cand_dies([A,B|_]) ->
t_sync_cand_dies([A,B,C]) ->
Leader = rpc:call(A, gproc_dist, get_leader, []),
Other = case Leader of
A -> B;
B -> A
B -> A;
C -> A
end,
?assertMatch(ok, rpc:call(Other, sys, suspend, [gproc_dist])),
P = rpc:call(Other, erlang, whereis, [gproc_dist]),
Expand All @@ -574,7 +575,11 @@ t_sync_cand_dies([A,B|_]) ->
%% immediately. Therefore, we should have our answer well within 1 sec.
?assertMatch({value, true}, rpc:nb_yield(Key, 1000)).

t_fail_node([A,B|_] = Ns) ->
%% Verify that the registry updates consistently if a non-leader node
%% dies.
t_fail_node(Ns) ->
Leader = rpc:call(hd(Ns), gproc_dist, get_leader, []),
[A,B] = Ns -- [Leader],
Na = ?T_NAME,
Nb = ?T_NAME,
Pa = t_spawn_reg(A, Na),
Expand Down

0 comments on commit 0357bc7

Please sign in to comment.