This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.8 by this push:
new 6adc1205e19 [fix][test] Fix flaky test NarUnpackerTest (#21328)
6adc1205e19 is described below
commit 6adc1205e199ea72ad3879468076245a0325cee4
Author: Lari Hotari <[email protected]>
AuthorDate: Mon Oct 9 16:26:25 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 | 27 +++++++++++++++-------
1 file changed, 19 insertions(+), 8 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 1d2acd0fa4e..8e7e38dea68 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();