Make EpollSocketChannelConfigTest tollerant of fd reuse race (#11552)

Motivation:
We cannot control when "the system" reuses file descriptors.
This makes any test that assert on the behaviour of closed file descriptors inherently racy.

Modification:
Allow the EpollSocketChannelConfigTest socketoption tests a few tries to get the correct assertion on the behaviour of closed socket file descriptors.

Result:
The EpollSocketChannelConfigTest should now be much less flaky.
This commit is contained in:
Chris Vest 2021-08-06 08:45:24 +02:00
parent 6d6d2060af
commit 6c2813bdb0
3 changed files with 20 additions and 2 deletions

View File

@ -815,6 +815,12 @@
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.artsok</groupId>
<artifactId>rerunner-jupiter</artifactId>
<version>2.1.6</version>
<scope>test</scope>
</dependency>
<!-- Test dependencies for jboss marshalling encoder/decoder -->
<dependency>

View File

@ -399,6 +399,11 @@
<classifier>${tcnative.classifier}</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.artsok</groupId>
<artifactId>rerunner-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -15,6 +15,7 @@
*/
package io.netty.channel.epoll;
import io.github.artsok.RepeatedIfExceptionsTest;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelHandler;
@ -137,7 +138,10 @@ public class EpollSocketChannelConfigTest {
assertTrue(ch.config().isTcpQuickAck());
}
@Test
// For this test to pass, we are relying on the sockets file descriptor not being reused after the socket is closed.
// This is inherently racy, so we allow getSoLinger to throw ChannelException a few of times, but eventually we do
// want to see a ClosedChannelException for the test to pass.
@RepeatedIfExceptionsTest(repeats = 4, exceptions = ChannelException.class)
public void testSetOptionWhenClosed() {
ch.close().syncUninterruptibly();
try {
@ -148,7 +152,10 @@ public class EpollSocketChannelConfigTest {
}
}
@Test
// For this test to pass, we are relying on the sockets file descriptor not being reused after the socket is closed.
// This is inherently racy, so we allow getSoLinger to throw ChannelException a few of times, but eventually we do
// want to see a ClosedChannelException for the test to pass.
@RepeatedIfExceptionsTest(repeats = 4, exceptions = ChannelException.class)
public void testGetOptionWhenClosed() {
ch.close().syncUninterruptibly();
try {