Skip to content

Commit 2a78a5b

Browse files
authored
Run HTTP/2 integration tests against local Caddy instead of nghttp2.org (#482)
* Run HTTP/2 integration tests against local Caddy instead of nghttp2.org The tests hitting nghttp2.org/httpbin/ had been failing on every CI run because the upstream httpbin backend behind nghttpx returns 502 to GitHub Actions runners. Enable h2c on the Caddy docker service (via a new HTTPBIN_H2C_PORT, default 8081, since the existing HTTPBIN_HTTP_PORT mapping goes directly to httpbin), point the TCP h2c test at it, and drop the duplicate "nghttp2.org/httpbin" describe block (ping and GET are already covered by the local "httpbin.org" block). * Fix stray :ssl message leak in HTTP/2 integration tests The twitter.com describe block was using @moduletag instead of @describetag, which made its connect: {"twitter.com", 443} tag apply to the whole module. That caused the top-level setup to open an HTTPS connection to twitter.com even for tests outside the describe (like the TCP h2c test), and the SSL socket's SETTINGS frame would land in the test mailbox. The previous test had a swallow-hack comment about "SSL messages sneaking in"; this removes the root cause.
1 parent 0bfcc86 commit 2a78a5b

5 files changed

Lines changed: 13 additions & 35 deletions

File tree

Caddyfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
local_certs
33
skip_install_trust
44
storage file_system /caddy_storage
5+
servers :{$HTTPBIN_HTTP_PORT:8080} {
6+
protocols h1 h2c
7+
}
58
}
69

710
https://localhost:{$HTTPBIN_HTTPS_PORT:8443} {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ TINYPROXY_PORT=8887 docker compose up --detach
141141
TINYPROXY_PORT=8887 mix test --include proxy
142142
```
143143

144-
Available port variables: `TINYPROXY_PORT` (default 8888), `TINYPROXY_AUTH_PORT` (default 8889), `HTTPBIN_HTTP_PORT` (default 8080), `HTTPBIN_HTTPS_PORT` (default 8443).
144+
Available port variables: `TINYPROXY_PORT` (default 8888), `TINYPROXY_AUTH_PORT` (default 8889), `HTTPBIN_HTTP_PORT` (default 8080), `HTTPBIN_HTTPS_PORT` (default 8443), `HTTPBIN_H2C_PORT` (default 8081).
145145

146146
## License
147147

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ services:
3434
- "./Caddyfile:/etc/caddy/Caddyfile:z"
3535
ports:
3636
- "${HTTPBIN_HTTPS_PORT:-8443}:${HTTPBIN_HTTPS_PORT:-8443}"
37+
- "${HTTPBIN_H2C_PORT:-8081}:${HTTPBIN_HTTP_PORT:-8080}"

test/mint/http2/integration_test.exs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ defmodule HTTP2.IntegrationTest do
3232
end
3333
end
3434

35-
test "TCP - nghttp2.org" do
36-
assert {:ok, %HTTP2{} = conn} = HTTP2.connect(:http, "nghttp2.org", 80)
35+
test "TCP - h2c prior knowledge" do
36+
assert {:ok, %HTTP2{} = conn} = HTTP2.connect(:http, HttpBin.host(), HttpBin.h2c_port())
3737

38-
assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/httpbin/", [], nil)
39-
40-
# For some reason, we get an SSL message sneaking in here. Instead of going
41-
# crazy trying to debug it, for now let's just swallow it.
42-
assert_receive {:ssl, _socket, _data}, 1000
38+
assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/", [], nil)
4339

4440
assert {:ok, %HTTP2{} = conn, responses} = receive_stream(conn)
4541

@@ -105,7 +101,7 @@ defmodule HTTP2.IntegrationTest do
105101
end
106102

107103
describe "twitter.com" do
108-
@moduletag connect: {"twitter.com", 443}
104+
@describetag connect: {"twitter.com", 443}
109105
@browser_user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
110106

111107
test "ping", %{conn: conn} do
@@ -159,32 +155,6 @@ defmodule HTTP2.IntegrationTest do
159155
end
160156
end
161157

162-
describe "nghttp2.org/httpbin" do
163-
@describetag connect: {"nghttp2.org", 443}
164-
165-
test "ping", %{conn: conn} do
166-
assert {:ok, %HTTP2{} = conn, ref} = HTTP2.ping(conn)
167-
assert {:ok, %HTTP2{} = conn, [{:pong, ^ref}]} = receive_stream(conn)
168-
assert conn.buffer == ""
169-
assert HTTP2.open?(conn)
170-
end
171-
172-
test "GET /", %{conn: conn} do
173-
assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/httpbin/", [], nil)
174-
175-
assert {:ok, %HTTP2{} = conn, responses} = receive_stream(conn)
176-
177-
assert [{:status, ^ref, status}, {:headers, ^ref, headers} | rest] = responses
178-
assert {_, [{:done, ^ref}]} = Enum.split_while(rest, &match?({:data, ^ref, _}, &1))
179-
180-
assert status == 200
181-
assert is_list(headers)
182-
183-
assert conn.buffer == ""
184-
assert HTTP2.open?(conn)
185-
end
186-
end
187-
188158
describe "robynthinks.wordpress.com" do
189159
@describetag connect: {"robynthinks.wordpress.com", 443}
190160

test/support/mint/http_bin.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ defmodule Mint.HttpBin do
1717
get_env_port("HTTPBIN_HTTPS_PORT", 8443)
1818
end
1919

20+
def h2c_port() do
21+
get_env_port("HTTPBIN_H2C_PORT", 8081)
22+
end
23+
2024
def proxy_port() do
2125
get_env_port("TINYPROXY_PORT", 8888)
2226
end

0 commit comments

Comments
 (0)