aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-03-28 15:19:42 +0100
committerLoïc Hoguin <[email protected]>2020-03-28 15:19:42 +0100
commitdf741e7107f53bb2275b1948de9599185b26205b (patch)
treefc311efa5e93f68983307fbffa6ce0f6d37b77da
parenta4ed628cec0aeb53acecf431ec73de6f698e7d5e (diff)
downloadgun-df741e7107f53bb2275b1948de9599185b26205b.tar.gz
gun-df741e7107f53bb2275b1948de9599185b26205b.tar.bz2
gun-df741e7107f53bb2275b1948de9599185b26205b.zip
Use gun_test:init_origin/3 in the gun_SUITE:reply_to_* tests
-rw-r--r--test/gun_SUITE.erl77
1 files changed, 35 insertions, 42 deletions
diff --git a/test/gun_SUITE.erl b/test/gun_SUITE.erl
index 4794505..fcdc9dc 100644
--- a/test/gun_SUITE.erl
+++ b/test/gun_SUITE.erl
@@ -233,55 +233,48 @@ reply_to_http2(_) ->
do_reply_to(http2).
do_reply_to(Protocol) ->
- {ok, ListenSocket} = gen_tcp:listen(0, [binary, {active, false}, {nodelay, true}]),
- {ok, {_, Port}} = inet:sockname(ListenSocket),
- Self = self(),
- {ok, Pid} = gun:open("localhost", Port, #{protocols => [Protocol]}),
- {ok, ClientSocket} = gen_tcp:accept(ListenSocket, 5000),
- ok = case Protocol of
- http -> ok;
- http2 ->
- {ok, _} = gen_tcp:recv(ClientSocket, 0, 5000),
- gen_tcp:send(ClientSocket, [
- <<0:24, 4:8, 0:40>>, %% Empty SETTINGS frame.
- <<0:24, 4:8, 1:8, 0:32>> %% SETTINGS ack.
- ])
- end,
+ {ok, OriginPid, OriginPort} = init_origin(tcp, Protocol,
+ fun(_, ClientSocket, ClientTransport) ->
+ {ok, _} = ClientTransport:recv(ClientSocket, 0, infinity),
+ ResponseData = case Protocol of
+ http ->
+ "HTTP/1.1 200 OK\r\n"
+ "Content-length: 12\r\n"
+ "\r\n"
+ "Hello world!";
+ http2 ->
+ %% Send a HEADERS frame with PRIORITY back.
+ {HeadersBlock, _} = cow_hpack:encode([
+ {<<":status">>, <<"200">>}
+ ]),
+ Len = iolist_size(HeadersBlock),
+ [
+ <<Len:24, 1:8,
+ 0:2, %% Undefined.
+ 0:1, %% PRIORITY.
+ 0:1, %% Undefined.
+ 0:1, %% PADDED.
+ 1:1, %% END_HEADERS.
+ 0:1, %% Undefined.
+ 1:1, %% END_STREAM.
+ 0:1, 1:31>>,
+ HeadersBlock
+ ]
+ end,
+ ok = ClientTransport:send(ClientSocket, ResponseData),
+ timer:sleep(1000)
+ end),
+ {ok, Pid} = gun:open("localhost", OriginPort, #{protocols => [Protocol]}),
{ok, Protocol} = gun:await_up(Pid),
+ handshake_completed = receive_from(OriginPid),
+ Self = self(),
ReplyTo = spawn(fun() ->
- receive Ref ->
+ receive Ref when is_reference(Ref) ->
Response = gun:await(Pid, Ref, infinity),
Self ! Response
end
end),
Ref = gun:get(Pid, "/", [], #{reply_to => ReplyTo}),
- {ok, _} = gen_tcp:recv(ClientSocket, 0, 5000),
- ResponseData = case Protocol of
- http ->
- "HTTP/1.1 200 OK\r\n"
- "Content-length: 12\r\n"
- "\r\n"
- "Hello world!";
- http2 ->
- %% Send a HEADERS frame with PRIORITY back.
- {HeadersBlock, _} = cow_hpack:encode([
- {<<":status">>, <<"200">>}
- ]),
- Len = iolist_size(HeadersBlock),
- [
- <<Len:24, 1:8,
- 0:2, %% Undefined.
- 0:1, %% PRIORITY.
- 0:1, %% Undefined.
- 0:1, %% PADDED.
- 1:1, %% END_HEADERS.
- 0:1, %% Undefined.
- 1:1, %% END_STREAM.
- 0:1, 1:31>>,
- HeadersBlock
- ]
- end,
- ok = gen_tcp:send(ClientSocket, ResponseData),
ReplyTo ! Ref,
receive
Msg ->