2011-11-15 96 views
2

我不斷收到Playframework功能測試java.util.concurrent.TimeoutException

java.util.concurrent.TimeoutException 

運行的,自從我遷移到Postgres的從MEM分貝我的功能測試時。

Http.Response response = GET("/services/names/"); 
    assertIsOk(response); 

完整的錯誤消息

java.lang.RuntimeException: java.util.concurrent.TimeoutException 
    at play.test.FunctionalTest.makeRequest(FunctionalTest.java:291) 
    at play.test.FunctionalTest.makeRequest(FunctionalTest.java:297) 
    at play.test.FunctionalTest.GET(FunctionalTest.java:100) 
    at play.test.FunctionalTest.GET(FunctionalTest.java:54) 
    at controllers.ImagesTest.shouldReturnListOfImages(ImagesTest.java:25) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at play.test.PlayJUnitRunner$StartPlay$2$1.evaluate(PlayJUnitRunner.java:98) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
    at play.test.PlayJUnitRunner.run(PlayJUnitRunner.java:48) 
    at org.junit.runners.Suite.runChild(Suite.java:128) 
    at org.junit.runners.Suite.runChild(Suite.java:24) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:136) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:117) 
    at play.test.TestEngine.run(TestEngine.java:101) 
    at controllers.TestRunner.run(TestRunner.java:67) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:546) 
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:500) 
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:476) 
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:471) 
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:159) 
    at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:220) 
    at play.Invoker$Invocation.run(Invoker.java:265) 
    at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:200) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98) 
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:680) 
Caused by: java.util.concurrent.TimeoutException 
    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:228) 
    at java.util.concurrent.FutureTask.get(FutureTask.java:91) 
    at play.test.FunctionalTest.makeRequest(FunctionalTest.java:278) 
+0

你在做什麼「/ services/name」調用?從mem db移動到PostgreSQL不應該破壞測試本身,除非你的模型不是PostgreSQL兼容的(使用保留關鍵字等),在這種情況下,這個錯誤可能掩蓋了真正的問題 –

回答

0

你可能需要增加你的線程池的大小。默認情況下,測試在DEV模式下運行,並DEV模式有1.看的線程池大小此行您application.conf

play.pool = 1

看看是否增加該值將幫幫我。

+0

不工作:( – lemon

1

對於每個請求 (參見Play 1.2.3中的FunctionalTest.java:278),功能測試的內置超時爲30秒硬編碼。也許你的測試在postgres上持續那麼久?

1

您遇到了一個死鎖:測試運行的事務和運行該事件的事務正如1.2 release notes中所解釋的那樣發生混淆。不幸的是,這是因爲即使你指定它使用SET TRANSACTION不能使用PostgreSQL中READ UNCOMMITED隔離級別,the transaction isolation level will still be READ COMMITTED

你可以做的是,確保在測試代碼中的交易在操作交易之前犯下的測試代碼調用啓動。例如

@Test 
public void testSomething() { 
    Fixtures.loadModels("models.yml"); 
    JPA.em().getTransaction().commit(); 

    // Call a controller 
} 

另一種方法是使用內存數據庫運行測試。