Make kernel version detection code in EpollReuseAddrTest more robust (#10556)

Motivation:

When we try to parse the kernel version we need to be careful what to
expect. Especially when a custom kernel is used we may get extra chars
in the version numbers. For example I had this one fail because of my
custom kernel that I built for io_uring:

5.8.7ioring-fixes+

Modifications:

- Try to be a bit more lenient when parsing
- If we cant parse the kernel version just use 0.0.0

Result:

Tests are more robust
This commit is contained in:
Norman Maurer 2020-09-09 15:51:37 +02:00 committed by GitHub
parent b43ce7ae1d
commit 5631f1b2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,9 @@ import io.netty.handler.logging.LoggingHandler;
import io.netty.util.NetUtil;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.internal.logging.InternalLogLevel;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Ignore;
@ -44,6 +47,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
public class EpollReuseAddrTest {
private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(EpollReuseAddrTest.class);
private static final int MAJOR;
private static final int MINOR;
private static final int BUGFIX;
@ -58,12 +63,24 @@ public class EpollReuseAddrTest {
MAJOR = Integer.parseInt(versionParts[0]);
MINOR = Integer.parseInt(versionParts[1]);
if (versionParts.length == 3) {
BUGFIX = Integer.parseInt(versionParts[2]);
int bugFix;
try {
bugFix = Integer.parseInt(versionParts[2]);
} catch (NumberFormatException ignore) {
// the last part of the version may include all kind of different things. Especially when
// someone compiles his / her own kernel.
// Just ignore a parse error here and use 0.
bugFix = 0;
}
BUGFIX = bugFix;
} else {
BUGFIX = 0;
}
} else {
throw new IllegalStateException("Can not parse kernel version " + kernelVersion);
LOGGER.log(InternalLogLevel.INFO, "Unable to parse kernel version: " + kernelVersion);
MAJOR = 0;
MINOR = 0;
BUGFIX = 0;
}
}