Skip to content

Commit 82eb220

Browse files
committed
Do not rely on all DOWN messages being delivered simultaniously
1 parent 4280765 commit 82eb220

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

test/plug/upload_test.exs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ defmodule Plug.UploadTest do
2020

2121
receive do
2222
{:DOWN, ^ref, :process, ^pid, :normal} ->
23-
{:ok, _} = Plug.Upload.random_file("sample")
24-
refute File.exists?(path)
23+
wait_until(fn -> not File.exists?(path) end)
24+
end
25+
end
26+
27+
defp wait_until(fun) do
28+
if fun.() do
29+
:ok
30+
else
31+
Process.sleep(50)
32+
wait_until(fun)
2533
end
2634
end
2735

@@ -82,31 +90,17 @@ defmodule Plug.UploadTest do
8290

8391
receive do
8492
{:DOWN, ^ref, :process, ^pid, :normal} ->
85-
{:ok, _} = Plug.Upload.random_file("sample")
86-
93+
wait_until(fn -> not File.exists?(path3) end)
8794
assert File.exists?(path1)
8895
assert File.exists?(path2)
89-
refute File.exists?(path3)
9096
end
9197

9298
send(other_pid, :exit)
9399

94100
receive do
95101
{:DOWN, ^other_ref, :process, ^other_pid, :normal} ->
96-
# force sync by creating file in unknown process
97-
parent = self()
98-
99-
spawn(fn ->
100-
{:ok, _} = Plug.Upload.random_file("sample")
101-
send(parent, :continue)
102-
end)
103-
104-
receive do
105-
:continue -> :ok
106-
end
107-
108-
refute File.exists?(path1)
109-
refute File.exists?(path2)
102+
wait_until(fn -> not File.exists?(path1) end)
103+
wait_until(fn -> not File.exists?(path2) end)
110104
end
111105
end
112106

@@ -158,20 +152,8 @@ defmodule Plug.UploadTest do
158152

159153
receive do
160154
{:DOWN, ^other_ref, :process, ^other_pid, :normal} ->
161-
# force sync by creating file in unknown process
162-
parent = self()
163-
164-
spawn(fn ->
165-
{:ok, _} = Plug.Upload.random_file("sample")
166-
send(parent, :continue)
167-
end)
168-
169-
receive do
170-
:continue -> :ok
171-
end
172-
173-
refute File.exists?(path)
174-
refute File.exists?(path1)
155+
wait_until(fn -> not File.exists?(path) end)
156+
wait_until(fn -> not File.exists?(path1) end)
175157
end
176158
end
177159
end

0 commit comments

Comments
 (0)