Skip to content

Commit 3783633

Browse files
committed
Increase quantile summary test coverage
1 parent bff620d commit 3783633

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

src/metrics/prometheus_quantile_summary.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ create_summary(Name, Help, Data) ->
494494

495495
validate_error(Error) when is_number(Error), 0.0 < Error, Error < 100.0 ->
496496
ok;
497-
validate_error(_Error) ->
498-
erlang:error({invalid_error, "Error should be a percentage point in (0,100)"}).
497+
validate_error(Error) ->
498+
erlang:error({invalid_error, Error, "Error should be a percentage point in (0,100)"}).
499499

500500
validate_bound(Bound) when is_integer(Bound), 0 < Bound ->
501501
ok;
502-
validate_bound(_Bound) ->
503-
erlang:error({invalid_bound, "Bound should be a positive integer"}).
502+
validate_bound(Bound) ->
503+
erlang:error({invalid_bound, Bound, "Bound should be a positive integer"}).

test/eunit/metric/prometheus_quantile_summary_tests.erl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ prometheus_format_test_() ->
1919
fun test_deregister/1,
2020
fun test_remove/1,
2121
fun test_default_value/1,
22+
fun test_values_when_empty/1,
23+
fun test_values_when_non_existing/1,
2224
fun test_values/1,
2325
fun test_collector1/1,
2426
fun test_collector2/1,
@@ -85,6 +87,23 @@ test_errors(_) ->
8587
{invalid_metric_help, 12, "metric help is not a string"},
8688
prometheus_quantile_summary:new([{name, "qwe"}, {help, 12}])
8789
),
90+
?_assertError(
91+
{invalid_bound, 3.141592, "Bound should be a positive integer"},
92+
prometheus_quantile_summary:new([
93+
{name, "qwe"},
94+
{bound, 3.141592},
95+
{help, ""}
96+
])
97+
),
98+
?_assertError(
99+
{invalid_error, 101, "Error should be a percentage point in (0,100)"},
100+
prometheus_quantile_summary:new([
101+
{name, "qwe"},
102+
{error, 101},
103+
{labels, ["qua", "quantile"]},
104+
{help, ""}
105+
])
106+
),
88107
%% mf/arity errors
89108
?_assertError(
90109
{unknown_metric, default, unknown_metric},
@@ -400,6 +419,27 @@ test_default_value(_) ->
400419
?_assertMatch({0, 0, []}, SomethingValue)
401420
].
402421

422+
test_values_when_empty(_) ->
423+
prometheus_quantile_summary:new([
424+
{name, orders_summary},
425+
{labels, [department]},
426+
{help, "Track orders count/total sum"}
427+
]),
428+
[
429+
?_assertMatch(
430+
[],
431+
lists:sort(prometheus_quantile_summary:values(default, orders_summary))
432+
)
433+
].
434+
435+
test_values_when_non_existing(_) ->
436+
[
437+
?_assertMatch(
438+
[],
439+
lists:sort(prometheus_quantile_summary:values(default, orders_summary))
440+
)
441+
].
442+
403443
test_values(_) ->
404444
prometheus_quantile_summary:new([
405445
{name, orders_summary},
@@ -408,7 +448,6 @@ test_values(_) ->
408448
]),
409449
prometheus_quantile_summary:observe(orders_summary, [electronics], 765.5),
410450
prometheus_quantile_summary:observe(orders_summary, [groceries], 112.3),
411-
412451
[
413452
?_assertMatch(
414453
[

0 commit comments

Comments
 (0)