summaryrefslogtreecommitdiff
path: root/lib/inets/test/httpd_load.erl
blob: a849c71f2d5765801f2ac5fb5986b1192ca97412 (plain)
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
%%
%% %CopyrightBegin%
%% 
%% Copyright Ericsson AB 2005-2010. All Rights Reserved.
%% 
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%% 
%% %CopyrightEnd%
%%
%%

-module(httpd_load).

-include("test_server.hrl").

%% General testcases bodies called from httpd_SUITE
-export([load_test/5]).

%% Help functions 
-export([load_test_client/8]).

%%-------------------------------------------------------------------------
%% Test cases starts here.
%%-------------------------------------------------------------------------
load_test(Type, Port, Host, Node,  NofTesters) ->
    URIs = 
	[
	 "/index.html", 
	 "/echo.shtml", 
	 "/",
	 "/flastmod.shtml", 
	 "/misc/"
	],
    Fun = fun(Mod, Host1, Port1, Node1, Req, Exp) -> 
		  ok = httpd_test_lib:verify_request(Mod, Host1, Port1,
						     Node1, Req, Exp)
	  end,
    load_test(Fun, URIs ++ URIs, Type, Host, Port, Node, NofTesters, []).
%%--------------------------------------------------------------------
%% Internal functions
%%--------------------------------------------------------------------

load_test(_, _, _, _, _, _, 0, []) ->
    ok;
load_test(Fun, URIs, Type, Host, Port, Node,  0, List) ->
    receive 
	{Pid, done} ->
	    load_test(Fun, URIs, Type, Host, Port, Node,  0, 
		      lists:delete(Pid, List));
	{'EXIT', Pid, normal} ->
	    load_test(Fun, URIs, Type, Host, Port, Node,  0, 
		      lists:delete(Pid, List));
	{'EXIT', Pid, Reason} ->
	    Str = lists:flatten(io_lib:format("client ~p exited: ~p", 
					      [Pid,Reason])),
	    test_server:fail(Str);
	_ ->
	    load_test(Fun, URIs, Type, Host, Port, Node,  0, List)
    end;

load_test(Fun, URIs, Type, Host, Port, Node,  X, List) ->
    Pid = spawn_link(?MODULE, load_test_client,
		     [Fun, URIs, Type,  Host,  Port,  Node,  self(), 100]),
    load_test(Fun, lists:reverse(URIs), Type, Host, Port, Node,  X-1,
	      [Pid | List]).

load_test_client(_Fun, [], _Type, _Host, _Port, _Node,  Boss, _Timeout) ->
    load_test_client_done(Boss);
load_test_client(Fun, [URI|URIs], Type, Host, Port, Node,  Boss, Timeout) ->  
    Req = "GET "++URI++" HTTP/1.0\r\nConnection: Close\r\n"
	"From: m@erix\r\nReferer: http://www.ericsson.se/\r\n\r\n",
    Timeout1 = 
	case (catch Fun(Type,  Host,  Port,  Node,  Req, 
			[{statuscode, 200}, {statuscode, 500}, 
			 {statuscode, 503}, {version, "HTTP/1.0"}])) of
	    {'EXIT', {suite_failed, connection_closed, _, _}} ->
		%% Some platforms seems to handle heavy load badly.
		%% So, back off and see if this helps
		%%?LOG("load_test_client->requestfailed:connection_closed"[]),
		2 * Timeout;
	    _ ->
		Timeout
	end,
    test_server:sleep(Timeout1),
    load_test_client(Fun, URIs, Type, Host, Port, Node, Boss, Timeout1).

load_test_client_done(Boss) ->
    Boss ! {self(), done}.