You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2023/10/09 13:21:53 UTC

[pulsar] branch branch-2.11 updated: [fix][test] Fix flaky test NarUnpackerTest (#21328)

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

lhotari pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.11 by this push:
     new ac7b5937787 [fix][test] Fix flaky test NarUnpackerTest (#21328)
ac7b5937787 is described below

commit ac7b5937787c6b6ab923934f00305dec5f138dfc
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Mon Oct 9 15:51:16 2023 +0300

    [fix][test] Fix flaky test NarUnpackerTest (#21328)
    
    (cherry picked from commit e76a86e3cd1c362e9daa1c88eb8b888e6ab38ab4)
    
    # Conflicts:
    #       pulsar-common/src/test/java/org/apache/pulsar/common/nar/NarUnpackerTest.java
---
 .../apache/pulsar/common/nar/NarUnpackerTest.java  | 29 +++++++++++++++-------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/pulsar-common/src/test/java/org/apache/pulsar/common/nar/NarUnpackerTest.java b/pulsar-common/src/test/java/org/apache/pulsar/common/nar/NarUnpackerTest.java
index 1f97b1b1b69..ddfdf55db40 100644
--- a/pulsar-common/src/test/java/org/apache/pulsar/common/nar/NarUnpackerTest.java
+++ b/pulsar-common/src/test/java/org/apache/pulsar/common/nar/NarUnpackerTest.java
@@ -46,7 +46,7 @@ public class NarUnpackerTest {
     public void createSampleZipFile() throws IOException {
         sampleZipFile = Files.createTempFile("sample", ".zip").toFile();
         try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(sampleZipFile))) {
-            for (int i = 0; i < 10000; i++) {
+            for (int i = 0; i < 5000; i++) {
                 ZipEntry e = new ZipEntry("hello" + i + ".txt");
                 out.putNextEntry(e);
                 byte[] msg = "hello world!".getBytes(StandardCharsets.UTF_8);
@@ -58,12 +58,20 @@ public class NarUnpackerTest {
     }
 
     @AfterMethod(alwaysRun = true)
-    void deleteSampleZipFile() throws IOException {
-        if (sampleZipFile != null) {
-            sampleZipFile.delete();
+    void deleteSampleZipFile() {
+        if (sampleZipFile != null && sampleZipFile.exists()) {
+            try {
+                sampleZipFile.delete();
+            } catch (Exception e) {
+                log.warn("Failed to delete file {}", sampleZipFile, e);
+            }
         }
-        if (extractDirectory != null) {
-            FileUtils.deleteFile(extractDirectory, true);
+        if (extractDirectory != null && extractDirectory.exists()) {
+            try {
+                FileUtils.deleteFile(extractDirectory, true);
+            } catch (IOException e) {
+                log.warn("Failed to delete directory {}", extractDirectory, e);
+            }
         }
     }
 
@@ -111,7 +119,7 @@ public class NarUnpackerTest {
 
     @Test
     void shouldExtractFilesOnceInDifferentProcess() throws InterruptedException {
-        int processes = 10;
+        int processes = 5;
         String javaExePath = findJavaExe().getAbsolutePath();
         CountDownLatch countDownLatch = new CountDownLatch(processes);
         AtomicInteger exceptionCounter = new AtomicInteger();
@@ -122,7 +130,9 @@ public class NarUnpackerTest {
                     // fork a new process with the same classpath
                     Process process = new ProcessBuilder()
                             .command(javaExePath,
-                                    "-Xmx64m",
+                                    "-Xmx96m",
+                                    "-XX:TieredStopAtLevel=1",
+                                    "-Dlog4j2.disable.jmx=true",
                                     "-cp",
                                     System.getProperty("java.class.path"),
                                     // use NarUnpackerWorker as the main class
@@ -130,6 +140,7 @@ public class NarUnpackerTest {
                                     // pass arguments to use for testing
                                     sampleZipFile.getAbsolutePath(),
                                     extractDirectory.getAbsolutePath())
+                            .redirectErrorStream(true)
                             .start();
                     String output = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8);
                     int retval = process.waitFor();
@@ -147,7 +158,7 @@ public class NarUnpackerTest {
                 }
             }).start();
         }
-        assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
+        assertTrue(countDownLatch.await(30, TimeUnit.SECONDS), "All processes should finish before timeout");
         assertEquals(exceptionCounter.get(), 0);
         assertEquals(extractCounter.get(), 1);
     }