ExJsonschema.Cache.Test (ExJsonschema v0.1.17)
View SourceTest cache implementation using process dictionary and Application environment.
This cache is designed for testing and supports both async and non-async tests:
- Async tests: Use process-local cache via
set_cache_for_process/1 - Non-async tests: Use Application environment via
set_global_cache/1
Usage
Async Tests (isolated per-process):
setup do
test_cache = start_supervised!({Agent, fn -> %{} end})
ExJsonschema.Cache.Test.set_cache_for_process(test_cache)
:ok
endNon-async Tests (global, works with spawns):
setup do
test_cache = start_supervised!({Agent, fn -> %{} end})
ExJsonschema.Cache.Test.set_global_cache(test_cache)
on_exit(fn ->
ExJsonschema.Cache.Test.clear_global_cache()
end)
:ok
end
Summary
Functions
Clears the global cache reference.
Sets the cache pid/name for the current process.
Sets the global cache pid/name for non-async tests.
Sets up the test cache in global mode for non-async tests.
Sets up the test cache in process-local mode for async tests.
Functions
Clears the global cache reference.
Should be called in test cleanup to avoid test pollution.
Sets the cache pid/name for the current process.
This cache will only be available to the current process and any processes spawned from it that explicitly inherit the process dictionary.
Sets the global cache pid/name for non-async tests.
This cache will be available to all processes, including spawned tasks. Should only be used in non-async tests to avoid conflicts.
Sets up the test cache in global mode for non-async tests.
Returns a cleanup function that should be called in test teardown.
Usage
setup do
test_cache = start_supervised!({Agent, fn -> %{} end})
cleanup = ExJsonschema.Cache.Test.setup_global_mode(test_cache)
on_exit(cleanup)
:ok
end
Sets up the test cache in process-local mode for async tests.
Returns a cleanup function that should be called in test teardown.
Usage
setup do
test_cache = start_supervised!({Agent, fn -> %{} end})
cleanup = ExJsonschema.Cache.Test.setup_process_mode(test_cache)
on_exit(cleanup)
:ok
end