You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2024/06/10 09:31:46 UTC

(lucene) branch main updated: Silence odd test runner warnings after gradle upgrade (#13471)

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

dweiss pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 06f86a50968 Silence odd test runner warnings after gradle upgrade (#13471)
06f86a50968 is described below

commit 06f86a50968cbc0cdcc357de3aad794e6f1790cb
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Mon Jun 10 11:31:40 2024 +0200

    Silence odd test runner warnings after gradle upgrade (#13471)
---
 gradle/testing/defaults-tests.gradle               |  7 +++++-
 .../lucene/codecs/TestCodecLoadingDeadlock.java    | 29 +++++++++++++++++-----
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/gradle/testing/defaults-tests.gradle b/gradle/testing/defaults-tests.gradle
index d8ee3cedaf0..db121a10988 100644
--- a/gradle/testing/defaults-tests.gradle
+++ b/gradle/testing/defaults-tests.gradle
@@ -133,7 +133,12 @@ allprojects {
         jvmArgs '--add-modules', 'jdk.incubator.vector'
       }
       
-      jvmArgs '--enable-native-access=' + (project.path == ':lucene:core' ? 'ALL-UNNAMED' : 'org.apache.lucene.core')
+      jvmArgs '--enable-native-access=' + (project.path in [
+              ':lucene:core',
+              ':lucene:codecs',
+              ":lucene:distribution.tests",
+              ":lucene:test-framework"
+      ] ? 'ALL-UNNAMED' : 'org.apache.lucene.core')
 
       def loggingConfigFile = layout.projectDirectory.file("${resources}/logging.properties")
       def tempDir = layout.projectDirectory.dir(testsTmpDir.toString())
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/TestCodecLoadingDeadlock.java b/lucene/core/src/test/org/apache/lucene/codecs/TestCodecLoadingDeadlock.java
index 854e271eb12..0e0c3941bec 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/TestCodecLoadingDeadlock.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/TestCodecLoadingDeadlock.java
@@ -16,8 +16,12 @@
  */
 package org.apache.lucene.codecs;
 
+import com.carrotsearch.randomizedtesting.LifecycleScope;
 import com.carrotsearch.randomizedtesting.RandomizedContext;
 import com.carrotsearch.randomizedtesting.RandomizedRunner;
+import com.carrotsearch.randomizedtesting.RandomizedTest;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -34,6 +38,7 @@ import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import org.apache.lucene.tests.util.LuceneTestCase;
 import org.apache.lucene.util.NamedThreadFactory;
+import org.apache.lucene.util.SuppressForbidden;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -46,6 +51,7 @@ public class TestCodecLoadingDeadlock extends Assert {
   private static final int MAX_TIME_SECONDS = 30;
 
   @Test
+  @SuppressForbidden(reason = "Uses Path.toFile because ProcessBuilder requires it.")
   public void testDeadlock() throws Exception {
     // pick random codec names for stress test in separate process:
     final Random rnd = RandomizedContext.current().getRandom();
@@ -67,12 +73,23 @@ public class TestCodecLoadingDeadlock extends Assert {
     args.addAll(List.of(getClass().getName(), codecName, pfName, dvfName));
 
     // Fork a separate JVM to reinitialize classes.
-    final Process p = new ProcessBuilder(args).inheritIO().start();
-    if (p.waitFor(MAX_TIME_SECONDS * 2, TimeUnit.SECONDS)) {
-      assertEquals("Process died abnormally?", 0, p.waitFor());
-    } else {
-      p.destroyForcibly().waitFor();
-      fail("Process did not exit after 60 secs?");
+    final Path output = RandomizedTest.newTempFile(LifecycleScope.TEST);
+    final Process p =
+        new ProcessBuilder(args).redirectErrorStream(true).redirectOutput(output.toFile()).start();
+    boolean success = false;
+    try {
+      if (p.waitFor(MAX_TIME_SECONDS * 2, TimeUnit.SECONDS)) {
+        assertEquals("Process died abnormally?", 0, p.waitFor());
+        success = true;
+      } else {
+        p.destroyForcibly().waitFor();
+        fail("Process did not exit after 60 secs?");
+      }
+    } finally {
+      if (!success) {
+        System.out.println("Subprocess emitted the following output:");
+        System.out.write(Files.readAllBytes(output));
+      }
     }
   }