Skip to content

Commit

Permalink
Test that trim functions return badarg; test that the slide server su…
Browse files Browse the repository at this point in the history
…rvives them returning badarg
  • Loading branch information
Sölvi Páll Ásgeirsson committed Oct 30, 2015
1 parent 21a3dd9 commit 1daa48c
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/folsom_sample_slide_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,22 @@ exercise() ->
Trimmed2 = folsom_sample_slide:trim(Slide#slide.reservoir, ?WINDOW),
?assertEqual((?RUNTIME * ?READINGS) - ((?RUNTIME - ?WINDOW - 1) * ?READINGS), Trimmed2),
check_table(Slide, []),
ok.

%% trim shuld throw badarg in the case of nonexistant ETS tables
NonExistant = ets:new(non_existant, []),
ets:delete(NonExistant),
?assertError(badarg, folsom_sample_slide:trim(NonExistant, ?WINDOW)),
?assertError(badarg, folsom_sample_slide_uniform:trim(NonExistant, ?WINDOW)),

%% The slide server exits with reason normal in case the ets table it's trimming goes away
process_flag(trap_exit, true),
{ok, SlideServer} = folsom_sample_slide_server:start_link(folsom_sample_slide, NonExistant, 1),
ExitMsg = wait_for_exit(SlideServer, timer:seconds(2)),
?assertMatch({'EXIT', SlideServer, normal}, ExitMsg),
process_flag(trap_exit, false),
ok.


expand_window() ->
%% create a new histogram
%% will leave the trim server running, as resize() needs it
Expand Down Expand Up @@ -207,3 +221,13 @@ check_table(Slide, Moments) ->
StrippedKeys = lists:usort([X || {X, _} <- Ks]),
?assertEqual(Moments, StrippedKeys),
?assertEqual(ExpectedVs, lists:sort(Vs)).

wait_for_exit(Pid, Timeout) ->
receive
M = {'EXIT', Pid, _Reason} ->
M;
Other ->
Other
after Timeout ->
timeout
end.

0 comments on commit 1daa48c

Please sign in to comment.