Skip to content

Commit

Permalink
Merge pull request #156 from getong/update_erlang_test
Browse files Browse the repository at this point in the history
add erlang 19, 20 for test
  • Loading branch information
cmullaparthi authored Sep 1, 2017
2 parents 7529807 + 02be390 commit 5ebdab2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ otp_release:
- 18.0
- 18.1
- 18.2.1
- 19.3
- 20.0
before_script:
- "./bootstrap_travis.sh"
script: "./rebar3 eunit"
10 changes: 9 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{erl_opts, [debug_info, warnings_as_errors, warn_unused_vars, nowarn_shadow_vars, warn_unused_import]}.
{erl_opts, [
debug_info,
warnings_as_errors,
warn_unused_vars,
nowarn_shadow_vars,
warn_unused_import,
{platform_define, "18|19|^2", new_rand},
{platform_define, "^2", ets_ref}
]}.
{xref_checks, [undefined_function_calls, deprecated_function_calls]}.
{eunit_opts, [verbose]}.
16 changes: 16 additions & 0 deletions src/ibrowse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,21 @@ all_trace_off() ->
%% @doc Shows some internal information about load balancing. Info
%% about workers spawned using spawn_worker_process/2 or
%% spawn_link_worker_process/2 is not included.
-ifdef(ets_ref).
show_dest_status() ->
io:format("~-40.40s | ~-5.5s | ~-10.10s | ~s~n",
["Server:port", "ETS", "Num conns", "LB Pid"]),
io:format("~80.80.=s~n", [""]),
Metrics = get_metrics(),
lists:foreach(
fun({Host, Port, {Lb_pid, _, Tid, Size, _}}) ->
io:format("~40.40s | ~-5.5s | ~-5.5s | ~p~n",
[Host ++ ":" ++ integer_to_list(Port),
ref_to_list(Tid),
integer_to_list(Size),
Lb_pid])
end, Metrics).
-else.
show_dest_status() ->
io:format("~-40.40s | ~-5.5s | ~-10.10s | ~s~n",
["Server:port", "ETS", "Num conns", "LB Pid"]),
Expand All @@ -692,6 +707,7 @@ show_dest_status() ->
integer_to_list(Size),
Lb_pid])
end, Metrics).
-endif.

show_dest_status(Url) ->
#url{host = Host, port = Port} = ibrowse_lib:parse_url(Url),
Expand Down
34 changes: 31 additions & 3 deletions test/ibrowse_load_test.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
-module(ibrowse_load_test).
-compile(export_all).
%%-compile(export_all).
-export([
random_seed/0,
start/3,
query_state/0,
shutdown/0,
start_1/3,
calculate_timings/0,
get_mmv/2,
spawn_workers/2,
spawn_workers/4,
wait_for_workers/1,
worker_loop/2,
update_unknown_counter/2
]).

-ifdef(new_rand).

-define(RAND, rand).
random_seed() ->
ok.

-else.

-define(RAND, random).
random_seed() ->
random:seed(os:timestamp()).

-endif.

-define(ibrowse_load_test_counters, ibrowse_load_test_counters).

Expand Down Expand Up @@ -95,7 +123,7 @@ spawn_workers(0, _Num_requests, _Parent, Acc) ->
lists:reverse(Acc);
spawn_workers(Num_workers, Num_requests, Parent, Acc) ->
Pid_ref = spawn_monitor(fun() ->
random:seed(os:timestamp()),
random_seed(),
case catch worker_loop(Parent, Num_requests) of
{'EXIT', Rsn} ->
io:format("Worker crashed with reason: ~p~n", [Rsn]);
Expand Down Expand Up @@ -135,7 +163,7 @@ wait_for_workers([{Pid, Pid_ref} | T] = Pids) ->
worker_loop(Parent, 0) ->
Parent ! {done, self()};
worker_loop(Parent, N) ->
Delay = random:uniform(100),
Delay = ?RAND:uniform(100),
Url = case Delay rem 10 of
%% Change 10 to some number between 0-9 depending on how
%% much chaos you want to introduce into the server
Expand Down
8 changes: 7 additions & 1 deletion test/ibrowse_test_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
get_conn_pipeline_depth/0
]).

-ifdef(new_rand).
-define(RAND, rand).
-else.
-define(RAND, random).
-endif.

-record(request, {method, uri, version, headers = [], body = [], state}).

-define(dec2hex(X), erlang:integer_to_list(X, 16)).
Expand Down Expand Up @@ -290,7 +296,7 @@ process_request(Sock, Sock_type, Req) ->
do_trace("Recvd req: ~p~n", [Req]),
Resp = <<"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n">>,
do_send(Sock, Sock_type, Resp),
timer:sleep(random:uniform(100)).
timer:sleep(?RAND:uniform(100)).

do_send(Sock, tcp, Resp) ->
gen_tcp:send(Sock, Resp);
Expand Down
2 changes: 1 addition & 1 deletion test/ibrowse_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-define(LONG_TIMEOUT_MS, 30000).
-define(PAUSE_FOR_CONNECTIONS_MS, 2000).

-compile(export_all).
%%-compile(export_all).

setup() ->
application:start(crypto),
Expand Down

0 comments on commit 5ebdab2

Please sign in to comment.