Skip to content

Commit

Permalink
(chores) core: wait for I/O to reduce flakiness (apache#12353)
Browse files Browse the repository at this point in the history
In slow systems, the interval between the exchange completion and the data being written to the disk may cause the test to read an empty file. This should give an extra time for that to happen.
  • Loading branch information
orpiske authored Dec 7, 2023
1 parent 0473b63 commit 9c18415
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ public Path testDirectory() {
}

protected Path testFile(String file) {
return testDirectory().resolve(file);
return testFile(testDirectory(), file);
}

protected static Path testFile(Path testDirectory, String file) {
return testDirectory.resolve(file);
}

protected Path testDirectory(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -57,12 +60,16 @@ void cleanupFile() {
}
}

@RepeatedTest(10)
@Test
void testFileProducerCharsetUTFtoISOConvertBodyTo() throws Exception {
assertTrue(oneExchangeDone.matchesWaitTime());

assertFileExists(testFile("output.txt"));
byte[] data = Files.readAllBytes(testFile("output.txt"));
final Path outputFile = testFile("output.txt");

Awaitility.await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertFileExists(outputFile));
Awaitility.await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertTrue(Files.size(outputFile) > 0));

byte[] data = Files.readAllBytes(outputFile);

assertEquals(DATA, new String(data, StandardCharsets.ISO_8859_1));
}
Expand Down

0 comments on commit 9c18415

Please sign in to comment.