-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathrouter_metrics_SUITE.erl
100 lines (80 loc) · 2.67 KB
/
router_metrics_SUITE.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
-module(router_metrics_SUITE).
-export([
all/0,
groups/0,
init_per_testcase/2,
end_per_testcase/2,
init_per_group/2,
end_per_group/2
]).
-export([
metrics_test/1
]).
-include_lib("helium_proto/include/blockchain_state_channel_v1_pb.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include("metrics.hrl").
%%--------------------------------------------------------------------
%% COMMON TEST CALLBACK FUNCTIONS
%%--------------------------------------------------------------------
%%--------------------------------------------------------------------
%% @public
%% @doc
%% Running tests for this suite
%% @end
%%--------------------------------------------------------------------
all() ->
[
{group, chain_alive},
{group, chain_dead}
].
groups() ->
[
{chain_alive, all_tests()},
{chain_dead, all_tests()}
].
all_tests() ->
[
metrics_test
].
%%--------------------------------------------------------------------
%% TEST CASE SETUP
%%--------------------------------------------------------------------
init_per_group(GroupName, Config) ->
test_utils:init_per_group(GroupName, Config).
init_per_testcase(TestCase, Config) ->
test_utils:init_per_testcase(TestCase, Config).
%%--------------------------------------------------------------------
%% TEST CASE TEARDOWN
%%--------------------------------------------------------------------
end_per_group(GroupName, Config) ->
test_utils:end_per_group(GroupName, Config).
end_per_testcase(TestCase, Config) ->
test_utils:end_per_testcase(TestCase, Config).
%%--------------------------------------------------------------------
%% TEST CASES
%%--------------------------------------------------------------------
metrics_test(Config) ->
#{
pubkey_bin := _PubKeyBin,
stream := _Stream,
hotspot_name := _HotspotName
} = test_utils:join_device(Config),
router_metrics ! ?METRICS_TICK,
ok = timer:sleep(timer:seconds(1)),
{_, RoutingPacketTime} = prometheus_histogram:value(?METRICS_ROUTING_PACKET, [
join,
accepted,
accepted,
true
]),
%% Minimum of 2s per but it should not take more than 25ms
ct:pal("[~p:~p:~p] MARKER ~p~n", [?MODULE, ?FUNCTION_NAME, ?LINE, RoutingPacketTime]),
?assert(RoutingPacketTime > 1999 andalso RoutingPacketTime < 2025),
{_, ConsoleAPITime} = prometheus_histogram:value(?METRICS_CONSOLE_API, [
report_status, ok
]),
?assert(ConsoleAPITime < 100),
?assertEqual(true, prometheus_boolean:value(?METRICS_WS)),
?assert(prometheus_gauge:value(?METRICS_VM_CPU, [1]) > 0),
ok.