Skip to content

Commit

Permalink
ZOOKEEPER-4779: Fix ZKUtilTest which fails to run on WSL
Browse files Browse the repository at this point in the history
Reviewers: maoling
Author: muthu90tech
Closes #2099 from muthu90tech/ZOOKEEPER-4779
  • Loading branch information
muthu90tech authored Feb 7, 2024
1 parent 07f5cc6 commit e2ea038
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions zookeeper-server/src/main/java/org/apache/zookeeper/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.io.FileUtils;
import org.apache.zookeeper.common.Time;
import org.apache.zookeeper.server.ExitCode;
import org.slf4j.Logger;
Expand Down Expand Up @@ -105,6 +107,24 @@ public static String[] getUlimitMemoryCommand(int memoryLimit) {
return new String[]{ULIMIT_COMMAND, "-v", String.valueOf(memoryLimit)};
}

/**
* Check if running in Windows Subsystem for Linux
* @return
* @throws IOException
*/
public static boolean isWsl() throws IOException {
if (WINDOWS) {
return false;
}
final File f = new File("/proc/version");
if (!f.exists()) {
return false;
}
final String output = FileUtils.readFileToString(f, StandardCharsets.UTF_8.name());
return (output != null)
&& System.getProperty("os.name").startsWith("Linux") && output.toLowerCase().contains("microsoft");
}

/** Set to true on Windows platforms */
public static final boolean WINDOWS /* borrowed from Path.WINDOWS */ = System.getProperty("os.name").startsWith("Windows");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public void testValidateFileInputDirectory() throws Exception {

@Test
public void testUnreadableFileInput() throws Exception {
//skip this test on Windows, coverage on Linux
assumeTrue(!org.apache.zookeeper.Shell.WINDOWS);
//skip this test on Windows and WSL, coverage on Linux
assumeTrue("Skipping this test on Windows and WSL",
!(org.apache.zookeeper.Shell.WINDOWS || org.apache.zookeeper.Shell.isWsl()));
File file = File.createTempFile("test", ".junit", testData);
file.setReadable(false, false);
file.deleteOnExit();
Expand Down

0 comments on commit e2ea038

Please sign in to comment.