borinquenkid opened a new pull request, #16033:
URL: https://github.com/apache/grails-core/pull/16033
## Summary
~20 test methods across `JsonViewHelperSpec`, `JsonViewTestSpec`,
`JsonApiSpec`, and
`ExpandSpec` (module `:grails-views-gson:test`) show the same
failure+flakiness
pattern (~2% failures, ~1% flakiness per apache/grails-core#16030) — one
shared root
cause, not 20 independent bugs.
## Root cause
Two confirmed leak vectors (an initial hypothesis about shared Groovy trait
statics
was empirically disproven via isolated Groovy 5.0.7/Spock 2.4 probes —
traits do *not*
share static storage across implementing classes in this version):
1. `ExpandSpec` silently resolved `Team`/`Player` to `JsonViewHelperSpec`'s
compiled
classes via an unqualified same-package reference (no import), so both
specs
registered the identical `Class` objects into independently-built
`KeyValueMappingContext` instances — letting class-keyed GORM caches leak
between
unrelated specs.
2. `org.grails.validation.ConstraintEvalUtils` is a genuine JVM-wide static
cache keyed
by `System.identityHashCode(config)`. `JsonApiSpec` alone worked around
this for its
own fixtures via a reflection hack into `Validateable`'s internal state;
the other
three specs had no equivalent reset, so whichever spec ran last in a
shared test
fork left stale cached constraint/association state for the next one —
explaining
the toMany/toOne/hasOne/expand assertion flakiness.
## Fix
- Hoisted cleanup into the shared `JsonViewTest` trait (implemented by ~19
specs) so
new specs get correct isolation by default: `cleanup()` clears the
`ConstraintEvalUtils` cache after every feature; a separate
`cleanupSpec()` tears
down any cached `GrailsApplication` once per spec class (split this way
because
per-feature teardown broke `MapRenderSpec`'s once-per-spec datastore bean
registration — found via isolated probes before touching real test files).
- Gave `ExpandSpec` its own `ExpandTeam`/`ExpandPlayer` domain classes
instead of
implicitly borrowing another spec's.
- Moved `JsonApiSpec` off the reflection hack onto the public
`SuperHero.clearConstraintsMapCache()` API (available since 7.1); removed
its now-
redundant local `cleanup()`.
No production code changed.
## Testing
- Full `:grails-views-gson:test` (178 tests): 0 failures, run to completion
multiple
times including with varied `--tests` orderings across the
originally-flagged specs
specifically to catch order-dependent regressions.
- CodeNarc/Checkstyle: clean.
Related: apache/grails-core#16030
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]