mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-09 13:07:37 +08:00
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:
parent
f11b9d50c9
commit
f58f9609d2
2 changed files with 22 additions and 10 deletions
|
@ -245,8 +245,6 @@ defmodule LivebookWeb.HomeLiveTest do
|
||||||
|
|
||||||
describe "notebook import" do
|
describe "notebook import" do
|
||||||
test "allows importing notebook directly from content", %{conn: conn} 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")
|
{:ok, view, _} = live(conn, "/home/import/content")
|
||||||
|
|
||||||
notebook_content = """
|
notebook_content = """
|
||||||
|
@ -257,9 +255,9 @@ defmodule LivebookWeb.HomeLiveTest do
|
||||||
|> element("form", "Import")
|
|> element("form", "Import")
|
||||||
|> render_submit(%{data: %{content: notebook_content}})
|
|> 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"
|
assert render(view) =~ "My notebook"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -274,7 +272,7 @@ defmodule LivebookWeb.HomeLiveTest do
|
||||||
|> element("form", "Import")
|
|> element("form", "Import")
|
||||||
|> render_submit(%{data: %{content: notebook_content}})
|
|> render_submit(%{data: %{content: notebook_content}})
|
||||||
|
|
||||||
{_path, flash} = assert_redirect(view)
|
{_path, flash} = assert_redirect(view, 1000)
|
||||||
|
|
||||||
assert flash["info"] =~
|
assert flash["info"] =~
|
||||||
"You have imported a notebook, no code has been executed so far. You should read and evaluate code as needed."
|
"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")
|
|> element("form", "Import")
|
||||||
|> render_submit(%{data: %{content: notebook_content}})
|
|> render_submit(%{data: %{content: notebook_content}})
|
||||||
|
|
||||||
{_path, flash} = assert_redirect(view)
|
{_path, flash} = assert_redirect(view, 1000)
|
||||||
|
|
||||||
assert flash["warning"] =~
|
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"
|
"We found problems while importing the file and tried to autofix them:\n- Downgrading all headings, because 3 instances of heading 1 were found"
|
||||||
|
|
|
@ -222,6 +222,8 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
destination: test
|
destination: test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||||
|
|
||||||
insert_cell_with_output(session.pid, section_id, {:input, input})
|
insert_cell_with_output(session.pid, section_id, {:input, input})
|
||||||
|
|
||||||
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
|
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
|
||||||
|
@ -249,6 +251,8 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
destination: test
|
destination: test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||||
|
|
||||||
insert_cell_with_output(session.pid, section_id, {:input, input})
|
insert_cell_with_output(session.pid, section_id, {:input, input})
|
||||||
|
|
||||||
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
|
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
|
||||||
|
@ -285,6 +289,8 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
reset_on_submit: []
|
reset_on_submit: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}")
|
||||||
|
|
||||||
insert_cell_with_output(session.pid, section_id, {:control, form_control})
|
insert_cell_with_output(session.pid, section_id, {:control, form_control})
|
||||||
|
|
||||||
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
|
{: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"}})
|
send(session.pid, {:runtime_evaluation_output, cell_id, {:stdout, "line 2\n"}})
|
||||||
wait_for_session_update(session.pid)
|
wait_for_session_update(session.pid)
|
||||||
|
# Render once, so that stdout send_update is processed
|
||||||
|
_ = render(view)
|
||||||
assert render(view) =~ "line 2"
|
assert render(view) =~ "line 2"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -514,10 +522,15 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
assert_reply view, %{"ref" => ref}
|
assert_reply view, %{"ref" => ref}
|
||||||
assert ref != nil
|
assert ref != nil
|
||||||
|
|
||||||
assert_push_event(view, "intellisense_response", %{
|
assert_push_event(
|
||||||
"ref" => ^ref,
|
view,
|
||||||
"response" => %{items: [%{label: "version/0"}]}
|
"intellisense_response",
|
||||||
})
|
%{
|
||||||
|
"ref" => ^ref,
|
||||||
|
"response" => %{items: [%{label: "version/0"}]}
|
||||||
|
},
|
||||||
|
1000
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -906,6 +919,7 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
|
|
||||||
cell_id = insert_text_cell(session_pid, section_id, :elixir, code)
|
cell_id = insert_text_cell(session_pid, section_id, :elixir, code)
|
||||||
Session.queue_cell_evaluation(session_pid, cell_id)
|
Session.queue_cell_evaluation(session_pid, cell_id)
|
||||||
|
assert_receive {:operation, {:add_cell_evaluation_response, _, ^cell_id, _, _}}
|
||||||
cell_id
|
cell_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue