diff --git a/lib/livebook/storage.ex b/lib/livebook/storage.ex index dd4309ebf..aa8bb67bf 100644 --- a/lib/livebook/storage.ex +++ b/lib/livebook/storage.ex @@ -152,14 +152,6 @@ defmodule Livebook.Storage do Path.join([Livebook.Config.data_path(), "livebook_config.ets"]) end - @doc """ - Synchronously awaits for all prior changes to be processed. - """ - @spec sync() :: :ok - def sync() do - GenServer.call(__MODULE__, :sync) - end - @impl true def init(_opts) do # Make sure that this process does not terminate abruptly @@ -172,11 +164,6 @@ defmodule Livebook.Storage do {:ok, %{table: table}} end - @impl true - def handle_call(:sync, _from, state) do - {:reply, :ok, state} - end - @impl true def handle_call({:insert, namespace, entity_id, attributes}, _from, %{table: table} = state) do keys_to_delete = Enum.map(attributes, fn {key, _val} -> key end) @@ -194,13 +181,11 @@ defmodule Livebook.Storage do {:reply, :ok, state, {:continue, :save_to_file}} end - @impl true def handle_call({:delete, namespace, entity_id}, _from, %{table: table} = state) do :ets.delete(table, {namespace, entity_id}) {:reply, :ok, state, {:continue, :save_to_file}} end - @impl true def handle_call({:delete_key, namespace, entity_id, key}, _from, %{table: table} = state) do delete_keys(table, namespace, entity_id, [key]) {:reply, :ok, state, {:continue, :save_to_file}} diff --git a/test/livebook/storage_test.exs b/test/livebook/storage_test.exs index 26062960f..e68116146 100644 --- a/test/livebook/storage_test.exs +++ b/test/livebook/storage_test.exs @@ -105,16 +105,25 @@ defmodule Livebook.StorageTest do describe "persistence" do defp read_table_and_lookup(entity) do - :ok = Storage.sync() + Process.sleep(1) {:ok, tab} = - Storage.config_file_path() - |> String.to_charlist() - |> :ets.file2tab() + with {:error, _} <- read_table() do + # :ets.tab2file is asynchronous and may occasionally take + # longer, so we retry once + Process.sleep(100) + read_table() + end :ets.lookup(tab, {:persistence, entity}) end + defp read_table() do + Storage.config_file_path() + |> String.to_charlist() + |> :ets.file2tab() + end + test "insert triggers saving to file" do :ok = Storage.insert(:persistence, "insert", key: "val")