Max Charas
Max Charas

Reputation: 5000

Using specs2 play! fake application with Reactivemongo causes timeouts

We are currently working on an issue where we use specs2 in scala togeather with mongodb/reactivemongo + Play!.

When we run the tests that write to mongodb the first operation runs fine the all subsequent tests/writes fail due to a timeout when to mongodb.

We found what seems to be an already documented bug on the reactive mongo site here: https://github.com/ReactiveMongo/Play-ReactiveMongo/issues/32

Does anyone know a workaround for this issue?

We have already tried:

Any help is greatly appreciated!

Upvotes: 3

Views: 1001

Answers (2)

ersefuril
ersefuril

Reputation: 919

I had timeout too during my tests, and it was a side effect in our Global.onStart() function. We were trying to ensure Mongo indexes with collection.indexesManager.ensure(), which can be a blocking operation according to the documentation.

Since we had tests that were instantiating a new app and writing/reading into database, this indexes lead to a lot of timeout. So, one solution could be to remove any interaction with indexes when you start your application.

I know this post is quite old but hope it can help for other people.

Upvotes: 0

ichaki5748
ichaki5748

Reputation: 2033

You can change (in your Controller/Repo/DAO/Service or whatever you call it):

val db = ReactiveMongoPlugin.db

to

def db = ReactiveMongoPlugin.db

Meaning val to def

Problem occures because calling

play.modules.reactivemongo.ReactiveMongoPlugin#db

returns current database setup so making it val wires it to the first test.

FYI before each test Reactive Mongo Plugin establishes connection to DB and after each test closes it.

Upvotes: 1

Related Questions