4
%% Copyright Ericsson AB 2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
20
-module(overload_SUITE).
21
-include_lib("common_test/include/ct.hrl").
25
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
all() -> [info, set_config_data, set_env_vars, request, timeout].
29
init_per_testcase(_Case,Config) ->
33
end_per_testcase(Case,Config) ->
34
try apply(?MODULE,Case,[cleanup,Config])
35
catch error:undef -> ok
39
%%%-----------------------------------------------------------------
41
Info = overload:get_overload_info(),
42
[{total_intensity,0.0},
43
{accept_intensity,0.0},
47
{accepted_requests,0}] = Info.
49
%%%-----------------------------------------------------------------
50
set_config_data(_Config) ->
51
InfoDefault = overload:get_overload_info(),
52
ok = check_info(0.8,0.1,InfoDefault),
53
ok = overload:set_config_data(0.5,0.4),
54
Info1 = overload:get_overload_info(),
55
ok = check_info(0.5,0.4,Info1),
58
%%%-----------------------------------------------------------------
59
set_env_vars(_Config) ->
60
InfoDefault = overload:get_overload_info(),
61
ok = check_info(0.8,0.1,InfoDefault),
62
ok = application:set_env(sasl,overload_max_intensity,0.5),
63
ok = application:set_env(sasl,overload_weight,0.4),
64
ok = application:stop(sasl),
65
ok = application:start(sasl),
66
Info1 = overload:get_overload_info(),
67
ok = check_info(0.5,0.4,Info1),
69
set_env_vars(cleanup,_Config) ->
70
application:unset_env(sasl,overload_max_intensity),
71
application:unset_env(sasl,overload_weight),
74
%%%-----------------------------------------------------------------
76
%% Find number of request that can be done with default settings
78
overload:set_config_data(0.8, 0.1),
79
NDefault = do_many_requests(0),
81
?t:format("NDefault: ~p",[NDefault]),
83
%% Check that the number of requests increases when max_intensity
85
overload:set_config_data(2, 0.1),
86
NLargeMI = do_many_requests(0),
88
?t:format("NLargeMI: ~p",[NLargeMI]),
89
true = NLargeMI > NDefault,
91
%% Check that the number of requests decreases when weight
93
overload:set_config_data(0.8, 1),
94
NLargeWeight = do_many_requests(0),
96
?t:format("NLargeWeight: ~p",[NLargeWeight]),
97
true = NLargeWeight < NDefault,
99
%% Check that number of requests increases when delay between
100
%% requests increases.
101
%% (Keeping same config and comparing to large weight in order to
102
%% minimize the time needed for this case.)
103
overload:set_config_data(0.8, 1),
104
NLargeTime = do_many_requests(500),
106
?t:format("NLargeTime: ~p",[NLargeTime]),
107
true = NLargeTime > NLargeWeight,
110
%%%-----------------------------------------------------------------
112
overload:set_config_data(0.8, 1),
113
_N = do_many_requests(0),
115
%% Check that the overload alarm is raised
116
[{overload,_}] = alarm_handler:get_alarms(),
118
%% Fake a clear timeout in overload.erl and check that, since it
119
%% came very soon after the overload situation, the alarm is not
123
[{overload,_}] = alarm_handler:get_alarms(),
125
%% A bit later, try again and check that this time the alarm is
129
[] = alarm_handler:get_alarms(),
134
%%%-----------------------------------------------------------------
135
%%% INTERNAL FUNCTIONS
137
%%%-----------------------------------------------------------------
138
%%% Call overload:request/0 up to 30 times with the given time delay
139
%%% between. Stop when 'reject' is returned.
140
do_many_requests(T) ->
141
30 - do_requests(30,T).
144
?t:fail(never_rejected);
146
case overload:request() of
154
%%%-----------------------------------------------------------------
155
%%% Restart the sasl application
157
application:stop(sasl),
158
application:start(sasl),
161
%%%-----------------------------------------------------------------
162
%%% Check that max_intensity and weight is set as expected
163
check_info(MI,W,Info) ->
164
case {lists:keyfind(max_intensity,1,Info), lists:keyfind(weight,1,Info)} of
165
{{_,MI},{_,W}} -> ok;
166
_ -> ?t:fail({unexpected_info,MI,W,Info})