0

I have written a few testcases with specs2 in play framework using Slick with MySQL database connection. A Database Connection rejected error is thrown for the later testcase, hence results in failure.

the error thrown is

Task slick.backend.DatabaseComponent$DatabaseDef$$anon$2@4877c5d rejected from java.util.concurrent.ThreadPoolExecutor@48e736[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1] (DatabaseComponent.scala:230)

The code for testcase is written in this format -

class tryTests extends PlaySpecification{
 "Application" should { 
       "test1" in new WithApplication{
            /* Some tests 
        }
       "test2" in new WithApplication{
            /* Some tests 
        }
 }

}

So the test1 will succeed successfully but test2 will fail with above mentioned error.

The sollutions that I've tried so far are

  1. using the "sequential" keyword
  2. using the function override method for "is"
  3. trying to connect with database in "before" part "with BeforeAfterEach"

Above 3 mentioned methods did not work out. Till now according to my understanding the problem is that testcases are being executed concurrently and each one disconnects the database connection. So the later testcase is not able to access the same.

Any suggestion for this problem !!!

Sumit Paliwal
  • 385
  • 1
  • 3
  • 14
  • Try change the config of mysql db, limited the threading pool, e.g. numThreads = 3 – Tom Dec 23 '15 at 14:32
  • I am pretty sure you can run it successfully, as I did. Slick run db access by Future, and you should use Await, or whenReady (extends ScalaFutures first), to run the db, also it used connection pool, the min size of the pool is the numThreads in db config, and the max is numThreads * 5, there is no way connection is closed for next one. Maybe you can paste the real test code here, and your db config too. Or try use mytop to check the connection at server side, and test if there is a too many connection issue. – Tom Jan 27 '16 at 14:26

0 Answers0