aboutsummaryrefslogtreecommitdiffstats
path: root/test/sendfile_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-08-17 16:52:46 +0200
committerLoïc Hoguin <[email protected]>2015-08-17 16:52:46 +0200
commitf5f480c5750b76b662430b62ef85ebceea5aadc6 (patch)
tree17cb06d0e11f571bc625707eeb6f83efe8028b5c /test/sendfile_SUITE.erl
parent5ea28fb44629eb217fee2a1e8fcd0bb47dde1034 (diff)
downloadranch-f5f480c5750b76b662430b62ef85ebceea5aadc6.tar.gz
ranch-f5f480c5750b76b662430b62ef85ebceea5aadc6.tar.bz2
ranch-f5f480c5750b76b662430b62ef85ebceea5aadc6.zip
Beginnings of modernizing the test suite
Merging because I have to do other work but this is still a nice enough improvement.
Diffstat (limited to 'test/sendfile_SUITE.erl')
-rw-r--r--test/sendfile_SUITE.erl100
1 files changed, 40 insertions, 60 deletions
diff --git a/test/sendfile_SUITE.erl b/test/sendfile_SUITE.erl
index c74659e..b067ded 100644
--- a/test/sendfile_SUITE.erl
+++ b/test/sendfile_SUITE.erl
@@ -13,29 +13,10 @@
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-module(sendfile_SUITE).
+-compile(export_all).
--include_lib("common_test/include/ct.hrl").
-
-%% ct.
--export([all/0]).
--export([suite/0]).
--export([groups/0]).
--export([init_per_suite/1]).
--export([end_per_suite/1]).
--export([init_per_group/2]).
--export([end_per_group/2]).
-
-%% Tests.
--export([filename/1]).
--export([rawfile/1]).
--export([rawfile_bytes_large/1]).
--export([rawfile_bytes_zero/1]).
--export([rawfile_chunk_size_large/1]).
--export([rawfile_offset_large/1]).
--export([rawfile_range_large/1]).
--export([rawfile_range_medium/1]).
--export([rawfile_range_small/1]).
--export([ssl_chunk_size/1]).
+-import(ct_helper, [config/2]).
+-import(ct_helper, [doc/1]).
all() ->
[{group, tcp}, {group, ssl}].
@@ -58,42 +39,30 @@ groups() ->
[{tcp, [parallel], Tests}, {ssl, [parallel], Tests ++ [ssl_chunk_size]}].
init_per_suite(Config) ->
- ok = application:start(ranch),
- ok = application:start(crypto),
- Filename = filename:join(?config(priv_dir, Config), "sendfile"),
+ Filename = filename:join(config(priv_dir, Config), "sendfile"),
Binary = crypto:rand_bytes(20 * 1024 * 1024),
ok = file:write_file(Filename, Binary),
[{filename, Filename} | Config].
end_per_suite(Config) ->
- application:stop(ranch),
- application:stop(crypto),
- Filename = ?config(filename, Config),
+ Filename = config(filename, Config),
ok = file:delete(Filename),
ok.
init_per_group(ssl, Config) ->
- application:start(asn1),
- application:start(public_key),
- application:start(ssl),
- {_, Cert, Key} = ct_helper:make_certs(),
- SslOpts = [{cert, Cert}, {key, Key}],
+ SslOpts = ct_helper:get_certs_from_ets(),
[{transport, ranch_ssl}, {transport_opts, SslOpts} | Config];
init_per_group(tcp, Config) ->
[{transport, ranch_tcp}, {transport_opts, []} | Config].
-end_per_group(ssl, _) ->
- application:stop(ssl),
- application:stop(public_key),
- application:stop(asn1),
- ok;
end_per_group(_, _) ->
ok.
%% Check can send a whole file given with filename.
+
filename(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
{ok, {Server, Client}} = sockets(Config),
@@ -105,9 +74,10 @@ filename(Config) ->
ok = Transport:close(Server).
%% Check can send a whole file with rawfile.
+
rawfile(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
{ok, {Server, Client}} = sockets(Config),
@@ -122,9 +92,10 @@ rawfile(Config) ->
ok = Transport:close(Server).
%% Check can send a file where Bytes is larger than file size.
+
rawfile_bytes_large(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
{ok, {Server, Client}} = sockets(Config),
@@ -140,9 +111,10 @@ rawfile_bytes_large(Config) ->
ok = Transport:close(Server).
%% Check can send whole file when Bytes =:= 0.
+
rawfile_bytes_zero(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
{ok, {Server, Client}} = sockets(Config),
@@ -157,9 +129,10 @@ rawfile_bytes_zero(Config) ->
ok = Transport:close(Server).
%% Check can send file where chunk_size is greater than file size.
+
rawfile_chunk_size_large(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
{ok, {Server, Client}} = sockets(Config),
@@ -176,9 +149,10 @@ rawfile_chunk_size_large(Config) ->
%% Check send file where offset is larger than file size sends no bytes and
%% returns {ok, 0}.
+
rawfile_offset_large(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
{ok, {Server, Client}} = sockets(Config),
@@ -191,9 +165,10 @@ rawfile_offset_large(Config) ->
%% Check can send file with positive Offset and Offset + Bytes larger than file
%% size.
+
rawfile_range_large(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
{ok, {Server, Client}} = sockets(Config),
@@ -215,9 +190,10 @@ rawfile_range_large(Config) ->
%% Check can send file with positive Offset and Offset + Bytes less than file
%% size.
+
rawfile_range_medium(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
{ok, {Server, Client}} = sockets(Config),
@@ -238,9 +214,10 @@ rawfile_range_medium(Config) ->
%% Check can send file with positive Offset, Offset + Bytes less than file
%% size and Bytes less than chunk_size.
+
rawfile_range_small(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
{ok, {Server, Client}} = sockets(Config),
{ok, RawFile} = file:open(Filename, [read, raw, binary]),
@@ -260,9 +237,10 @@ rawfile_range_small(Config) ->
ok = Transport:close(Server).
%% Check ssl obeys chunk_size.
+
ssl_chunk_size(Config) ->
- Transport = ?config(transport, Config),
- Filename = ?config(filename, Config),
+ Transport = config(transport, Config),
+ Filename = config(filename, Config),
{ok, Binary} = file:read_file(Filename),
Size = byte_size(Binary),
Self = self(),
@@ -292,9 +270,11 @@ ssl_chunk_size(Config) ->
_ = erlang:trace(all, false, [all]),
ok = clean_traces().
+%% Internal.
+
sockets(Config) ->
- Transport = ?config(transport, Config),
- TransportOpts = ?config(transport_opts, Config),
+ Transport = config(transport, Config),
+ TransportOpts = config(transport_opts, Config),
{ok, LSocket} = Transport:listen(TransportOpts),
{ok, {_, Port}} = Transport:sockname(LSocket),
Self = self(),