From 6f75598b70801bbfb6828e5367bc7ed7477ad915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 13 Jun 2016 16:26:00 +0200 Subject: Fix chunked_hello_world example --- test/examples_SUITE.erl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/examples_SUITE.erl') diff --git a/test/examples_SUITE.erl b/test/examples_SUITE.erl index 046f2fe..40a8b9c 100644 --- a/test/examples_SUITE.erl +++ b/test/examples_SUITE.erl @@ -106,6 +106,35 @@ do_hello_world(Transport, Protocol, Config) -> {200, _, <<"Hello world!">>} = do_get(Transport, Protocol, "/", Config), ok. +%% Chunked Hello World. + +chunked_hello_world(Config) -> + doc("Chunked Hello World example."), + try + do_compile_and_start(chunked_hello_world), + do_chunked_hello_world(tcp, http, Config), + do_chunked_hello_world(tcp, http2, Config) + after + do_stop(chunked_hello_world) + end. + +do_chunked_hello_world(Transport, Protocol, Config) -> + ConnPid = gun_open([{port, 8080}, {type, Transport}, {protocol, Protocol}|Config]), + Ref = gun:get(ConnPid, "/"), + {response, nofin, 200, _} = gun:await(ConnPid, Ref), + %% We expect to receive a chunk every second, three total. + {data, nofin, <<"Hello\r\n">>} = gun:await(ConnPid, Ref, 2000), + {data, nofin, <<"World\r\n">>} = gun:await(ConnPid, Ref, 2000), + {data, IsFin, <<"Chunked!\r\n">>} = gun:await(ConnPid, Ref, 2000), + %% We may get an extra empty chunk (last chunk for HTTP/1.1, + %% empty DATA frame with the FIN bit set for HTTP/2). + case IsFin of + fin -> ok; + nofin -> + {data, fin, <<>>} = gun:await(ConnPid, Ref, 500), + ok + end. + %% Echo GET. echo_get(Config) -> -- cgit v1.2.3