Skip to content

Commit

Permalink
File-split-ftp: fix read files race condition
Browse files Browse the repository at this point in the history
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
  • Loading branch information
artembilan committed Oct 25, 2016
1 parent 171dd51 commit e35d441
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -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");
Expand Down

0 comments on commit e35d441

Please sign in to comment.