Grails

Dynamic finders created by mockDomain are not torn down properly

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Duplicate
  • Affects Version/s: 1.1
  • Fix Version/s: 1.1.1
  • Component/s: Testing
  • Labels:
    None
  • Environment:
    Ubuntu Linux 8.10 / OSX Leopard, Java 6, Grails 1.1
  • Testcase included:
    yes

Description

Dynamic finders created by mockDomain in a unit test are sometimes still getting invoked somehow in subsequent tests even though they should have been removed in the tearDown phase of the relevant test. This can even go as far as bleeding over into integration tests if run together with the unit tests, even though integration tests should have 'real' dynamic finders in place.

I've attached an example app showing the behaviour in a single unit test case. It shows the dynamic finder being used correctly by the class under test, then not working (as expected) when called directly from a subsequent test, then mysteriously still working when called by a new instance of the class under test in a third test despite mockDomain only having been used in the first test.

Activity

Hide
Robert Fletcher added a comment -

May be related to http://jira.codehaus.org/browse/GRAILS-4271 although the specifics of the effect are a little different.

Show
Robert Fletcher added a comment - May be related to http://jira.codehaus.org/browse/GRAILS-4271 although the specifics of the effect are a little different.
Hide
Robert Fletcher added a comment -

I should mention this specifically seems to be a problem with mockDomain using methodMissing to implement the finders (not that I think that's theoretically the wrong approach, but it seems to be the root of the problem). If I stop using mockDomain and instead implement a finder directly (Thing.metaClass.static.findByName = { x } for example) the tear down works correctly (assuming I've used registerMetaClass(Thing) obviously), however if I try to implement a simplified version of what mockDomain does (e.g. Thing.metaClass.static.methodMissing = {name, args -> x }) the same problem occurs.

Show
Robert Fletcher added a comment - I should mention this specifically seems to be a problem with mockDomain using methodMissing to implement the finders (not that I think that's theoretically the wrong approach, but it seems to be the root of the problem). If I stop using mockDomain and instead implement a finder directly (Thing.metaClass.static.findByName = { x } for example) the tear down works correctly (assuming I've used registerMetaClass(Thing) obviously), however if I try to implement a simplified version of what mockDomain does (e.g. Thing.metaClass.static.methodMissing = {name, args -> x }) the same problem occurs.
Hide
Burt Beckwith added a comment -

This is related to callsite caching. Graeme reported this bug http://jira.codehaus.org/browse/GROOVY-3433 and using the Groovy 1.6.1 jar fixes this problem too. Note that because of hard-coded jar names, you need to rename groovy-all-1.6.1.jar to groovy-all-1.6.0.jar in $GRAILS_HOME/lib

Show
Burt Beckwith added a comment - This is related to callsite caching. Graeme reported this bug http://jira.codehaus.org/browse/GROOVY-3433 and using the Groovy 1.6.1 jar fixes this problem too. Note that because of hard-coded jar names, you need to rename groovy-all-1.6.1.jar to groovy-all-1.6.0.jar in $GRAILS_HOME/lib

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: