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 {