From f543bccb7bd2e738029595369d421cf452d988dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Charvet=20=E9=BB=91=E7=93=9C?= Date: Mon, 1 Jul 2024 11:20:22 +0100 Subject: [PATCH] Add a simple test for clearing caches --- test/teiserver/caches_test.exs | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/teiserver/caches_test.exs diff --git a/test/teiserver/caches_test.exs b/test/teiserver/caches_test.exs new file mode 100644 index 000000000..ad22bd517 --- /dev/null +++ b/test/teiserver/caches_test.exs @@ -0,0 +1,42 @@ +defmodule Teiserver.CachesTest do + use Teiserver.DataCase, async: false + + # This module is merely here to check that + # Teiserver.TeiserverTestLib.clear_all_con_caches does indeed clear the advertised + # cache across tests. + # because all queries rely heavily on caches, it's important to clear them between + # tests so as not to pollute other tests + + @caches [ + :telemetry_complex_client_event_types_cache, + :telemetry_complex_lobby_event_types_cache, + :telemetry_complex_match_event_types_cache, + :telemetry_complex_server_event_types_cache, + :telemetry_property_types_cache, + :telemetry_simple_client_event_types_cache, + :telemetry_simple_lobby_event_types_cache, + :telemetry_simple_match_event_types_cache, + :telemetry_simple_server_event_types_cache, + :users, + :users_lookup_id_with_discord, + :users_lookup_id_with_email, + :users_lookup_id_with_name, + :users_lookup_name_with_id + ] + + test "clear caches between tests 1" do + for cache <- @caches do + assert is_nil(ConCache.get(cache, "test_key")) + ConCache.put(cache, "test_key", "test_val") + assert "test_val" == ConCache.get(cache, "test_key") + end + end + + test "clear caches between tests 2" do + for cache <- @caches do + assert is_nil(ConCache.get(cache, "test_key")) + ConCache.put(cache, "test_key", "test_val") + assert "test_val" == ConCache.get(cache, "test_key") + end + end +end