Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
msfstef committed Nov 27, 2024
1 parent 068ba13 commit 313729d
Showing 1 changed file with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,49 @@ defmodule Electric.ShapeCache.StorageImplimentationsTest do
Electric.ShapeCache.Storage.get_all_stored_shapes({storage, opts})
end
end

describe "#{module_name}.unsafe_cleanup/1" do
setup do
{:ok, %{module: unquote(module)}}
end

setup :start_storage

test "should remove entire data directory without requiring process to run", %{
module: storage,
opts: opts,
pid: pid
} do
lsn = Lsn.from_integer(1000)

log_items =
[
%Changes.NewRecord{
relation: {"public", "test_table"},
record: %{"id" => "123", "name" => "Test"},
log_offset: LogOffset.new(lsn, 0)
}
]
|> changes_to_log_items()

storage.append_to_log!(log_items, opts)

Process.exit(pid, :normal)

assert File.exists?(opts.data_dir)

storage.unsafe_cleanup!(opts)

refute File.exists?(opts.data_dir)
end
end
end

defp start_storage(%{module: module} = context) do
opts = module |> opts(context) |> module.shared_opts()
shape_opts = module.for_shape(@shape_handle, opts)
{:ok, _} = module.start_link(shape_opts)
{:ok, %{module: module, opts: shape_opts}}
{:ok, pid} = module.start_link(shape_opts)
{:ok, %{module: module, opts: shape_opts, pid: pid}}
end

defp opts(InMemoryStorage, %{stack_id: stack_id}) do
Expand Down

0 comments on commit 313729d

Please sign in to comment.