From d4db9726c68984986836da061108ac0e746a83df Mon Sep 17 00:00:00 2001 From: Anthony Molinaro Date: Tue, 18 Jun 2019 22:25:23 +0000 Subject: [PATCH] a bit more coverage --- src/mondemand_perfmsg.erl | 34 ++++++++++++++++++++++++++++++++++ src/mondemand_statsmsg.erl | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/src/mondemand_perfmsg.erl b/src/mondemand_perfmsg.erl index be8d727..1ce767c 100644 --- a/src/mondemand_perfmsg.erl +++ b/src/mondemand_perfmsg.erl @@ -316,6 +316,40 @@ perfmsg_test_ () -> lwes_event:from_binary(lwes_event:to_binary(to_lwes(P)),list))) end }, + { "basic constructor test with contexts", + fun () -> + P = new (<<"foo">>, <<"bar">>, [{<<"baz">>,5,10}]), + ?assertEqual (<<"foo">>, id(P)), + ?assertEqual (<<"bar">>,caller_label(P)), + ?assertEqual (1, num_timings(P)), + [ T ] = timings(P), + ?assertEqual (<<"baz">>,timing_label (T)), + ?assertEqual (5, timing_start_time (T)), + ?assertEqual (10, timing_end_time (T)), + ?assertEqual ([],context (P)), + ?assertEqual ({0, P}, + from_lwes( + lwes_event:from_binary(lwes_event:to_binary(to_lwes(P)),list))), + P2 = add_context(P, <<"ck0">>, <<"cv0">>), + ?assertEqual ([{<<"ck0">>,<<"cv0">>}], context(P2)), + ?assertEqual ({0, P2}, + from_lwes( + lwes_event:from_binary(lwes_event:to_binary(to_lwes(P2)),list))), + P3 = add_contexts(P2, [{<<"ck2">>,<<"cv2">>},{<<"ck1">>,<<"cv1">>}]), + ?assertEqual ([{<<"ck2">>,<<"cv2">>}, + {<<"ck1">>,<<"cv1">>}, + {<<"ck0">>,<<"cv0">>}], context(P3)), + % sort order seems to change with serialize/deserialize test, so + % check with them sorted + {0, P4} = + from_lwes( + lwes_event:from_binary(lwes_event:to_binary(to_lwes(P3)),list)), + P5 = P3#md_perf_msg { context = lists:sort(P3#md_perf_msg.context) }, + P6 = P4#md_perf_msg { context = lists:sort(P4#md_perf_msg.context) }, + ?assertEqual (P5, P6) + end + }, + { "basic constructor multi-test", fun () -> P = new (<<"foo">>, <<"bar">>, [{<<"baz">>,5,10},{<<"bob">>,6,8}]), diff --git a/src/mondemand_statsmsg.erl b/src/mondemand_statsmsg.erl index 3c1221d..e93310e 100644 --- a/src/mondemand_statsmsg.erl +++ b/src/mondemand_statsmsg.erl @@ -2065,6 +2065,11 @@ statsmsg_test_ () -> ?assertEqual (undefined, statset_from_string ("::")), ?assertEqual (gauge, string_to_type ("gauge")), ?assertEqual (gauge, string_to_type (<<"gauge">>)), + % unknown exists in some other implementations and is here for + % completeness + ?assertEqual (unknown, string_to_type ("unknown")), + ?assertEqual (unknown, string_to_type (<<"unknown">>)), + ?assertEqual (<<"unknown">>, type_to_string(unknown)), NewEvent = E1#lwes_event { attrs = [{?LWES_INT_64, ?MD_RECEIPT_TIME, 5} | E1#lwes_event.attrs ]},