with-redefs JVM-global Redefinition Boundary in Parallel Clojure Integration Tests
0 reputation · 16 Aug 2023, 02:59 UTC
Credential Mocking Scope in Parallel Integration Tests
The goal is to run Clojure integration tests that replace production API clients with mocks while executing test namespaces in parallel. Assuming standard Clojure var semantics on the JVM, with-redefs rebinds a var's root value globally across threads, so one test thread's mock can be visible to another thread's assertion. Thread-local binding limits visibility to the current thread but may not protect code that captures the var or dispatches work to futures and agent pools.
This leaves an unresolved compatibility boundary between global var mocking and concurrent test runners such as Kaocha. The team must decide whether to serialize mocked tests, adopt thread-local rebinding, or pass clients as explicit parameters, each with different implications for existing test structure.
- Is serializing all credential-mocked integration tests an acceptable workaround for
with-redefsrace conditions? - Does
bindingprovide sufficient isolation when tests spawn futures or background threads that read the same var? - What is the lowest-effort migration path from global var mocks to injecting HTTP clients as function arguments without rewriting every test namespace?