From 66eb2d12a90f0f6eb10ccda54e46f46c0b6e56db Mon Sep 17 00:00:00 2001 From: Dongfu Ye Date: Sat, 14 Jan 2023 14:01:26 +0800 Subject: [PATCH] add test to cover code --- .../adapters/local/generation_test.exs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/nebulex/adapters/local/generation_test.exs b/test/nebulex/adapters/local/generation_test.exs index 16878d20..611563f1 100644 --- a/test/nebulex/adapters/local/generation_test.exs +++ b/test/nebulex/adapters/local/generation_test.exs @@ -307,6 +307,26 @@ defmodule Nebulex.Adapters.Local.GenerationTest do end end + describe "cleanup cover" do + test "cleanup when gc_interval not set" do + {:ok, _pid} = + LocalWithSizeLimit.start_link( + max_size: 3, + gc_cleanup_min_timeout: 1000, + gc_cleanup_max_timeout: 1500 + ) + + # Put some entries to exceed the max size + _ = cache_put(LocalWithSizeLimit, 1..4) + + # Wait the max cleanup timeout + :ok = Process.sleep(1600) + + # assert not crashed + assert LocalWithSizeLimit.count_all() == 4 + end + end + ## Private Functions defp check_cache_size(cache) do