Skip to content

Commit

Permalink
Merge the wait_until conditions to try to prevent raciness
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Apr 20, 2018
1 parent 6eb85b6 commit 64d1226
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions test/hbbft_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ simple_test(_Config) ->
[ok = hbbft_worker:submit_transaction(Msg, D) || D <- Destinations]
end, Msgs),

%% wait for all the worker's mailboxes to settle...
ok = hbbft_ct_utils:wait_until(fun() ->
0 == lists:sum([element(2, rpc:call(Node, erlang, process_info, [W, message_queue_len])) || {Node, {ok, W}} <- Workers ])
end, 60*2, 500),

%% wait for the chains to converge, this will usually be instant
%% wait for all the worker's mailboxes to settle and
%% wait for the chains to converge
ok = hbbft_ct_utils:wait_until(fun() ->
Chains = sets:from_list(lists:map(fun(W) ->
{ok, Blocks} = hbbft_worker:get_blocks(W),
Blocks
end, Workers)),

0 == lists:sum([element(2, erlang:process_info(W, message_queue_len)) || W <- Workers ]) andalso
1 == sets:size(Chains) andalso
0 /= length(hd(sets:to_list(Chains)))
end, 60*2, 500),
Expand Down
10 changes: 4 additions & 6 deletions test/hbbft_distributed_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@ simple_test(Config) ->
[hbbft_worker:submit_transaction(Msg, Destination) || {_Node, {ok, Destination}} <- Destinations]
end, Msgs),

%% wait for all the worker's mailboxes to settle...
ok = hbbft_ct_utils:wait_until(fun() ->
0 == lists:sum([element(2, rpc:call(Node, erlang, process_info, [W, message_queue_len])) || {Node, {ok, W}} <- Workers ])
end, 60*2, 1000),

%% wait for the chains to converge, this will usually be instant
%% wait for all the worker's mailboxes to settle and.
%% wait for the chains to converge
ok = hbbft_ct_utils:wait_until(fun() ->
Chains = sets:from_list(lists:map(fun({_Node, {ok, W}}) ->
{ok, Blocks} = hbbft_worker:get_blocks(W),
Blocks
end, Workers)),

0 == lists:sum([element(2, rpc:call(Node, erlang, process_info, [W, message_queue_len])) || {Node, {ok, W}} <- Workers ]) andalso
1 == sets:size(Chains) andalso
0 /= length(hd(sets:to_list(Chains)))
end, 60*2, 500),
Expand Down

0 comments on commit 64d1226

Please sign in to comment.