From 2d03d631fa9d4083379b5bb7cebf3da4021ea136 Mon Sep 17 00:00:00 2001 From: Varun Bharadwaj Date: Wed, 22 Oct 2025 12:08:42 -0700 Subject: [PATCH] fix flaky test for file-based indexing Signed-off-by: Varun Bharadwaj --- .../ingestion/fs/FileBasedIngestionSingleNodeTests.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/ingestion-fs/src/test/java/org/opensearch/plugin/ingestion/fs/FileBasedIngestionSingleNodeTests.java b/plugins/ingestion-fs/src/test/java/org/opensearch/plugin/ingestion/fs/FileBasedIngestionSingleNodeTests.java index 555b0d0152e21..8fa97723cf206 100644 --- a/plugins/ingestion-fs/src/test/java/org/opensearch/plugin/ingestion/fs/FileBasedIngestionSingleNodeTests.java +++ b/plugins/ingestion-fs/src/test/java/org/opensearch/plugin/ingestion/fs/FileBasedIngestionSingleNodeTests.java @@ -71,6 +71,15 @@ public void setupIngestionFile() throws Exception { try (FileChannel channel = FileChannel.open(shardFile, StandardOpenOption.READ)) { channel.force(true); } + + // Wait for file to be fully visible by reading it back + // This prevents race conditions where tests start before file is ready + assertBusy(() -> { + java.util.List lines = Files.readAllLines(shardFile, StandardCharsets.UTF_8); + assertEquals("File should have exactly 2 lines", 2, lines.size()); + assertTrue("First line should contain alice", lines.get(0).contains("alice")); + assertTrue("Second line should contain bob", lines.get(1).contains("bob")); + }); } public void testFileIngestion() throws Exception {