jamesfredley opened a new pull request, #15346:
URL: https://github.com/apache/grails-core/pull/15346
## Summary
Add a new static method `clearConstraintsMapCache()` to the `Validateable`
trait that allows clearing the cached constraints map, forcing re-evaluation on
next access.
## Motivation
The `Validateable` trait caches evaluated constraints in a private static
field `constraintsMapInternal`. During parallel test execution, constraints may
be evaluated before `doWithConfig()` has registered shared constraints, causing
test failures where shared constraint names (like `'isProg'`) are not found.
This new public API method enables proper test isolation by allowing tests
to clear the constraint cache in setup/cleanup methods.
## API Addition
```groovy
/**
* Clears the cached constraints map, forcing re-evaluation on next access.
* This is useful in testing scenarios where shared constraints may need
* to be re-evaluated after configuration changes, particularly during
* parallel test execution.
*
* @since 7.1
*/
@Generated
static void clearConstraintsMapCache()
```
## Usage Example
```groovy
class CommandObjectsSpec extends Specification implements
ControllerUnitTest<TestController> {
Closure doWithConfig() {{ config ->
config['grails.gorm.default.constraints'] = {
isProg inList: ['Emerson', 'Lake', 'Palmer']
}
}}
def setup() {
ConstraintEvalUtils.clearDefaultConstraints()
Artist.clearConstraintsMapCache()
}
def cleanup() {
ConstraintEvalUtils.clearDefaultConstraints()
Artist.clearConstraintsMapCache()
}
}
```
## Why This is a Feature (7.1)
Per the Grails versioning policy, adding a new public method to a trait is a
backward-compatible feature addition that belongs in a MINOR release (7.1.x),
not a PATCH release (7.0.x).
A companion change in PR #15335 (targeting 7.0.x) uses reflection to achieve
the same test isolation without modifying the public API.
## Files Changed
- `grails-validation/src/main/groovy/grails/validation/Validateable.groovy`
- Add new `clearConstraintsMapCache()` method
-
`grails-validation/src/test/groovy/grails/validation/ValidateableTraitSpec.groovy`
- Add test isolation
-
`grails-validation/src/test/groovy/grails/validation/ValidateableTraitAdHocSpec.groovy`
- Add test isolation
-
`grails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectsSpec.groovy`
- Add test isolation
-
`grails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectNoDataSpec.groovy`
- Add test isolation
--
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]