aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-04-30 17:09:21 +0200
committerLoïc Hoguin <[email protected]>2017-04-30 17:09:21 +0200
commit7a213b6a95357c5304e9d9a2a52930882bf8305e (patch)
tree9563c84b938618a76c78a99e2576599db13f5ee7
parente56fa6e8d6e99a0385977acee500193e04fc2a83 (diff)
downloadgun-7a213b6a95357c5304e9d9a2a52930882bf8305e.tar.gz
gun-7a213b6a95357c5304e9d9a2a52930882bf8305e.tar.bz2
gun-7a213b6a95357c5304e9d9a2a52930882bf8305e.zip
Add missing gun_SUITE test suite
Forgot to commit it earlier. My bad!
-rw-r--r--test/gun_SUITE.erl93
1 files changed, 93 insertions, 0 deletions
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl
new file mode 100644
index 0000000..c62c600
--- /dev/null
+++ b/test/gun_SUITE.erl
@@ -0,0 +1,93 @@
+%% Copyright (c) 2017, Loïc Hoguin <[email protected]>
+%%
+%% Permission to use, copy, modify, and/or distribute this software for any
+%% purpose with or without fee is hereby granted, provided that the above
+%% copyright notice and this permission notice appear in all copies.
+%%
+%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+-module(gun_SUITE).
+-compile(export_all).
+
+-import(ct_helper, [doc/1]).
+
+all() ->
+ ct_helper:all(?MODULE).
+
+connect_timeout(_) ->
+ doc("Ensure an integer value for connect_timeout is accepted."),
+ {ok, Pid} = gun:open("localhost", 12345, #{connect_timeout => 1000, retry => 0}),
+ Ref = monitor(process, Pid),
+ receive
+ {'DOWN', Ref, process, Pid, {gone, _}} ->
+ ok
+ after 5000 ->
+ error(timeout)
+ end.
+
+connect_timeout_infinity(_) ->
+ doc("Ensure infinity for connect_timeout is accepted."),
+ {ok, Pid} = gun:open("localhost", 12345, #{connect_timeout => infinity, retry => 0}),
+ Ref = monitor(process, Pid),
+ receive
+ {'DOWN', Ref, process, Pid, {gone, _}} ->
+ ok
+ after 5000 ->
+ error(timeout)
+ end.
+
+gone_reason(_) ->
+ doc("The last connection failure must be propagated."),
+ {ok, Pid} = gun:open("localhost", 12345, #{retry => 0}),
+ Ref = monitor(process, Pid),
+ receive
+ {'DOWN', Ref, process, Pid, {gone, econnrefused}} ->
+ ok
+ after 200 ->
+ error(timeout)
+ end.
+
+retry_0(_) ->
+ doc("Ensure Gun gives up immediately with retry=0."),
+ {ok, Pid} = gun:open("localhost", 12345, #{retry => 0, retry_timeout => 500}),
+ Ref = monitor(process, Pid),
+ receive
+ {'DOWN', Ref, process, Pid, {gone, _}} ->
+ ok
+ after 200 ->
+ error(timeout)
+ end.
+
+retry_1(_) ->
+ doc("Ensure Gun gives up with retry=1."),
+ {ok, Pid} = gun:open("localhost", 12345, #{retry => 1, retry_timeout => 500}),
+ Ref = monitor(process, Pid),
+ receive
+ {'DOWN', Ref, process, Pid, {gone, _}} ->
+ ok
+ after 700 ->
+ error(timeout)
+ end.
+
+retry_timeout(_) ->
+ doc("Ensure the retry_timeout value is enforced."),
+ {ok, Pid} = gun:open("localhost", 12345, #{retry => 1, retry_timeout => 1000}),
+ Ref = monitor(process, Pid),
+ receive
+ {'DOWN', Ref, process, Pid, {gone, _}} ->
+ error(gone_too_early)
+ after 800 ->
+ ok
+ end,
+ receive
+ {'DOWN', Ref, process, Pid, {gone, _}} ->
+ ok
+ after 400 ->
+ error(gone_too_late)
+ end.