Slick unit testing - duplicate statements in logs

58 views Asked by At

I have a suit of tests for slick in playframework environment, but when they are run, the statements are duplicated in logs, and it seems that they are duplicated as many times as number of tests. So if I have only one test I have one e.g. insert and select statement, but with few I have situation like that:

[info] c.z.h.HikariDataSource - HikariCP pool db is starting.
[info] c.z.h.HikariDataSource - HikariCP pool db is starting.
[info] a.e.s.Slf4jLogger - Slf4jLogger started
[info] c.z.h.HikariDataSource - HikariCP pool db is starting.
[info] c.z.h.HikariDataSource - HikariCP pool db is starting.
[info] a.e.s.Slf4jLogger - Slf4jLogger started
[info] a.e.s.Slf4jLogger - Slf4jLogger started
[debug] s.j.J.statement - Preparing insert statement (returning: ID): insert into `USER` (`EMAIL`,`PASSWORD`,`ACTIVATION_TOKEN`,`ACTIVATED`,`CREATED`)  values (?,?,?,?,?)
[debug] s.j.J.statement - Preparing insert statement (returning: ID): insert into `USER` (`EMAIL`,`PASSWORD`,`ACTIVATION_TOKEN`,`ACTIVATED`,`CREATED`)  values (?,?,?,?,?)
[debug] s.j.J.statement - Preparing statement: select `ACTIVATION_TOKEN`, `PASSWORD`, `ACTIVATED`, `CREATED`, `EMAIL`, `ID` from `USER` where `EMAIL` = '[email protected]' limit 1
[debug] s.j.J.statement - Preparing statement: select `ACTIVATION_TOKEN`, `PASSWORD`, `ACTIVATED`, `CREATED`, `EMAIL`, `ID` from `USER` where `EMAIL` = '[email protected]' limit 1
[info] c.z.h.p.HikariPool - HikariCP pool db is shutting down.
[info] c.z.h.p.HikariPool - HikariCP pool db is shutting down.
[info] c.z.h.HikariDataSource - HikariCP pool db is starting.
[info] c.z.h.HikariDataSource - HikariCP pool db is starting.
[info] c.z.h.p.HikariPool - HikariCP pool db is shutting down.
[info] c.z.h.p.HikariPool - HikariCP pool db is shutting down.

In database state results look correct - there are no redundant statements, only these logs concerns me. "Slf4jLogger started" message is 10 times, so it's not because of parallel execution of tests. Number of duplicates is up to number of tests (currently 4), they are placed sequentially so no other statements from other parallel execution between. Unit code:

class UserSpec extends PlaySpecification {

    val userRepo = Injector.inject[UserRepo]

    import scala.concurrent.ExecutionContext.Implicits.global

    def fakeApp: FakeApplication = {
      FakeApplication(additionalConfiguration =
        Map(
          "slick.dbs.default.driver" -> "slick.driver.H2Driver$",
          "slick.dbs.default.db.driver" -> "org.h2.Driver",
          "slick.dbs.default.db.url" -> "jdbc:h2:mem:test;MODE=MySQL;DATABASE_TO_UPPER=FALSE"
        ))}

    "User" should {
      "be created as not activated" in new WithApplication(fakeApp) {
        val email = "[email protected]"
        val action = userRepo.create(email, "Password")
            .flatMap(_ => userRepo.findByEmail(email))

        val result = Await.result(action, Duration.Inf)
        result must not(beNone)
        result.map {
          case User(id, email2, _, _, activated, _) => {
            activated must beFalse
            email2 must beEqualTo(email)
          }
        }
      }

      "cannot be create if same email" in new WithApplication(fakeApp) {
        val email = "[email protected]"
        val action = userRepo.create(email, "Password")
          .flatMap(_ => userRepo.create(email, "Password"))

        val result = Await.result(action, Duration.Inf)
        result must beNone
      }
// rest omitted
}
0

There are 0 answers