@@ -420,27 +420,32 @@ defmodule Plug.ConnTest do
420
420
|> send_chunked ( 200 )
421
421
|> chunk ( "CHUNK" )
422
422
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
425
429
end
426
430
427
431
test "chunk/2 uses the updated conn from before_chunk callbacks" do
428
432
pid = self ( )
429
433
430
434
conn =
431
435
conn ( :get , "/foo" )
436
+ |> assign ( :test_counter , 0 )
432
437
|> 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 } )
434
439
send ( pid , { :before_chunk , count } )
435
440
conn
436
441
end )
437
442
|> send_chunked ( 200 )
438
443
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" )
442
447
443
- assert_received { :before_chunk , nil }
448
+ assert_received { :before_chunk , 0 }
444
449
assert_received { :before_chunk , 1 }
445
450
assert_received { :before_chunk , 2 }
446
451
end
0 commit comments