From dedf5a433b4249d69fcc867991c366452e0672c7 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 | 25 +++++++++++++++++++++++++ 1 file changed, 25 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..73672671e --- /dev/null +++ b/test/teiserver/caches_test.exs @@ -0,0 +1,25 @@ +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 + + test "Clear user caches 1" do + name = "ClearDbEachTestUser" + assert is_nil(Teiserver.CacheUser.get_user_by_name(name)) + user = Teiserver.TeiserverTestLib.new_user(name) + result = Teiserver.CacheUser.get_user_by_id(user.id) + assert result[:name] == name + end + + test "Clear user caches 2" do + name = "ClearDbEachTestUser" + assert is_nil(Teiserver.CacheUser.get_user_by_name(name)) + user = Teiserver.TeiserverTestLib.new_user(name) + result = Teiserver.CacheUser.get_user_by_id(user.id) + assert result[:name] == name + end +end