Skip to content

Commit

Permalink
Fix broken tests + remove outdated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lpgauth committed Jul 19, 2011
1 parent 114f3ab commit 4af873c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 161 deletions.
26 changes: 12 additions & 14 deletions src/lhttpc.erl
Expand Up @@ -325,20 +325,18 @@ request(Host, Port, Ssl, Path, Method, Hdrs, Body, Timeout, Options) ->
Args = [self(), Host, Port, Ssl, Path, Method, Hdrs, Body, Options],
Pid = spawn_link(lhttpc_client, request, Args),
receive
X ->
X
% {response, Pid, R} ->
% R;
% {exit, Pid, Reason} ->
% % We would rather want to exit here, instead of letting the
% % linked client send us an exit signal, since this can be
% % caught by the caller.
% exit(Reason);
% {'EXIT', Pid, Reason} ->
% % This could happen if the process we're running in taps exits
% % and the client process exits due to some exit signal being
% % sent to it. Very unlikely though
% exit(Reason)
{response, Pid, R} ->
R;
{exit, Pid, Reason} ->
% We would rather want to exit here, instead of letting the
% linked client send us an exit signal, since this can be
% caught by the caller.
exit(Reason);
{'EXIT', Pid, Reason} ->
% This could happen if the process we're running in taps exits
% and the client process exits due to some exit signal being
% sent to it. Very unlikely though
exit(Reason)
after Timeout ->
kill_client(Pid)
end.
Expand Down
119 changes: 0 additions & 119 deletions test/lhttpc_manager_tests.erl

This file was deleted.

35 changes: 7 additions & 28 deletions test/lhttpc_tests.erl
@@ -1,7 +1,7 @@
%%% ----------------------------------------------------------------------------
%%% Copyright (c) 2009, Erlang Training and Consulting Ltd.
%%% All rights reserved.
%%%
%%%
%%% Redistribution and use in source and binary forms, with or without
%%% modification, are permitted provided that the following conditions are met:
%%% * Redistributions of source code must retain the above copyright
Expand All @@ -12,7 +12,7 @@
%%% * Neither the name of Erlang Training and Consulting Ltd. nor the
%%% names of its contributors may be used to endorse or promote products
%%% derived from this software without specific prior written permission.
%%%
%%%
%%% THIS SOFTWARE IS PROVIDED BY Erlang Training and Consulting Ltd. ''AS IS''
%%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
%%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Expand Down Expand Up @@ -109,7 +109,7 @@ stop_app(_) ->
ok = application:stop(ssl).

tcp_test_() ->
{inorder,
{inorder,
{setup, fun start_app/0, fun stop_app/1, [
?_test(simple_get()),
?_test(empty_get()),
Expand All @@ -134,7 +134,6 @@ tcp_test_() ->
?_test(bad_url()),
?_test(persistent_connection()),
?_test(request_timeout()),
?_test(connection_timeout()),
?_test(suspended_manager()),
?_test(chunked_encoding()),
?_test(partial_upload_identity()),
Expand All @@ -152,8 +151,7 @@ tcp_test_() ->
?_test(partial_download_smallish_chunks()),
?_test(partial_download_slow_chunks()),
?_test(close_connection()),
?_test(message_queue()),
?_test(connection_count()) % just check that it's 0 (last)
?_test(message_queue())
]}
}.

Expand All @@ -162,8 +160,7 @@ ssl_test_() ->
{setup, fun start_app/0, fun stop_app/1, [
?_test(ssl_get()),
?_test(ssl_post()),
?_test(ssl_chunked()),
?_test(connection_count()) % just check that it's 0 (last)
?_test(ssl_chunked())
]}
}.

Expand Down Expand Up @@ -379,18 +376,6 @@ request_timeout() ->
URL = url(Port, "/slow"),
?assertEqual({error, timeout}, lhttpc:request(URL, get, [], 50)).

connection_timeout() ->
Port = start(gen_tcp, [fun simple_response/5, fun simple_response/5]),
URL = url(Port, "/close_conn"),
lhttpc_manager:update_connection_timeout(50), % very short keep alive
{ok, Response} = lhttpc:request(URL, get, [], 100),
?assertEqual({200, "OK"}, status(Response)),
?assertEqual(<<?DEFAULT_STRING>>, body(Response)),
timer:sleep(100),
?assertEqual(0,
lhttpc_manager:connection_count({"localhost", Port, false})),
lhttpc_manager:update_connection_timeout(300000). % set back

suspended_manager() ->
Port = start(gen_tcp, [fun simple_response/5, fun simple_response/5]),
URL = url(Port, "/persistent"),
Expand All @@ -401,8 +386,6 @@ suspended_manager() ->
true = erlang:suspend_process(Pid),
?assertEqual({error, timeout}, lhttpc:request(URL, get, [], 50)),
true = erlang:resume_process(Pid),
?assertEqual(1,
lhttpc_manager:connection_count({"localhost", Port, false})),
{ok, SecondResponse} = lhttpc:request(URL, get, [], 50),
?assertEqual({200, "OK"}, status(SecondResponse)),
?assertEqual(<<?DEFAULT_STRING>>, body(SecondResponse)).
Expand Down Expand Up @@ -484,7 +467,7 @@ partial_upload_chunked() ->
?assertEqual(<<?DEFAULT_STRING>>, body(Response1)),
?assertEqual("This is chunky stuff!",
lhttpc_lib:header_value("x-test-orig-body", headers(Response1))),
?assertEqual(element(2, Trailer),
?assertEqual(element(2, Trailer),
lhttpc_lib:header_value("x-test-orig-trailer-1", headers(Response1))),
% Make sure it works with no body part in the original request as well
Headers = [{"Transfer-Encoding", "chunked"}],
Expand All @@ -497,7 +480,7 @@ partial_upload_chunked() ->
?assertEqual(<<?DEFAULT_STRING>>, body(Response2)),
?assertEqual("This is chunky stuff!",
lhttpc_lib:header_value("x-test-orig-body", headers(Response2))),
?assertEqual(element(2, Trailer),
?assertEqual(element(2, Trailer),
lhttpc_lib:header_value("x-test-orig-trailer-1", headers(Response2))).

partial_upload_chunked_no_trailer() ->
Expand Down Expand Up @@ -681,10 +664,6 @@ ssl_chunked() ->
?assertEqual("2", lhttpc_lib:header_value("Trailer-2",
headers(SecondResponse))).

connection_count() ->
timer:sleep(50), % give the TCP stack time to deliver messages
?assertEqual(0, lhttpc_manager:connection_count()).

invalid_options() ->
?assertError({bad_options, [{foo, bar}, bad_option]},
lhttpc:request("http://localhost/", get, [], <<>>, 1000,
Expand Down

0 comments on commit 4af873c

Please sign in to comment.