Skip to content

Commit

Permalink
Add tests for socket drainer configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
studzien committed Aug 24, 2023
1 parent 06eaf9e commit 5904438
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/phoenix/socket/socket_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,49 @@ defmodule Phoenix.SocketTest do
assert socket.assigns[:abc] == :def
end
end

describe "drainer_spec/1" do
defmodule Endpoint do
use Phoenix.Endpoint, otp_app: :phoenix
end

defmodule DrainerSpecSocket do
use Phoenix.Socket

def id(_), do: "123"

def dynamic_drainer_config do
[
batch_size: 200,
batch_interval: 2_000,
shutdown: 20_000
]
end
end

test "loads static drainer config" do
drainer_spec = [
batch_size: 100,
batch_interval: 1_000,
shutdown: 10_000
]

assert DrainerSpecSocket.drainer_spec(drainer: drainer_spec, endpoint: Endpoint) ==
{Phoenix.Socket.PoolDrainer, {Endpoint, DrainerSpecSocket, drainer_spec}}
end

test "loads dynamic drainer config" do
drainer_spec = DrainerSpecSocket.dynamic_drainer_config()

assert DrainerSpecSocket.drainer_spec(
drainer: {DrainerSpecSocket, :dynamic_drainer_config, []},
endpoint: Endpoint
) ==
{Phoenix.Socket.PoolDrainer, {Endpoint, DrainerSpecSocket, drainer_spec}}
end

test "returns ignore if drainer is set to false" do
assert DrainerSpecSocket.drainer_spec(drainer: false, endpoint: Endpoint) == :ignore
end
end
end

0 comments on commit 5904438

Please sign in to comment.