3

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:

  • Forcing the tests to be run in sequence
  • Each test running in its own fake application
  • Running all tests in the same fake application
  • Defining the collection as a def (as suggested in the issue 32 above)

Any help is greatly appreciated!

Max Charas
  • 4,980
  • 3
  • 20
  • 40

2 Answers2

1

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.

ichaki5748
  • 1,993
  • 1
  • 14
  • 13
0

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.

ersefuril
  • 809
  • 9
  • 16