From: James Procter Date: Tue, 12 Dec 2023 17:20:04 +0000 (+0000) Subject: JAL-4353 wait for files to be written fully before comparing size with older file X-Git-Tag: Release_2_11_4_0~56^2^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cf66eafda7511e40453e251e2dee3f2951cca183;p=jalview.git JAL-4353 wait for files to be written fully before comparing size with older file --- diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index 2d54093..7b42737 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -191,13 +191,17 @@ public class CommandsTest Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename + "' has no content from '" + cmdLine + "'"); // make sure the successive output files get bigger! - if (lastFile != null) { - Assert.assertTrue(Files.size(file.toPath()) > Files.size(lastFile.toPath())); - System.out.println("this file: " + file + " +" + Files.size(file.toPath()) + " greater than " - + Files.size(lastFile.toPath())); - } - // remember it for next file - lastFile = file; + if (lastFile != null) + { + waitForLastWrite(file,25); + + if (Files.size(file.toPath()) > Files + .size(lastFile.toPath())) + Assert.assertTrue(Files.size(file.toPath()) > Files + .size(lastFile.toPath())); + } + // remember it for next file + lastFile = file; } } catch (Exception x) { @@ -210,7 +214,22 @@ public class CommandsTest } } + private static long waitForLastWrite(File file, int i) throws IOException + { + long lastSize,stableSize =Files.size(file.toPath()); + // wait around until we are sure the file has been completely written. + do { + lastSize = stableSize; + try { + Thread.sleep(i); + } catch (Exception x) {} + stableSize=Files.size(file.toPath()); + } while (stableSize!=lastSize); + return stableSize; + } + @Test(groups = "Functional", dataProvider = "argfileOutputFiles", singleThreaded = true) + public void argFilesGlobAndSubstitutionsTest(String cmdLine, String[] filenames) throws IOException {