Skip to content

Commit 1d38b6d

Browse files
authored
test(composite_kv): use named function captures in the shared suite (#259)
The shared `Nebulex.Cache.CompositeKVTest` passed literal anonymous functions (`fn _ -> :pop end`, `&{&1, nil}`) to `get_and_update`. Those functions belong to the in-memory test module, which doesn't exist on peer nodes, so adapters that run the function on the node owning the key (e.g., the Partitioned adapter) fail with `UndefinedFunctionError`. Use captures of named helpers from the test cache instead, as the suite already does for the other functions.
1 parent 5774c0f commit 1d38b6d

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎test/shared/cache/composite_kv_test.exs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ defmodule Nebulex.Cache.CompositeKVTest do
1212
test "stores a nil value when the function returns {get, nil}", %{cache: cache} do
1313
:ok = cache.put(:counter, 1)
1414

15-
assert cache.get_and_update(:counter, &{&1, nil}) == {:ok, {1, nil}}
15+
assert cache.get_and_update(:counter, &cache.get_and_update_nil_fun/1) == {:ok, {1, nil}}
1616
assert cache.fetch!(:counter) == nil
1717
assert cache.has_key?(:counter) == {:ok, true}
1818
end
1919

2020
test "pops the key when the function returns :pop", %{cache: cache} do
2121
:ok = cache.put(:counter, 1)
2222

23-
assert cache.get_and_update(:counter, fn _ -> :pop end) == {:ok, {1, nil}}
23+
assert cache.get_and_update(:counter, &cache.pop_fun/1) == {:ok, {1, nil}}
2424
assert cache.has_key?(:counter) == {:ok, false}
25-
assert cache.get_and_update(:counter, fn _ -> :pop end) == {:ok, {nil, nil}}
25+
assert cache.get_and_update(:counter, &cache.pop_fun/1) == {:ok, {nil, nil}}
2626
end
2727

2828
test "pops a cached nil value", %{cache: cache} do
2929
:ok = cache.put(:counter, nil)
3030

31-
assert cache.get_and_update(:counter, fn _ -> :pop end) == {:ok, {nil, nil}}
31+
assert cache.get_and_update(:counter, &cache.pop_fun/1) == {:ok, {nil, nil}}
3232
assert cache.has_key?(:counter) == {:ok, false}
3333
end
3434

@@ -52,8 +52,8 @@ defmodule Nebulex.Cache.CompositeKVTest do
5252
test "gets and updates the value", %{cache: cache} do
5353
assert cache.get_and_update!(:counter, &cache.get_and_update_fun/1) == {nil, 1}
5454
assert cache.get_and_update!(:counter, &cache.get_and_update_fun/1) == {1, 2}
55-
assert cache.get_and_update!(:counter, fn _ -> :pop end) == {2, nil}
56-
assert cache.get_and_update!(:counter, fn _ -> :pop end) == {nil, nil}
55+
assert cache.get_and_update!(:counter, &cache.pop_fun/1) == {2, nil}
56+
assert cache.get_and_update!(:counter, &cache.pop_fun/1) == {nil, nil}
5757
end
5858
end
5959

‎test/support/test_cache.exs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ defmodule Nebulex.TestCache do
1111

1212
def get_and_update_bad_fun(_), do: :other
1313

14+
def get_and_update_nil_fun(current), do: {current, nil}
15+
16+
def pop_fun(_), do: :pop
17+
1418
def fetch_or_store_fun, do: {:ok, "value"}
1519

1620
def fetch_or_store_error_fun, do: {:error, :error}

0 commit comments

Comments
 (0)