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 12:51:25 UTC
[pulsar] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new e76a86e3cd1 [fix][test] Fix flaky test NarUnpackerTest (#21328)
e76a86e3cd1 is described below
commit e76a86e3cd1c362e9daa1c88eb8b888e6ab38ab4
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Mon Oct 9 15:51:16 2023 +0300
[fix][test] Fix flaky test NarUnpackerTest (#21328)
---
.../apache/pulsar/common/nar/NarUnpackerTest.java | 31 +++++++++++++++-------
1 file changed, 21 insertions(+), 10 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 b331c751dcf..a1f915c8b78 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
@@ -38,7 +38,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@Slf4j
-@Test(groups = "flaky")
+@Test
public class NarUnpackerTest {
File sampleZipFile;
File extractDirectory;
@@ -47,7 +47,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);
@@ -59,12 +59,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);
+ }
}
}
@@ -112,7 +120,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();
@@ -123,7 +131,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
@@ -131,6 +141,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();
@@ -148,7 +159,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);
}