Skip to content

Fix all integration tests #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ iex> flush()

Users are not supposed to examine these messages. Instead, Mint provides a `stream/2` function that turns messages into HTTP responses. Mint streams responses back to the user in parts through response parts such as `:status`, `:headers`, `:data`, and `:done`.


```elixir
iex> {:ok, conn} = Mint.HTTP.connect(:https, "httpbin.org", 443)
iex> {:ok, conn, request_ref} = Mint.HTTP.request(conn, "GET", "/", [], "")
Expand Down Expand Up @@ -151,7 +150,6 @@ Copyright 2018 Eric Meadows-Jönsson and Andrea Leopardi
See the License for the specific language governing permissions and
limitations under the License.

[castore]: https://github.com/elixir-mint/castore
[documentation]: https://hexdocs.pm/mint
[issues]: https://github.com/elixir-mint/mint/issues
[mint_web_socket]: https://github.com/elixir-mint/mint_web_socket
Expand Down
2 changes: 1 addition & 1 deletion test/mint/http1/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ defmodule Mint.HTTP1.IntegrationTest do
HTTP1.connect(
:https,
"localhost",
8443,
Mint.HttpBin.https_port(),
transport_opts: [cacerts: [], log_alert: false, reuse_sessions: false]
)

Expand Down
84 changes: 2 additions & 82 deletions test/mint/http2/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -77,80 +77,22 @@ defmodule HTTP2.IntegrationTest do
assert conn.buffer == ""
assert HTTP2.open?(conn)
end
end

describe "http2.golang.org" do
@describetag skip: """
http2.golang.org has been decommisioned.
Re-enable these tests in the future if we figure out a test server that supports
a similar set of features.
"""

test "GET /clockstream", %{conn: conn} do
assert {:ok, %HTTP2{} = conn, req_id} = HTTP2.request(conn, "GET", "/clockstream", [], nil)

assert {:ok, %HTTP2{} = conn, responses} = stream_messages_until_response(conn)
assert [{:status, ^req_id, 200}, {:headers, ^req_id, _headers} | rest] = responses

conn =
if rest != [] do
assert [{:data, ^req_id, data}] = rest
assert data =~ "# ~1KB of junk to force browsers to start rendering immediately"
conn
else
assert_receive message, 5000
assert {:ok, %HTTP2{} = conn, responses} = HTTP2.stream(conn, message)
assert [{:data, ^req_id, data}] = responses
assert data =~ "# ~1KB of junk to force browsers to start rendering immediately"
conn
end

assert_receive message, 5000
assert {:ok, %HTTP2{} = conn, responses} = HTTP2.stream(conn, message)
assert [{:data, ^req_id, data}] = responses
assert data =~ ~r/\A\d{4}-\d{2}-\d{2}/

assert HTTP2.open?(conn)
end

test "PUT /ECHO", %{conn: conn} do
assert {:ok, %HTTP2{} = conn, req_id} =
HTTP2.request(conn, "PUT", "/ECHO", [], "hello world")

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

assert [
{:status, ^req_id, 200},
{:headers, ^req_id, headers},
{:data, ^req_id, data},
{:data, ^req_id, ""},
{:done, ^req_id}
] = responses

assert is_list(headers)
assert data == "HELLO WORLD"

assert conn.buffer == ""
assert HTTP2.open?(conn)
end

test "GET /file/gopher.png", %{conn: conn} do
assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/file/gopher.png", [], nil)
test "GET /image/png", %{conn: conn} do
assert {:ok, %HTTP2{} = conn, ref} = HTTP2.request(conn, "GET", "/image/png", [], nil)
assert {:ok, %HTTP2{} = conn, responses} = receive_stream(conn)

assert [
{:status, ^ref, 200},
{:headers, ^ref, headers},
{:data, ^ref, data1},
{:data, ^ref, data2},
{:data, ^ref, data3},
{:done, ^ref}
] = responses

assert is_list(headers)
assert is_binary(data1)
assert is_binary(data2)
assert is_binary(data3)

assert conn.buffer == ""
assert HTTP2.open?(conn)
Expand All @@ -162,19 +104,6 @@ defmodule HTTP2.IntegrationTest do
assert conn.buffer == ""
assert HTTP2.open?(conn)
end

test "GET /serverpush", %{conn: conn} do
assert {:ok, %HTTP2{} = conn, req_id} = HTTP2.request(conn, "GET", "/serverpush", [], nil)
assert {:ok, %HTTP2{} = _conn, responses} = receive_stream(conn)

# TODO: improve this test by improving receive_stream/1.
assert [
{:push_promise, ^req_id, _promised_req_id1, _headers1},
{:push_promise, ^req_id, _promised_req_id2, _headers2},
{:push_promise, ^req_id, _promised_req_id3, _headers3},
{:push_promise, ^req_id, _promised_req_id4, _headers4} | _
] = responses
end
end

describe "twitter.com" do
Expand Down Expand Up @@ -329,14 +258,5 @@ defmodule HTTP2.IntegrationTest do
end
end

defp stream_messages_until_response(conn) do
assert_receive message, 1000

case HTTP2.stream(conn, message) do
{:ok, %HTTP2{} = conn, []} -> stream_messages_until_response(conn)
other -> other
end
end

# TODO: certificate verification; badssl.com does not seem to support HTTP2
end
15 changes: 11 additions & 4 deletions test/mint/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ defmodule Mint.IntegrationTest do

describe "nghttp2.org" do
test "SSL - select HTTP1" do
assert {:ok, conn} = HTTP.connect(:https, "nghttp2.org", 443, protocols: [:http1])
assert {:ok, conn} =
HTTP.connect(:https, HttpBin.host(), HttpBin.https_port(),
transport_opts: HttpBin.https_transport_opts(),
protocols: [:http1]
)

assert conn.__struct__ == Mint.HTTP1
assert {:ok, conn, request} = HTTP.request(conn, "GET", "/httpbin/bytes/1", [], nil)
assert {:ok, conn, request} = HTTP.request(conn, "GET", "/bytes/1", [], nil)
assert {:ok, _conn, responses} = receive_stream(conn)

assert [
Expand All @@ -24,10 +28,13 @@ defmodule Mint.IntegrationTest do
end

test "SSL - select HTTP2" do
assert {:ok, conn} = HTTP.connect(:https, "nghttp2.org", 443)
assert {:ok, conn} =
HTTP.connect(:https, HttpBin.host(), HttpBin.https_port(),
transport_opts: HttpBin.https_transport_opts()
)

assert conn.__struct__ == Mint.HTTP2
assert {:ok, conn, request} = HTTP.request(conn, "GET", "/httpbin/bytes/1", [], nil)
assert {:ok, conn, request} = HTTP.request(conn, "GET", "/bytes/1", [], nil)
assert {:ok, _conn, responses} = receive_stream(conn)

assert [
Expand Down
2 changes: 1 addition & 1 deletion test/mint/unix_socket_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Mint.UnitSocketTest do
defmodule Mint.UnixSocketTest do
use ExUnit.Case, async: true

alias Mint.{HTTP, TestSocketServer}
Expand Down
Loading