Skip to content

Commit

Permalink
Fixes spurious test failure
Browse files Browse the repository at this point in the history
We need to spawn async pushes but need them to be in the right order.
There was a sleep that was supposed to do this.  I think the sleep was
actually outside the for comprehension.
  • Loading branch information
joekain committed Oct 5, 2016
1 parent f8c1ba3 commit 289f921
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/blocking_queue_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,16 @@ defmodule BlockingQueueTest do

test "BlockingQueue returns results to multiple push waiters in LIFO order" do
{:ok, pid} = BlockingQueue.start_link(1)
parent = self
range = 1..10
expected_result = Enum.into(range, [])

# tiny sleep included to make absolutely sure we spawn waiters in the right order
for item <- range, do: Task.async(fn -> BlockingQueue.push(pid, item) end); :timer.sleep 1
for item <- range do
Task.async(fn ->
BlockingQueue.push(pid, item)
end);
:timer.sleep 1
end

assert expected_result == Enum.into(range, [], fn _ -> BlockingQueue.pop(pid) end)
end
Expand Down

0 comments on commit 289f921

Please sign in to comment.