0

I was writing integration tests in Grails 3.3 with multiple Asynchronous GORM calls when I realized I could not get access to values stored in the database. I wrote the following test to understand what is happening.

   void "test something"() {
        given:
        def instance = new ExampleDomain(aStringField: "testval").save(flush:true)

        when:
        def promise = ExampleDomain.async.task {
            ExampleDomain.get(instance.id).aStringField
        }

       then:
       promise.get() == "testval"

    }

My domain class

class ExampleDomain implements AsyncEntity<ExampleDomain> {

    String aStringField

    static constraints = {}
}

build.gradle configuration

compile "org.grails:grails-datastore-gorm-async:6.1.6.RELEASE"

Any idea what is going wrong? I'm expecting to have access to the datastore during the execution of the async call.

vitgou
  • 13
  • 3

1 Answers1

0

Most likely the given block is in a transaction that hasn't committed. Without seeing the full test class it is impossible to know, however it is likely you have the @Rollback annotation.

The fix is to remove the annotation and put the logic for saving the domain in a separate transactional method. You will then be responsible for cleaning up any inserted data.

James Kleeh
  • 12,094
  • 5
  • 34
  • 61