blackbox-global-scope-teardown: repro for global test scope corruption by mock-scoped test classes - #1054
Draft
stevenschlansker wants to merge 2 commits into
Draft
Conversation
…n by mock-scoped test classes A test class with mocks/profiles/scopePerTest rebuilds the entire application parented only on the TestScope beans. The rebuilt beans run their lifecycle beside the still-live global scope, and closing them at afterEach tears down JVM-global state (static registries, drivers, MBeans) the global scope's beans still depend on. With alphabetical class order in one fork: T1 (global) passes, T2 (one @mock) passes, T3 (global again) fails. Each class passes in isolation. Reproduces on 12.6 and 12.7-RC2.
stevenschlansker
force-pushed
the
blackbox-global-scope-teardown
branch
from
August 14, 2026 20:26
d20de65 to
95e31d4
Compare
Responds to review feedback asking for a real-world case instead of a synthetic one. ServerStatus registers itself on the JVM-wide platform MBeanServer in @PostConstruct and unregisters in @PreDestroy, the standard JMX pattern (HikariCP, Kafka clients, Jetty). T1 (plain @injecttest) passes. T2 mocks one unrelated interface and never references ServerStatus; wiring its scope rebuilds the whole application beside the live global scope and fails with the JDK's InstanceAlreadyExistsException. Closing that failed scope runs the duplicate's @PreDestroy, which unregisters the MBean by ObjectName out from under the live global instance, so T3 (identical to T1) fails with InstanceNotFoundException. T1 and T3 pass in isolation.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A test class with mocks/profiles/scopePerTest rebuilds the entire application parented only on the TestScope beans, beside the still-live global scope. This version reproduces the corruption with real JVM-global state: ServerStatus registers itself on the platform MBeanServer in @PostConstruct and unregisters in @PreDestroy, the standard JMX pattern.
With alphabetical class order in one fork: T1 (plain) passes. T2 mocks one unrelated interface and never references ServerStatus; wiring its per-test scope constructs ServerStatus a second time and fails with InstanceAlreadyExistsException, and closing that failed scope unregisters (by ObjectName) the MBean the live global scope owns. T3 (identical to T1) then fails with InstanceNotFoundException. T1 and T3 pass in isolation; T2 fails even alone.
Reproduces on 12.6 and 12.7-RC2.