Forgus / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Already Value ... bound to thread #211

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem? If possible, provide source code and
stack trace.
=======================
import grails.plugin.spock.*
import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import spock.lang.*

@TestFor(Company)
@Mock(Fleet)
class CompanySpec extends Specification {

    def "should accept Fleet"() {
        given:
        Company acmeCompany = new Company(name:"ACME")
            .addToFleets(new Fleet(name:"Fleet One"))
            .save(flush:true)

        expect:
        acmeCompany.fleets.size() == 1
        acmeCompany.fleets.iterator().next().company != null    

    }
}
=======================

When the above test is run together with other tests it results in the 
stacktrace below.  Running test-app on a project with 100+ specs resulted in 
the GebSpec, IntegrationSpec and old-style UnitSpec tests running correctly but 
specs extending spock.lang.Specification failed in the same manner.  
Unfortunately I was unable to reproduce the error in a simple project with the 
above spec.

What version of Spock and Groovy are you using?
Groovy 1.8 Spock 0.6-SNAPSHOT (2011-10-29)
Note that rolling back to 0.6-SNAPSHOT (2011-10-25) results in successful 
execution.

Please provide any additional information below. You can also assign
labels.

java.lang.reflect.InvocationTargetException
    at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:66)
    at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:66)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:173)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:173)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: Already value 
[org.grails.datastore.mapping.transactions.SessionHolder@444ef630] for key 
[org.grails.datastore.mapping.simple.SimpleMapDatastore@10ea443f] bound to 
thread [main]
    at org.springframework.transaction.support.TransactionSynchronizationManager.bindResource(TransactionSynchronizationManager.java:179)
    at org.grails.datastore.mapping.core.DatastoreUtils.bindSession(DatastoreUtils.java:336)
    at grails.test.mixin.domain.DomainClassUnitTestMixin.connectDatastore(DomainClassUnitTestMixin.groovy:93)
    at fleet.CompanySpec.connectDatastore(CompanySpec.groovy)
    ... 10 more

Original issue reported on code.google.com by colin.we...@freedomit.co.za on 29 Oct 2011 at 6:12

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I have the same problem. My exception is roughly the same:

WARN  07/Mar/2012 18:13:13,768 DatastoreUtils Cannot unbind session, it's not 
registered in a SessionHolder
| Running 23 spock tests... 2 of 23
| Failure:  description too long(com.spotmapping.domain.activity.ActivitySpec)
|  java.lang.IllegalStateException: Already value 
[org.grails.datastore.mapping.transactions.SessionHolder@3a38df00] for key 
[org.grails.datastore.mapping.simple.SimpleMapDatastore@5472e884] bound to 
thread [main]
    at org.grails.datastore.mapping.core.DatastoreUtils.bindSession(DatastoreUtils.java:336)
    at grails.test.mixin.domain.DomainClassUnitTestMixin.connectDatastore(DomainClassUnitTestMixin.groovy:110)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:176)
    at org.spockframework.runtime.extension.builtin.JUnitFixtureMethodsExtension$FixtureType$FixtureMethodInterceptor.intercept(JUnitFixtureMethodsExtension.java:145)
    at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:84)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:176)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:176)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:176)

This happened after upgrading from the SNAPSHOT release to 0.6. Before that I 
"only" got the warning that the DatastoreUtils Cannot unbind the session, but 
the test would still pass.

Original comment by n.wittst...@gmail.com on 7 Mar 2012 at 7:20

GoogleCodeExporter commented 8 years ago
Do you still see this problem (with latest Grails version)? Spock 0.6 changed 
the initialization order a bit, but I can't see how this could cause problems.

Original comment by pnied...@gmail.com on 12 May 2012 at 6:31

GoogleCodeExporter commented 8 years ago
I am not seeing this problem any longer. I think it was somehow cache related, 
because after deleting the plugin cache everything worked fine.

Original comment by n.wittst...@gmail.com on 13 May 2012 at 12:09

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Run grails clean. Then, when you select the test to run in Intellij, make sure 
you choose "Grails test".

Original comment by fsa...@gmail.com on 11 Mar 2014 at 10:12

GoogleCodeExporter commented 8 years ago
This problem seems to be related to running tests in IntelliJ with the JUnit 
runner - which used to work fine. but now seems broken.

JUnit Runner is approx 5x faster than the "Grails test" so was obviously 
preferable. 

Original comment by epg.team...@gmail.com on 2 Apr 2014 at 7:43

GoogleCodeExporter commented 8 years ago
It's nothing that we can do anything about, as it doesn't happen in our code. 
Can you report this to the Grails and/or IntelliJ team?

Original comment by pnied...@gmail.com on 2 Apr 2014 at 3:00

GoogleCodeExporter commented 8 years ago
Facing this exact same issue on a very simple domain class test. Anyone been 
able to find a root cause?

Original comment by dmitry.b...@gmail.com on 3 Nov 2014 at 11:03

GoogleCodeExporter commented 8 years ago
I am fairly certain this issue in IntelliJ happens when 2 grails test plugins 
are referenced on the classpath by the IDE dependency resolver. For my 
mavenized grails project there is a refernce to this plugin from Maven POM as 
well as from the Grails SDK entry I made in IntelliJ that references the entire 
grails directory.

Original comment by dmitry.b...@gmail.com on 25 Mar 2015 at 4:46

GoogleCodeExporter commented 8 years ago
I think this is caused by the
@TestFor(Company)
@Mock(Fleet)
bit - that causes DomainClassUnitTestMixin.connectDatastore() (an @Before 
method) to be called twice for a test, the 2nd call triggering the exception. 
Possibly the combination of Mock and TestFor is causing the mixin to be mixed 
in twice sometimes in some way. 

I'm seeing it a plain unit test that doesn't use spock, in grails 2.2.1. I 
daresay it's fixed in more recent versions, where unit testing has been 
somewhat overhauled. A workaround might be to manually do the mocking and 
remove the @Mock(Fleet) bit, using a manual call to mockDomains in the test 
setup() method instead.

Original comment by tom.wid...@gmail.com on 17 Apr 2015 at 2:59