Fix race conditions in tests (#1031)

* Fix race conditions in tests

* Format

* Increase session import redirect timeout

* Increase intellisense timeout
This commit is contained in:
Jonatan Kłosko 2022-02-28 22:27:39 +01:00 committed by GitHub
parent f11b9d50c9
commit f58f9609d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View file

@ -245,8 +245,6 @@ defmodule LivebookWeb.HomeLiveTest do
describe "notebook import" do
test "allows importing notebook directly from content", %{conn: conn} do
Phoenix.PubSub.subscribe(Livebook.PubSub, "tracker_sessions")
{:ok, view, _} = live(conn, "/home/import/content")
notebook_content = """
@ -257,9 +255,9 @@ defmodule LivebookWeb.HomeLiveTest do
|> element("form", "Import")
|> render_submit(%{data: %{content: notebook_content}})
assert_receive {:session_created, %{id: id, notebook_name: "My notebook"}}
{path, _flash} = assert_redirect(view, 1000)
{:ok, view, _} = live(conn, "/sessions/#{id}")
{:ok, view, _} = live(conn, path)
assert render(view) =~ "My notebook"
end
@ -274,7 +272,7 @@ defmodule LivebookWeb.HomeLiveTest do
|> element("form", "Import")
|> render_submit(%{data: %{content: notebook_content}})
{_path, flash} = assert_redirect(view)
{_path, flash} = assert_redirect(view, 1000)
assert flash["info"] =~
"You have imported a notebook, no code has been executed so far. You should read and evaluate code as needed."
@ -294,7 +292,7 @@ defmodule LivebookWeb.HomeLiveTest do
|> element("form", "Import")
|> render_submit(%{data: %{content: notebook_content}})
{_path, flash} = assert_redirect(view)
{_path, flash} = assert_redirect(view, 1000)
assert flash["warning"] =~
"We found problems while importing the file and tried to autofix them:\n- Downgrading all headings, because 3 instances of heading 1 were found"

View file

@ -222,6 +222,8 @@ defmodule LivebookWeb.SessionLiveTest do
destination: test
}
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
insert_cell_with_output(session.pid, section_id, {:input, input})
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -249,6 +251,8 @@ defmodule LivebookWeb.SessionLiveTest do
destination: test
}
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
insert_cell_with_output(session.pid, section_id, {:input, input})
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -285,6 +289,8 @@ defmodule LivebookWeb.SessionLiveTest do
reset_on_submit: []
}
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
insert_cell_with_output(session.pid, section_id, {:control, form_control})
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
@ -320,6 +326,8 @@ defmodule LivebookWeb.SessionLiveTest do
send(session.pid, {:runtime_evaluation_output, cell_id, {:stdout, "line 2\n"}})
wait_for_session_update(session.pid)
# Render once, so that stdout send_update is processed
_ = render(view)
assert render(view) =~ "line 2"
end
@ -514,10 +522,15 @@ defmodule LivebookWeb.SessionLiveTest do
assert_reply view, %{"ref" => ref}
assert ref != nil
assert_push_event(view, "intellisense_response", %{
"ref" => ^ref,
"response" => %{items: [%{label: "version/0"}]}
})
assert_push_event(
view,
"intellisense_response",
%{
"ref" => ^ref,
"response" => %{items: [%{label: "version/0"}]}
},
1000
)
end
end
@ -906,6 +919,7 @@ defmodule LivebookWeb.SessionLiveTest do
cell_id = insert_text_cell(session_pid, section_id, :elixir, code)
Session.queue_cell_evaluation(session_pid, cell_id)
assert_receive {:operation, {:add_cell_evaluation_response, _, ^cell_id, _, _}}
cell_id
end