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:
parent
6c5a6dba46
commit
5d418e7bd9
@ -26,6 +26,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;
|
||||
@ -42,6 +45,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;
|
||||
@ -56,12 +61,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user