From aabbea350930b8c2904e4f1544f0d786e7d59792 Mon Sep 17 00:00:00 2001 From: James Procter Date: Fri, 15 Dec 2023 11:30:11 +0000 Subject: [PATCH] =?utf8?q?JAL-4290=20new=20CommandsTest.headlessOrGuiImageOu?= =?utf8?q?tputTest=20-=20uses=20CommandLineOperations.Worker=20to=20run=20ja?= =?utf8?q?lview=20as=20a=20separate=20process=20to=20verify=20headless=20ali?= =?utf8?q?gnment=20image=20export=20should=20be=20same=20size=20as=20when=20?= =?utf8?q?launched=20with=20=E2=80=94gui?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- test/jalview/bin/CommandLineOperations.java | 6 +- test/jalview/bin/CommandsTest.java | 111 ++++++++++++++++++++++----- 2 files changed, 95 insertions(+), 22 deletions(-) diff --git a/test/jalview/bin/CommandLineOperations.java b/test/jalview/bin/CommandLineOperations.java index 77cbd92..3855dc7 100644 --- a/test/jalview/bin/CommandLineOperations.java +++ b/test/jalview/bin/CommandLineOperations.java @@ -71,7 +71,7 @@ public class CommandLineOperations * @author jimp * */ - private static class Worker extends Thread + public static class Worker extends Thread { private final Process process; @@ -156,7 +156,7 @@ public class CommandLineOperations return classpath; } - private Worker getJalviewDesktopRunner(boolean withAwt, String cmd, + public static Worker getJalviewDesktopRunner(boolean withAwt, String cmd, int timeout) { // Note: JAL-3065 - don't include quotes for lib/* because the arguments are @@ -183,7 +183,7 @@ public class CommandLineOperations new InputStreamReader(ls2_proc.getInputStream())); BufferedReader errorReader = new BufferedReader( new InputStreamReader(ls2_proc.getErrorStream())); - worker = new Worker(ls2_proc); + worker = new CommandLineOperations.Worker(ls2_proc); worker.start(); try { diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index 7b42737..e42cc54 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -180,29 +180,44 @@ public class CommandsTest callJalviewMain(args); Commands cmds = Jalview.getInstance().getCommands(); Assert.assertNotNull(cmds); - File lastFile = null; - for (String filename : filenames) + verifyIncreasingSize(cmdLine, filenames); + } catch (Exception x) + { + Assert.fail("Unexpected exception during structureImageOutputTest", + x); + } finally + { + cleanupFiles(filenames); + tearDown(); + } + } + + /** + * given two command lines, compare the output files produced - they should exist and be equal in size + */ + @Test( + groups = + { "Functional", "testTask3" }, + dataProvider = "compareHeadlessAndGUIOps", + singleThreaded = true) + public void headlessOrGuiImageOutputTest(String[] cmdLines, + String[] filenames) throws IOException + { + cleanupFiles(filenames); + try + { + for (String cmdLine : cmdLines) { - File file = new File(filename); - Assert.assertTrue(file.exists(), "File '" + filename - + "' was not created by '" + cmdLine + "'"); - Assert.assertTrue(file.isFile(), "File '" + filename - + "' is not a file from '" + cmdLine + "'"); - 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) + CommandLineOperations.Worker runner = CommandLineOperations.getJalviewDesktopRunner(false, cmdLine, 1000); + long timeOut = 10000; + while (runner.isAlive() && timeOut>0) { - waitForLastWrite(file,25); - - if (Files.size(file.toPath()) > Files - .size(lastFile.toPath())) - Assert.assertTrue(Files.size(file.toPath()) > Files - .size(lastFile.toPath())); + Thread.sleep(25); + timeOut-=25; } - // remember it for next file - lastFile = file; } + verifyOrderedFileSet(cmdLines[0] + " vs " + cmdLines[1], filenames, + false); } catch (Exception x) { Assert.fail("Unexpected exception during structureImageOutputTest", @@ -213,7 +228,65 @@ public class CommandsTest tearDown(); } } + @DataProvider(name = "compareHeadlessAndGUIOps") + public Object[][] compareHeadlessAndGUIOps() + { + return new Object[][] { + new Object[] + { new String[] { "--open examples/uniref50.fa " + + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]" + + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json --image=" + + testfiles + "test-al-pae-ss-gui.png --overwrite --gui --quit", + "--open examples/uniref50.fa " + + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]" + + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb " + + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json --image=" + + testfiles + + "test-al-pae-ss-nogui.png --overwrite --nogui" + + }, new String[] { + testfiles + "test-al-pae-ss-gui.png", + testfiles + + "test-al-pae-ss-nogui.png", + } } }; + } + + private static void verifyIncreasingSize(String cmdLine, String[] filenames) throws Exception + { + verifyOrderedFileSet(cmdLine, filenames, true); + } + + private static void verifyOrderedFileSet(String cmdLine, String[] filenames, boolean increasingSize) throws Exception + { + File lastFile = null; + for (String filename : filenames) + { + File file = new File(filename); + Assert.assertTrue(file.exists(), "File '" + filename + + "' was not created by '" + cmdLine + "'"); + Assert.assertTrue(file.isFile(), "File '" + filename + + "' is not a file from '" + cmdLine + "'"); + 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) + { + waitForLastWrite(file,25); + + if (increasingSize) + { Assert.assertTrue(Files.size(file.toPath()) > Files + .size(lastFile.toPath()),"Expected " + file.toPath()+ " to be larger than "+lastFile.toPath()); + } else { + Assert.assertEquals(Files.size(file.toPath()), Files + .size(lastFile.toPath()), "New file "+file.toPath()+" (actual size) not same as last file's size "+lastFile.toString()); + } + } + // remember it for next file + lastFile = file; + } + } private static long waitForLastWrite(File file, int i) throws IOException { long lastSize,stableSize =Files.size(file.toPath()); -- 1.7.10.2