Skip to content

Commit

Permalink
Improve sanity check unit test
Browse files Browse the repository at this point in the history
Now checking the keys sent to graphite.
  • Loading branch information
Seth Falcon committed Nov 27, 2012
1 parent 784d994 commit b280052
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions test/estatsd_server_tests.erl
Expand Up @@ -40,19 +40,27 @@ estatsd_sanity_test_() ->
ok = gen_udp:send(S, "127.0.0.1", Port, <<"mycounter:10|c">>),
ok = gen_udp:send(S, "127.0.0.1", Port, <<"mycounter:10|c">>),
ok = gen_udp:send(S, "127.0.0.1", Port, <<"mycounter:5|d">>),
timer:sleep(3000),
{MsgCount, _Msgs} = capture_tcp:read(),
?debugVal(_Msgs),
estatsd_server:force_flush(),
%% sadly, need sleep here because flush is async. The
%% work is done in an unsupervised spawned process.
timer:sleep(200),
{MsgCount, Msgs} = capture_tcp:read(),
%% three UDP messages are sent, but these will be aggregated into
%% a single message sent off to "graphite".
?assertEqual(1, MsgCount),
%% ?assert(lists:member(<<"mycounter">>, Metrics)),
%% MyCounter = folsom_metrics:get_metric_value(<<"mycounter">>),
%% ?debugVal(MyCounter),
ok
Keys = [ K || {K, _, _} <- process_graphite(hd(Msgs)) ],
?assertEqual([<<"stats.mycounter">>, <<"stats_counts.mycounter">>, <<"statsd.numStats">>],
Keys)
end}]
end}.

process_graphite(Msg) ->
[ parse_graphite_line(X) || X <- re:split(Msg, "\n"), X =/= <<>> ].

parse_graphite_line(Line) ->
[Key, Value, Time] = re:split(Line, " "),
{Key, Value, Time}.

multi() ->
Port = 3344,
{ok, S} = gen_udp:open(0),
Expand Down

0 comments on commit b280052

Please sign in to comment.