Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDatastore is closed too early #138

Open
Doogiemuc opened this issue Oct 5, 2020 · 1 comment
Open

MongoDatastore is closed too early #138

Doogiemuc opened this issue Oct 5, 2020 · 1 comment

Comments

@Doogiemuc
Copy link

I have a Micronaut Backend API with some simple REST resources. Implemented in Groovy. The backend uses a (local) mongoDB. The backend services access this mongoDB with GORM for mongoDB

I have two spock test classes with some simpl tests that send REST requests to that backend. Both test classes inject the MongoDatastore to directly access the DB where needed. For example to pre-fill the DB with test data.

When I run the test classes individually, one at a time, the tests in each class run successfully. But when I run both classes together with gradle test one fails with the following error:

First test class: HappyCase.groovy

@MicronautTest
@Slf4j
class HappyCase extends Specification {
	@Shared
	@AutoCleanup
	EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer)

	@Shared
	@AutoCleanup
	BlockingHttpClient client = HttpClient.create(embeddedServer.URL).toBlocking()

	@Inject
	MongoDatastore mongoDatastore

       [... test methods ...]
}

The second TestClass has the same fields.

Error message

java.lang.IllegalStateException: state should be: open

The stacktrace always leads back to a line of code where the backend access one of my GORM Models, e.g. with a finder method.

  @Put("/joinTeam")
  @Secured(SecurityRule.IS_ANONYMOUS)
    HttpResponse joinTeam(@Body @Valid JoinTeamRequest req) {
    // Remark: Team.class is one of my GORM @Entity 
    Team team = Team.findByInviteCode(req.inviteCode)            // <=== this  is where the error is thrown
    [...]
  }

My assumption would be that Micronaut already closes the connection to the DB via the injected mongoDatastore, while the other test is still running. But that is just a guess.

Environment Information

  • Operating System: Windows
  • Micronaut Version:
  • JDK Version: jdk 13.0.1

GitHub Repo

https://github.com/Doogiemuc/liquido-micronaut-groovy

Direct Links:

Things I alreay tried

  • Adding/Removing @Shared does not help
  • Adding/Removing @AutoCleanup (or in combination with or without @Shared) does not help
  • Running from within IntelliJ gives the same effect: Run one test class works. Run both at the same time does not work
  • Adding packe of Application.class to @MicronautTest annotation (mabe) for better class path scanning does not help: @MicronautTest(application = org.doogie.Application.class)

(Please tell me if I can add any more information to this ticket.)

@Doogiemuc
Copy link
Author

I found a workaround:

Team team = Team.find(Filters.eq("inviteCode", req.inviteCode)).first()     // this works
//Team team = Team.findByInviteCode(req.inviteCode)  // BUG: throws "Internal Server Error: state should be: open"

So in the end this looks like a Groovy Mongo GORM bug ...

@graemerocher graemerocher transferred this issue from micronaut-projects/micronaut-test Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant