Skip to content

Commit

Permalink
Update status check
Browse files Browse the repository at this point in the history
  • Loading branch information
vihu committed Apr 9, 2021
1 parent fb4b0c8 commit d99f4c3
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/dkg_distributed_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,38 @@ run(N, F, T, Nodes) ->

_ = [ ct:pal("~p is_done? :~p", [Node, dkg_worker:is_done(W)]) || {Node, {ok, W}} <- Workers],

_ = [ ct:pal("~p status? :~p", [Node, dkg_worker:dkg_status(W)]) || {Node, {ok, W}} <- Workers],
true = check_status(Workers),

[ unlink(W) || {_, {ok, W}} <- Workers ].

%% helper functions

check_status(Workers) ->
Statuses = [dkg_worker:dkg_status(W) || {_Node, {ok, W}} <- Workers],

Check1 = lists:all(fun(Status) ->
5 == maps:get(echoes_required, Status) andalso
3 == maps:get(readies_required, Status)
end,
Statuses),

CountShares = lists:foldl(fun(Status, Acc) ->
SharesMap = maps:get(shares_map, Status),

CountDone = maps:fold(fun(_ID, Result, Acc2) ->
case maps:get(done, Result, false) of
true -> Acc2 + 1;
false -> Acc2
end
end, 0, SharesMap),

CountDone + Acc
end,
0,
Statuses),

%% for each worker, we expect i - 1 shares worse case
MinimumExpectedShares = (length(Workers) - 1) * length(Workers),
Check2 = CountShares >= MinimumExpectedShares,

Check1 andalso Check2.

0 comments on commit d99f4c3

Please sign in to comment.