3

I have a Play application that defines three different connection configurations in conf/reference.conf. When I run unit tests that require the use of FakeApplication the BoneCP plugin automatically initializes these three connections even when the unit tests do not call any classes that use any database connections. It starts up and shuts down connections for every unit test. This causes unit tests to take forever to complete. Is there a way to lazily start database connections in BoneCP, HikariCP, or some other connection manager, only opening them when they're first used?

I could of course disable BoneCPPlugin altogether inside the relevant unit tests, but what if I have a unit tests that needs one of the connection configurations?

Alex
  • 439
  • 4
  • 8
  • If it needs a database connection, is it _really_ a unit test? – millhouse May 28 '15 at 00:53
  • You're right, it's an integration test, not a unit test. However, They're being invoked as unit tests right now so I'm looking for a solution until we get a chance to move them to a separate integration test suite. – Alex May 28 '15 at 02:34
  • Also, even if we separate these as proper integration tests, we'll still run into the same performance problems. – Alex May 28 '15 at 02:43
  • 1
    You can have a look at http://acolyte.eu.org/ for persistence (not DB) unit testing. – cchantep May 28 '15 at 07:43

1 Answers1

1

For HikariCP, just set initializationFailFast=false and minimumIdle=0.

brettw
  • 10,664
  • 2
  • 42
  • 59
  • I tried adding `play.db.prototype.hikaricp.initializationFailFast=false` and `play.db.prototype.hikaricp.minimumIdle=0` to `application.conf` as well as `initializationFailFast = false` and `minimumIdle = 0` to `reference.conf` inside the `db.` section and although it seems to speed things up, it's still making unnecessary connections to the databases. I'm seeing lots of "_Creating Pool for datasource _" messages when running unit tests. – Alex May 28 '15 at 19:13
  • 1
    If the message you are getting is "Creating Pool for datasource " then this is a message coming from Play. I recommend asking on the Play Google Group. – brettw May 29 '15 at 06:08