This is an automated email from the ASF dual-hosted git repository.

maoling pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new e2ea0381f ZOOKEEPER-4779: Fix ZKUtilTest which fails to run on WSL
e2ea0381f is described below

commit e2ea0381f4b41ff05d86d6fbd0ed58a5d9dc9915
Author: Muthuraj Ramalingakumar <[email protected]>
AuthorDate: Wed Feb 7 01:30:23 2024 -0800

    ZOOKEEPER-4779: Fix ZKUtilTest which fails to run on WSL
    
    Reviewers: maoling
    Author: muthu90tech
    Closes #2099 from muthu90tech/ZOOKEEPER-4779
---
 .../src/main/java/org/apache/zookeeper/Shell.java    | 20 ++++++++++++++++++++
 .../test/java/org/apache/zookeeper/ZKUtilTest.java   |  5 +++--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/Shell.java 
b/zookeeper-server/src/main/java/org/apache/zookeeper/Shell.java
index d59079f5f..f780ff985 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/Shell.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/Shell.java
@@ -33,10 +33,12 @@ import java.io.BufferedReader;
 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;
@@ -105,6 +107,24 @@ public abstract class Shell {
         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");
 
diff --git 
a/zookeeper-server/src/test/java/org/apache/zookeeper/ZKUtilTest.java 
b/zookeeper-server/src/test/java/org/apache/zookeeper/ZKUtilTest.java
index a73ff2fa7..21dad4c50 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/ZKUtilTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/ZKUtilTest.java
@@ -80,8 +80,9 @@ public class ZKUtilTest extends ClientBase {
 
     @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();

Reply via email to