You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While creating unit tests to handle some command line output and exceptions thrown in an application, I decided to use SystemErrRule and SystemOutRule to assist with this.
As this particular test is for the main entry point of the application, it is parsing the command line and calling System.exit(1) when invalid command line arguments have been provided.
However, including both of these causes Gradle to throw an exception when trying to run the task gradlew test:
:test
Unexpected exception thrown.
org.gradle.messaging.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:50239'.
at org.gradle.messaging.remote.internal.inet.SocketConnection.receive(SocketConnection.java:79)
at org.gradle.messaging.remote.internal.hub.MessageHub$ConnectionReceive.run(MessageHub.java:235)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.esotericsoftware.kryo.KryoException: java.io.IOException: An existing connection was forcibly closed by the remote host
at com.esotericsoftware.kryo.io.Input.fill(Input.java:141)
at com.esotericsoftware.kryo.io.Input.require(Input.java:159)
at com.esotericsoftware.kryo.io.Input.readByte(Input.java:255)
at org.gradle.internal.serialize.kryo.KryoBackedDecoder.readByte(KryoBackedDecoder.java:80)
at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageReader.read(InterHubMessageSerializer.java:69)
at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageReader.read(InterHubMessageSerializer.java:58)
at org.gradle.messaging.remote.internal.inet.SocketConnection.receive(SocketConnection.java:74)
... 6 more
Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(Unknown Source)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.read(Unknown Source)
at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
at org.gradle.messaging.remote.internal.inet.SocketConnection$SocketInputStream.read(SocketConnection.java:158)
at com.esotericsoftware.kryo.io.Input.fill(Input.java:139)
... 12 more
Unexpected exception thrown.
org.gradle.messaging.remote.internal.MessageIOException: Could not write message [EndOfStream] to '/127.0.0.1:50239'.
at org.gradle.messaging.remote.internal.inet.SocketConnection.dispatch(SocketConnection.java:106)
at org.gradle.messaging.remote.internal.hub.MessageHub$ConnectionDispatch.run(MessageHub.java:284)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(Unknown Source)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.write(Unknown Source)
at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
at org.gradle.messaging.remote.internal.inet.SocketConnection$SocketOutputStream.flush(SocketConnection.java:221)
at org.gradle.messaging.remote.internal.inet.SocketConnection.dispatch(SocketConnection.java:104)
... 6 more
:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> Process 'Gradle Test Executor 1' finished with non-zero exit value 1
In IntelliJ, trying to run this test results in the error response "Failed to start: 0 passed, 1 not started" - so it isn't isolated to Gradle.
Here is an example setup that can reproduce this issue:
packageorg.test.example;
importorg.junit.Rule;
importorg.junit.Test;
importorg.junit.contrib.java.lang.system.ExpectedSystemExit;
importorg.junit.contrib.java.lang.system.SystemErrRule;
importorg.junit.contrib.java.lang.system.SystemOutRule;
importorg.junit.runner.RunWith;
importorg.powermock.core.classloader.annotations.PrepareForTest;
importorg.powermock.modules.junit4.PowerMockRunner;
importstaticorg.junit.Assert.assertFalse;
importstaticorg.junit.Assert.assertTrue;
@RunWith(PowerMockRunner.class)
@PrepareForTest(Program.class)
publicclassProgramTest
{
/** Handles System.exit() calls. */@RuleprivatefinalExpectedSystemExitexit = ExpectedSystemExit.none();
/** Handles System.err calls. */@RuleprivatefinalSystemErrRuleerr = newSystemErrRule().enableLog().muteForSuccessfulTests();
/** Handles System.out calls. */@RuleprivatefinalSystemOutRuleout = newSystemOutRule().enableLog().muteForSuccessfulTests();
/** * Verify server does not run when only a single valid command line * parameter is provided. * * @throws Exception On error. */@TestpublicvoidtestMainOneParameterPort() throwsException
{
expectExit();
Program.main(newString[] { "-port" });
}
/** * Helper function to setup System.exit() expectations */privatevoidexpectExit()
{
exit.expectSystemExitWithStatus(1);
exit.checkAssertionAfterwards(() ->
{
assertFalse(out.getLog().isEmpty());
assertTrue(err.getLog().isEmpty());
});
}
}
Environment Configuration:
Windows 10 Pro x64 10.0.10586
Oracle JDK/JRE x64 1.8.0_66
Gradle 2.5
JUnit 4.12
System Rules 1.15.1
Mockito 1.10.19
PowerMock 1.6.4
The text was updated successfully, but these errors were encountered:
ghost
changed the title
ExpectedSystemExit and SystemErrRule or SystemOutRule cause Gradle to throw org.gradle.messaging.remote.internal.MessageIOException when used in the same test
ExpectedSystemExit and SystemErrRule or SystemOutRule cause Gradle to throw MessageIOException when used in the same test
Jan 3, 2016
This is a PowerMock issue: powermock/powermock#427. I created a pull request for PowerMock that solves the problem. I found a workaround, too. The issue does not apply if there is only one rule for a test. This can be achieved by using org.junit.rules.RuleChain:
While creating unit tests to handle some command line output and exceptions thrown in an application, I decided to use SystemErrRule and SystemOutRule to assist with this.
As this particular test is for the main entry point of the application, it is parsing the command line and calling System.exit(1) when invalid command line arguments have been provided.
However, including both of these causes Gradle to throw an exception when trying to run the task
gradlew test
:In IntelliJ, trying to run this test results in the error response "Failed to start: 0 passed, 1 not started" - so it isn't isolated to Gradle.
Here is an example setup that can reproduce this issue:
Program.java:
ProgramTest.java:
Environment Configuration:
The text was updated successfully, but these errors were encountered: