This is an automated email from the ASF dual-hosted git repository.
apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new e28af912b110 CAMEL-25232: Fix flaky SpringSimpleFileNameWithQuoteTest
e28af912b110 is described below
commit e28af912b11005e29f5f8e9dff21996c4e7ac3fd
Author: Aurélien Pupier <[email protected]>
AuthorDate: Fri Nov 20 09:43:29 2026 +0100
CAMEL-25232: Fix flaky SpringSimpleFileNameWithQuoteTest
Reason:
The test sends the file with the file producer to the same directory that
the route consumes with a 10 ms polling delay. The producer writes straight
to the target file: it creates the (empty) file and only then writes the
body. When the consumer polls between those two steps it picks up an empty
file, and the test fails with:
mock://result Body of message: 0. Expected: <Hello World!> but was: <>
Fix:
Send the file with tempPrefix=.inprogress-. The producer then writes a
hidden temp file and renames it to hello.txt once the content is complete.
The file consumer always skips names starting with a dot, so it can only
see the complete file.
How it was reproduced locally:
The race window is a few microseconds and could not be hit by brute force:
3000 runs in 30 parallel JVMs and 800 runs in fresh JVMs (60 at a time on
22 cores) all passed. To widen the window, a temporary (not committed) delay
was added in FileOperations.writeFileByString: create the empty target file,
sleep 100 ms, then write the body.
- Without the fix: 5 out of 5 runs failed with the exact error above.
- With the fix, same delay: 10 out of 10 runs passed.
Co-authored-by: IBM Bob 2.2.1
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../apache/camel/spring/file/SpringSimpleFileNameWithQuoteTest.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/file/SpringSimpleFileNameWithQuoteTest.java
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/file/SpringSimpleFileNameWithQuoteTest.java
index aba5b9588f7a..7408308c6c90 100644
---
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/file/SpringSimpleFileNameWithQuoteTest.java
+++
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/file/SpringSimpleFileNameWithQuoteTest.java
@@ -46,7 +46,10 @@ public class SpringSimpleFileNameWithQuoteTest extends
SpringRunWithTestSupport
result.expectedBodiesReceived(expectedBody);
result.expectedHeaderReceived("foo", "\"hello.txt\" abc");
- template.sendBodyAndHeader(fileUri(tempDir, ""), expectedBody,
Exchange.FILE_NAME, "hello.txt");
+ // write via a hidden temp file (skipped by the consumer) and rename
when complete, so that the consumer
+ // cannot pick up the file while it is still empty
+ template.sendBodyAndHeader(fileUri(tempDir,
"?tempPrefix=.inprogress-"), expectedBody, Exchange.FILE_NAME,
+ "hello.txt");
result.assertIsSatisfied();
}