Skip to content

Commit 71f37c9

Browse files
committed
Slightly improve some tests
1 parent 8bff7c1 commit 71f37c9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

test/plug/conn_test.exs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,27 +420,32 @@ defmodule Plug.ConnTest do
420420
|> send_chunked(200)
421421
|> chunk("CHUNK")
422422

423-
assert_received {:before_chunk, 2, "CHUNK"}
424-
assert_received {:before_chunk, 1, "CHUNK"}
423+
# We need to match with n1 and n2 because if we match directly on 1 and 2 then
424+
# selective receive will match on the messages even if they're out of order.
425+
assert_receive {:before_chunk, n1, "CHUNK"}
426+
assert_receive {:before_chunk, n2, "CHUNK"}
427+
assert n1 == 2
428+
assert n2 == 1
425429
end
426430

427431
test "chunk/2 uses the updated conn from before_chunk callbacks" do
428432
pid = self()
429433

430434
conn =
431435
conn(:get, "/foo")
436+
|> assign(:test_counter, 0)
432437
|> register_before_chunk(fn conn, _chunk ->
433-
{count, conn} = get_and_update_in(conn.assigns[:test_counter], &{&1, (&1 || 0) + 1})
438+
{count, conn} = get_and_update_in(conn.assigns[:test_counter], &{&1, &1 + 1})
434439
send(pid, {:before_chunk, count})
435440
conn
436441
end)
437442
|> send_chunked(200)
438443

439-
{:ok, conn} = chunk(conn, "CHUNK")
440-
{:ok, conn} = chunk(conn, "CHUNK")
441-
{:ok, _} = chunk(conn, "CHUNK")
444+
assert {:ok, conn} = chunk(conn, "CHUNK")
445+
assert {:ok, conn} = chunk(conn, "CHUNK")
446+
assert {:ok, _conn} = chunk(conn, "CHUNK")
442447

443-
assert_received {:before_chunk, nil}
448+
assert_received {:before_chunk, 0}
444449
assert_received {:before_chunk, 1}
445450
assert_received {:before_chunk, 2}
446451
end

0 commit comments

Comments
 (0)