mardi 25 août 2015

Play framework sequential testing

So I wrote my first few integration tests and tried them out one-by-one. They worked correctly. Then when I take them to one test class and run them together 2 out of 3 are always failing but never the same.

The root of the problem is when we start the play server, the plays onStart starting an another server on another port. When the tests run, these play servers with there companions are starting to run simultaneously. My tests connecting to the companion servers (sending rest requests), but when the first play server is stoping the other tests fails with

Connection refused: no further information: localhost/127.0.0.1:9001 to http://localhost:9001/version (NettyConnec tListener.java:104)

My guessing is that only the first companion server bind the port, and the tests run against that app only, so when the first test is executed and the first apps companion server is releasing the port, the other requests are refused.

After a day of googleing:

The play fw uses sbt where you can switch off the paralell test runing with:

parallelExecution in Test := false
testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "sequential", "true", "junitxml", "console")
fork in Test := true
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)

(If you read the documentations the top one must be enought.)

These are not working, my tests still failing (my log still contain start-start-stop-stop sequences instead of start-stop-start-stop). So I can add magic things to my test-class too, like:

override def is = args(sequential = true) ^ super.is

or the sequential keyword. None of them helped.

Versions: specs2 3.5; play 2.3.8; scala 2.11.1

I have 3 workaround, but all of them is bad in some kind of view:

  • I can make all test-case to a test-class (classes run sequentially)
  • I can make some test-case to one test-case
  • I can use locks or synchronized

If somebody meet these kind of problems before, and can give me a helping hand that would be nice.

Aucun commentaire:

Enregistrer un commentaire