Stabilize preview and sandbox cleanup
This commit is contained in:
@@ -12,6 +12,7 @@ defmodule BDS.Desktop.ImportShellLiveTest do
|
||||
setup do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, {:shared, self()})
|
||||
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, :manual) end)
|
||||
|
||||
Enum.each(BDS.Tasks.list_running_tasks(), fn task ->
|
||||
BDS.Tasks.cancel_task(task.id)
|
||||
|
||||
@@ -11,6 +11,7 @@ defmodule BDS.Desktop.MiscEditorTest do
|
||||
setup do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, {:shared, self()})
|
||||
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, :manual) end)
|
||||
|
||||
temp_dir =
|
||||
Path.join(System.tmp_dir!(), "bds-misc-editor-test-#{System.unique_integer([:positive])}")
|
||||
|
||||
@@ -87,8 +87,19 @@ defmodule BDS.Desktop.ShellCommandsTest do
|
||||
end
|
||||
|
||||
setup do
|
||||
if :ets.whereis(BDS.Preview.ServerTable) != :undefined do
|
||||
case :ets.lookup(BDS.Preview.ServerTable, :current) do
|
||||
[{:current, %{project_id: project_id}}] ->
|
||||
_ = BDS.Preview.stop_preview(project_id)
|
||||
|
||||
_other ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, {:shared, self()})
|
||||
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, :manual) end)
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.allow(BDS.Repo, self(), Process.whereis(BDS.Preview))
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.allow(BDS.Repo, self(), Process.whereis(BDS.Publishing))
|
||||
:ok = BDS.Tasks.clear_finished()
|
||||
@@ -117,7 +128,7 @@ defmodule BDS.Desktop.ShellCommandsTest do
|
||||
|
||||
assert result.kind == "open_url"
|
||||
assert result.action == "open_in_browser"
|
||||
assert result.url == "http://127.0.0.1:4123/"
|
||||
assert result.url == BDS.Preview.base_url() <> "/"
|
||||
assert result.project_id == project.id
|
||||
end
|
||||
|
||||
|
||||
@@ -640,8 +640,29 @@ defmodule BDS.Desktop.ShellLiveTest do
|
||||
end
|
||||
|
||||
setup do
|
||||
if :ets.whereis(BDS.Preview.ServerTable) != :undefined do
|
||||
case :ets.lookup(BDS.Preview.ServerTable, :current) do
|
||||
[{:current, %{project_id: project_id}}] ->
|
||||
_ = BDS.Preview.stop_preview(project_id)
|
||||
|
||||
_other ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
if :ets.whereis(BDS.Preview.ServerTable) != :undefined do
|
||||
case :ets.lookup(BDS.Preview.ServerTable, :current) do
|
||||
[{:current, %{project_id: project_id}}] ->
|
||||
_ = BDS.Preview.stop_preview(project_id)
|
||||
|
||||
_other ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, {:shared, self()})
|
||||
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, :manual) end)
|
||||
|
||||
Enum.each(BDS.Tasks.list_running_tasks(), fn task ->
|
||||
BDS.Tasks.cancel_task(task.id)
|
||||
@@ -661,7 +682,8 @@ defmodule BDS.Desktop.ShellLiveTest do
|
||||
DynamicSupervisor.terminate_child(BDS.Tasks.TaskSupervisor, pid)
|
||||
end
|
||||
|
||||
Process.sleep(100)
|
||||
wait_for_supervisor_clear(BDS.TCP.TaskSupervisor)
|
||||
wait_for_supervisor_clear(BDS.Tasks.TaskSupervisor)
|
||||
|
||||
temp_dir =
|
||||
Path.join(System.tmp_dir!(), "bds-shell-live-#{System.unique_integer([:positive])}")
|
||||
@@ -700,6 +722,21 @@ defmodule BDS.Desktop.ShellLiveTest do
|
||||
%{project: project, temp_dir: temp_dir}
|
||||
end
|
||||
|
||||
defp wait_for_supervisor_clear(supervisor, attempts \\ 50)
|
||||
|
||||
defp wait_for_supervisor_clear(_supervisor, 0), do: :ok
|
||||
|
||||
defp wait_for_supervisor_clear(supervisor, attempts) do
|
||||
case DynamicSupervisor.which_children(supervisor) do
|
||||
[] ->
|
||||
:ok
|
||||
|
||||
_children ->
|
||||
Process.sleep(10)
|
||||
wait_for_supervisor_clear(supervisor, attempts - 1)
|
||||
end
|
||||
end
|
||||
|
||||
test "sidebar headers expose old-app create actions for posts, media, scripts, templates, chat, and imports" do
|
||||
{:ok, view, html} = live_isolated(build_conn(), BDS.Desktop.ShellLive)
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ defmodule BDS.Desktop.ShellLive.SettingsEditor.StyleEditorTest do
|
||||
result = StyleEditor.build_style(assigns)
|
||||
assert result.preview_url =~ "theme=default"
|
||||
assert result.preview_url =~ "mode=auto"
|
||||
assert result.preview_url =~ "127.0.0.1:4123/__style-preview"
|
||||
assert result.preview_url =~ BDS.Preview.base_url() <> "/__style-preview"
|
||||
end
|
||||
|
||||
test "preview_url reflects selected_theme", %{project: project} do
|
||||
|
||||
@@ -12,6 +12,7 @@ defmodule BDS.Desktop.TagEditorLiveTest do
|
||||
setup do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, {:shared, self()})
|
||||
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, :manual) end)
|
||||
|
||||
Enum.each(BDS.Tasks.list_running_tasks(), fn task ->
|
||||
BDS.Tasks.cancel_task(task.id)
|
||||
|
||||
@@ -15,6 +15,7 @@ defmodule BDS.Desktop.TemplateEditorLiveTest do
|
||||
setup do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, {:shared, self()})
|
||||
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.mode(BDS.Repo, :manual) end)
|
||||
|
||||
Enum.each(BDS.Tasks.list_running_tasks(), fn task ->
|
||||
BDS.Tasks.cancel_task(task.id)
|
||||
|
||||
Reference in New Issue
Block a user