'Why is some code run on the "Time-limited test" thread instead of the main thread?

I have some tests. I notice that sometime my log messages indicate that the code is running on the main thread. Other log messages indicate that the code is running on the "Time-limited test" thread. Many of my tests have a timeout specified.

00000 Time-limt WARNING start gtp2: (a model-18 (0,1) ...

00001 Time-limt WARNING response2: = A1

00002 main WARNING named threads! ...

Edit 1. The "Time-limited test" thread is started by FailOnTimeout() (please see below). The elapsed time in milliseconds is give as well as the timeout time (200 ms.). I have a few hundred tests that are similar but only a dozen or so timeout on me. In all cases the elapsed time is less than the timeout value for the test.

These tests start up one to five threads, run some test, and then try to shutdown gracefully by interrupting and joining.

00000 Time-limt SEVERE not main! 'Time-limited test' 1.491111 ms. 200 ms. in controller.GTPBackEnd.startGTP() controller.GTPBackEnd.startGTP(GTPBackEnd.java:50) controller.ABothTestCase.testBothGenmoveTrue(ABothTestCase.java:39) java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.base/java.lang.reflect.Method.invoke(Method.java:568) org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299) org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293) java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)



Solution 1:[1]

This will be an artifact of the code that you are testing. The message refers to a "time-limt" (sic) thread. That spelling error is a big clue1 that the thread doesn't belong to the JUnit test framework.

So, my guess is that the application code that you are testing creates a thread and names it "time-limt". That thread generates log messages. Some test (running on the "main" thread) calls the application code (on the "main" thread) ... which interacts with the "time-limt" thread ... which produces the log messages.

In short, those messages are not direct evidence that the test are running on different threada.


1 - If you doubt my inference, download the source code for the version of JUnit you are using, and search for the string time-limt. I could be wrong.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1