我有一个包含大约一千个测试用例的测试套件。它们都运行成功,但 TestNG 在最后挂起。我在六个线程中运行测试。每个测试都正确运行到完成,但最后一个测试只是挂起。它已经完成了所有的工作,但只是坐在那里。
这种情况发生的概率大约为 20%。我每天都运行同一个套件 - 没有代码更改并且在同一个构建代理上运行。大多数日子里,套件成功完成并终止,但每周至少有一个随机的日子(它会有所不同),运行不会终止。它会一直坐在那里,直到我的构建代理看到它已达到超时,然后它会以这种方式终止。
这是日志的一些输出:
07:05:00 Test1000 -- Successfully generated and stored form
07:05:00 Test1000 -- Completed -- ThreadID: 18
09:00:17 The build MySuite #392 {buildId=6352946} has been running for more than 240 minutes. Terminating...
09:00:17 Execution timeout
09:00:17 Stopping build on agent. Reason: build execution timeout
09:00:22 PID: 9976, PPID: 1056, Command line: "C:\Program Files\Java\jdk1.8.0_221\bin\java.exe" -DAppType=392 -DBuildBranch=392 -DFxCopCmdFileVersion=16.0.32413.511 "-DFxCopRoot=D:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Static Analysis Tools\FxCop"
09:00:22 2023-03-03 09:00:22
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.221-b11 mixed mode):
"Thread-5" #31 prio=5 os_prio=0 tid=0x0000000015541000 nid=0xf50 runnable [0x000000001d16f000]
java.lang.Thread.State: RUNNABLE
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:255)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
- locked <0x00000000fd7d5ba8> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
- locked <0x00000000fd7d5ba8> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at org.apache.maven.surefire.shade.org.apache.maven.shared.utils.cli.StreamPumper.run(StreamPumper.java:76)
"ThreadedStreamConsumer" #27 daemon prio=5 os_prio=0 tid=0x0000000016d01000 nid=0x26e0 waiting on condition [0x000000001ce6f000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000fc4a8940> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:403)
at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:83)
at java.lang.Thread.run(Thread.java:748)
在日志的下方我看到了这个:
"TestNG-test=Regression-6" #18 prio=8 os_prio=1 tid=0x000000001e087000 nid=0x28dc waiting on condition [0x00000000207ce000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006c0546670> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
"TestNG-test=Regression-5" #17 prio=8 os_prio=1 tid=0x000000001e086000 nid=0x20d8 waiting on condition [0x00000000206cf000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006c0546670> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
这已经发生几个月了,我无法找出根本原因。有没有其他人看到这种行为或想出解决方案?
我目前正在使用 Java 8 运行 TestNG 7.5。