mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-10 15:04:25 +08:00
Fix race condition in tests
This commit is contained in:
parent
e59f5b03e5
commit
4d10d4fa3a
1 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
defmodule Livebook.TestHelpers do
|
defmodule Livebook.TestHelpers do
|
||||||
import Phoenix.LiveViewTest
|
import Phoenix.LiveViewTest
|
||||||
|
import ExUnit.Assertions
|
||||||
|
|
||||||
alias Livebook.Session.Data
|
alias Livebook.Session.Data
|
||||||
|
|
||||||
|
@ -106,17 +107,20 @@ defmodule Livebook.TestHelpers do
|
||||||
def source_for_blocking() do
|
def source_for_blocking() do
|
||||||
name = Livebook.Utils.random_short_id() |> String.to_atom()
|
name = Livebook.Utils.random_short_id() |> String.to_atom()
|
||||||
|
|
||||||
|
Process.register(self(), name)
|
||||||
|
|
||||||
code =
|
code =
|
||||||
quote do
|
quote do
|
||||||
# This test uses the Embedded runtime, so we can target the
|
# We assume the test uses the Embedded runtime, so we can
|
||||||
# process by name
|
# target the process by name
|
||||||
Process.register(self(), unquote(name))
|
send(unquote(name), {:started, self()})
|
||||||
receive do: (:finish -> :ok)
|
receive do: (:finish -> :ok)
|
||||||
end
|
end
|
||||||
|> Macro.to_string()
|
|> Macro.to_string()
|
||||||
|
|
||||||
continue_fun = fn ->
|
continue_fun = fn ->
|
||||||
send(Process.whereis(name), :finish)
|
assert_receive {:started, pid}
|
||||||
|
send(pid, :finish)
|
||||||
end
|
end
|
||||||
|
|
||||||
{code, continue_fun}
|
{code, continue_fun}
|
||||||
|
|
Loading…
Add table
Reference in a new issue