-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For a while now, I've been seeing spurious test failures, but hadn't been able to figure out the root cause. It turns out that clearing the entire `InMemoryCache` before tests was causing test interference. This is obvious in retrospect. There's also a spurious failure in CI with the integration tests where a second instance tries to start with the same SDK key as another. I'm not sure if I've fixed that one with these changes. Changes: - Clear only a specific cache key from the InMemoryCache, and only when multiple tests will use the same key. - Mark the integration tests as `async: false` to be sure they run in isolation. - Eliminate log noise from the tests.
- Loading branch information
1 parent
a0dfa81
commit c79a7cd
Showing
5 changed files
with
25 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
defmodule ConfigCat.InMemoryCacheTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias ConfigCat.InMemoryCache, as: Cache | ||
alias ConfigCat.InMemoryCache | ||
|
||
@cache_key "CACHE_KEY" | ||
|
||
setup do | ||
Cache.clear() | ||
InMemoryCache.clear(@cache_key) | ||
|
||
:ok | ||
end | ||
|
||
test "cache is initially empty" do | ||
assert Cache.get(@cache_key) == {:error, :not_found} | ||
assert InMemoryCache.get(@cache_key) == {:error, :not_found} | ||
end | ||
|
||
test "returns cached value" do | ||
entry = "serialized-cache-entry" | ||
|
||
:ok = Cache.set(@cache_key, entry) | ||
:ok = InMemoryCache.set(@cache_key, entry) | ||
|
||
assert {:ok, ^entry} = Cache.get(@cache_key) | ||
assert {:ok, ^entry} = InMemoryCache.get(@cache_key) | ||
end | ||
|
||
test "cache is empty after clearing" do | ||
entry = "serialized-cache-entry" | ||
|
||
:ok = Cache.set(@cache_key, entry) | ||
:ok = InMemoryCache.set(@cache_key, entry) | ||
|
||
assert :ok = Cache.clear() | ||
assert Cache.get(@cache_key) == {:error, :not_found} | ||
assert :ok = InMemoryCache.clear(@cache_key) | ||
assert InMemoryCache.get(@cache_key) == {:error, :not_found} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters