diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbdbf67..b1b06c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,4 +44,23 @@ jobs: - run: mix compile --warnings-as-errors if: ${{ matrix.lint }} + - run: mix test + test_cowboy_latest: + runs-on: ubuntu-20.04 + env: + MIX_ENV: test + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v2 + + - uses: erlef/setup-beam@v1 + with: + otp-version: 24.2.2 + elixir-version: 1.13.3 + + - run: mix deps.unlock cowboy cowlib ranch && mix deps.get --only test + + - run: mix deps.compile + - run: mix test diff --git a/lib/plug/cowboy/translator.ex b/lib/plug/cowboy/translator.ex index 169b202..740af6c 100644 --- a/lib/plug/cowboy/translator.ex +++ b/lib/plug/cowboy/translator.ex @@ -1,6 +1,7 @@ defmodule Plug.Cowboy.Translator do @moduledoc false + # Cowboy 2.12.0 and below error format @doc """ The `translate/4` function expected by custom Logger translators. """ @@ -14,6 +15,17 @@ defmodule Plug.Cowboy.Translator do translate_ranch(min_level, ref, extra, stream_pid, reason, stack) end + # Cowboy 2.13.0 error format + def translate( + min_level, + :error, + :format, + {~c"Ranch listener" ++ _, [ref, conn_pid, stream_id, stream_pid, {reason, stack}]} + ) do + extra = [" (connection ", inspect(conn_pid), ", stream id ", inspect(stream_id), ?)] + translate_ranch(min_level, ref, extra, stream_pid, reason, stack) + end + def translate(_min_level, _level, _kind, _data) do :none end diff --git a/test/plug/cowboy_test.exs b/test/plug/cowboy_test.exs index 7bb9199..e5ea59c 100644 --- a/test/plug/cowboy_test.exs +++ b/test/plug/cowboy_test.exs @@ -13,12 +13,11 @@ defmodule Plug.CowboyTest do test "supports Elixir child specs" do spec = {Plug.Cowboy, [scheme: :http, plug: __MODULE__, port: 4040]} + ranch_listener_mod = ranch_listener_for_version() + assert %{ - id: {:ranch_listener_sup, Plug.CowboyTest.HTTP}, - modules: [:ranch_listener_sup], - restart: :permanent, - shutdown: :infinity, - start: {:ranch_listener_sup, :start_link, _}, + id: {^ranch_listener_mod, Plug.CowboyTest.HTTP}, + start: {^ranch_listener_mod, :start_link, _}, type: :supervisor } = Supervisor.child_spec(spec, []) @@ -26,11 +25,8 @@ defmodule Plug.CowboyTest do spec = {Plug.Cowboy, [scheme: :http, plug: __MODULE__, options: [port: 4040]]} assert %{ - id: {:ranch_listener_sup, Plug.CowboyTest.HTTP}, - modules: [:ranch_listener_sup], - restart: :permanent, - shutdown: :infinity, - start: {:ranch_listener_sup, :start_link, _}, + id: {^ranch_listener_mod, Plug.CowboyTest.HTTP}, + start: {^ranch_listener_mod, :start_link, _}, type: :supervisor } = Supervisor.child_spec(spec, []) @@ -39,11 +35,8 @@ defmodule Plug.CowboyTest do [scheme: :http, plug: __MODULE__, parent: :key, options: [:inet6, port: 4040]]} assert %{ - id: {:ranch_listener_sup, Plug.CowboyTest.HTTP}, - modules: [:ranch_listener_sup], - restart: :permanent, - shutdown: :infinity, - start: {:ranch_listener_sup, :start_link, _}, + id: {^ranch_listener_mod, Plug.CowboyTest.HTTP}, + start: {^ranch_listener_mod, :start_link, _}, type: :supervisor } = Supervisor.child_spec(spec, []) end @@ -58,7 +51,8 @@ defmodule Plug.CowboyTest do spec = {Plug.Cowboy, [scheme: :https, plug: __MODULE__] ++ options} - %{start: {:ranch_listener_sup, :start_link, opts}} = Supervisor.child_spec(spec, []) + ranch_listener_mod = ranch_listener_for_version() + %{start: {^ranch_listener_mod, :start_link, opts}} = Supervisor.child_spec(spec, []) assert [ Plug.CowboyTest.HTTPS, @@ -178,13 +172,19 @@ defmodule Plug.CowboyTest do end test "builds child specs" do + ranch_listener_mod = ranch_listener_for_version() + assert %{ - id: {:ranch_listener_sup, Plug.CowboyTest.HTTP}, - modules: [:ranch_listener_sup], - start: {:ranch_listener_sup, :start_link, _}, - restart: :permanent, - shutdown: :infinity, + id: {^ranch_listener_mod, Plug.CowboyTest.HTTP}, + start: {^ranch_listener_mod, :start_link, _}, type: :supervisor } = child_spec(scheme: :http, plug: __MODULE__, options: []) end + + defp ranch_listener_for_version() do + case Version.parse!("#{Application.spec(:ranch, :vsn)}") |> Version.compare("2.2.0") do + :lt -> :ranch_listener_sup + _ -> :ranch_embedded_sup + end + end end