From e35d4416919786ad21d6bbf8429d1f0ae8ef7d3d Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 25 Oct 2016 10:34:54 -0400 Subject: [PATCH] File-split-ftp: fix read files race condition https://build.spring.io/browse/INTSAMPLES-NIGHTLY-1898/ There is no guarantee that if `File.exists()`, the real write to file has occurred * Add `while()` to check not only `File.exists()` but also its `length()` only after that proceed to assert logic --- .../integration/samples/filesplit/ApplicationTests.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/applications/file-split-ftp/src/test/java/org/springframework/integration/samples/filesplit/ApplicationTests.java b/applications/file-split-ftp/src/test/java/org/springframework/integration/samples/filesplit/ApplicationTests.java index 9da803395..3b3b49d0e 100644 --- a/applications/file-split-ftp/src/test/java/org/springframework/integration/samples/filesplit/ApplicationTests.java +++ b/applications/file-split-ftp/src/test/java/org/springframework/integration/samples/filesplit/ApplicationTests.java @@ -118,12 +118,20 @@ private String runTest(boolean fail) throws Exception { br.close(); out.delete(); out = new File("/tmp/out/006.txt"); + n = 0; + while(n++ < 100 && (!out.exists() || out.length() < 12)) { + Thread.sleep(100); + } assertThat(out.exists()).isTrue(); br = new BufferedReader(new FileReader(out)); assertThat(br.readLine()).isEqualTo("*006,baz,qux"); br.close(); out.delete(); out = new File("/tmp/out/009.txt"); + n = 0; + while(n++ < 100 && (!out.exists() || out.length() < 12)) { + Thread.sleep(100); + } assertThat(out.exists()).isTrue(); br = new BufferedReader(new FileReader(out)); assertThat(br.readLine()).isEqualTo("*009,fiz,buz");