From: Ben Soares Date: Wed, 9 Nov 2022 15:30:09 +0000 (+0000) Subject: JAL-1988 JAL-3772 Test for FORCE_QUIT whilst saving a file X-Git-Tag: Release_2_11_3_0~23^2~4^2~13^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0d37fef8a89c67845c14f2383e89003c9a2c5b62;p=jalview.git JAL-1988 JAL-3772 Test for FORCE_QUIT whilst saving a file --- diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 9e3eb55..dfef0d2 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -1822,7 +1822,7 @@ public class Desktop extends jalview.jbgui.GDesktop saveState_actionPerformed(true); } - private void setProjectFile(File choice) + protected void setProjectFile(File choice) { this.projectFile = choice; } diff --git a/test/jalview/gui/QuitHandlerTest.java b/test/jalview/gui/QuitHandlerTest.java index 2caa8ec..b1dab96 100644 --- a/test/jalview/gui/QuitHandlerTest.java +++ b/test/jalview/gui/QuitHandlerTest.java @@ -66,7 +66,7 @@ public class QuitHandlerTest // reset mock response JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); // close desktop windows/frames - jalview.gui.Desktop.instance.closeAll_actionPerformed(null); + Desktop.instance.closeAll_actionPerformed(null); // reset debug delay Jalview2XML.setDebugDelaySave(20); } @@ -79,10 +79,12 @@ public class QuitHandlerTest // reset mock response JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); // close desktop windows/frames - jalview.gui.Desktop.instance.closeAll_actionPerformed(null); + Desktop.instance.closeAll_actionPerformed(null); // reset debug delay Cache.setProperty("DEBUG_DELAY_SAVE", "false"); Jalview2XML.setDebugDelaySave(3); + // set the project file + Desktop.instance.setProjectFile(new File(saveProjectFile)); } @AfterMethod(alwaysRun = true) @@ -113,6 +115,7 @@ public class QuitHandlerTest long start = System.currentTimeMillis(); // if a save is attempted it will delay 3s + Jalview2XML.setDebugDelaySave(3); Cache.setProperty("DEBUG_DELAY_SAVE", "true"); // loaded file but haven't done anything, should just quit @@ -120,7 +123,7 @@ public class QuitHandlerTest long end = System.currentTimeMillis(); Assert.assertEquals(response, QResponse.QUIT); - Assert.assertTrue(end - start < 1000, + Assert.assertTrue(end - start < 500, "Quit-with-no-save-needed took too long (" + (end - start) + "ms)"); Desktop.instance.closeAll_actionPerformed(null); @@ -137,15 +140,15 @@ public class QuitHandlerTest long start = System.currentTimeMillis(); // start a long save (3s) + Jalview2XML.setDebugDelaySave(3); Cache.setProperty("DEBUG_DELAY_SAVE", "true"); - af.saveAlignment(saveProjectFile, FileFormat.Jalview); + Desktop.instance.saveState_actionPerformed(false); - QResponse response = QuitHandler.getQuitResponse(true, - QuitHandler.defaultOkQuit, () -> { - // set FORCE_QUIT without the force quit - QuitHandler.setResponse(QResponse.FORCE_QUIT); - return null; - }, QuitHandler.defaultCancelQuit); + // give the saveState thread time to start! + Thread.sleep(500); + + // af.saveAlignment(saveProjectFile, FileFormat.Jalview); + QResponse response = QuitHandler.getQuitResponse(true); long end = System.currentTimeMillis(); Assert.assertEquals(response, QResponse.QUIT); @@ -173,12 +176,7 @@ public class QuitHandlerTest // this is only a two button dialog [Quit] [Cancel] so use NO_OPTION JvOptionPane.setMockResponse(JvOptionPane.NO_OPTION); - QResponse response = QuitHandler.getQuitResponse(true, - QuitHandler.defaultOkQuit, () -> { - // set FORCE_QUIT without the force quit - QuitHandler.setResponse(QResponse.FORCE_QUIT); - return null; - }, QuitHandler.defaultCancelQuit); + QResponse response = QuitHandler.getQuitResponse(true); // if not saved this would be CANCEL_QUIT Assert.assertEquals(response, QResponse.QUIT); @@ -203,12 +201,7 @@ public class QuitHandlerTest // this is only a two button dialog [Quit] [Cancel] so use NO_OPTION JvOptionPane.setMockResponse(JvOptionPane.NO_OPTION); - QResponse response = QuitHandler.getQuitResponse(true, - QuitHandler.defaultOkQuit, () -> { - // set FORCE_QUIT without the force quit - QuitHandler.setResponse(QResponse.FORCE_QUIT); - return null; - }, QuitHandler.defaultCancelQuit); + QResponse response = QuitHandler.getQuitResponse(true); // if not saved this would be CANCEL_QUIT Assert.assertEquals(response, QResponse.QUIT); @@ -229,12 +222,7 @@ public class QuitHandlerTest // this is only a two button dialog [Quit] [Cancel] so use NO_OPTION JvOptionPane.setMockResponse(JvOptionPane.NO_OPTION); - QResponse response = QuitHandler.getQuitResponse(true, - QuitHandler.defaultOkQuit, () -> { - // set FORCE_QUIT without the force quit - QuitHandler.setResponse(QResponse.FORCE_QUIT); - return null; - }, QuitHandler.defaultCancelQuit); + QResponse response = QuitHandler.getQuitResponse(true); Assert.assertEquals(response, QResponse.CANCEL_QUIT); Desktop.instance.closeAll_actionPerformed(null); @@ -254,15 +242,61 @@ public class QuitHandlerTest // this is only a two button dialog [Quit] [Cancel] so use NO_OPTION JvOptionPane.setMockResponse(JvOptionPane.NO_OPTION); + /* QResponse response = QuitHandler.getQuitResponse(false, QuitHandler.defaultOkQuit, () -> { // set FORCE_QUIT without the force quit QuitHandler.setResponse(QResponse.FORCE_QUIT); return null; }, QuitHandler.defaultCancelQuit); + */ + QResponse response = QuitHandler.getQuitResponse(false); Assert.assertEquals(response, QResponse.QUIT); Desktop.instance.closeAll_actionPerformed(null); } + @Test(groups = { "Functional" }, singleThreaded = true, priority = 11) + public void testForceQuit() throws Exception + { + String inFile = "examples/uniref50.fa"; + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(inFile, + DataSourceType.FILE); + assertNotNull(af, "Didn't read input file " + inFile); + + long start = System.currentTimeMillis(); + + // start a long save (10s) + Jalview2XML.setDebugDelaySave(10); + Cache.setProperty("DEBUG_DELAY_SAVE", "true"); + Desktop.instance.saveState_actionPerformed(false); + + // give the saveState thread time to start! + Thread.sleep(100); + + // this will select "Force Quit" + JvOptionPane.setMockResponse(JvOptionPane.YES_OPTION); + QResponse response = QuitHandler.getQuitResponse(true, + QuitHandler.defaultOkQuit, () -> { + // set FORCE_QUIT without the force quit + jalview.bin.Console.debug( + "Setting FORCE_QUIT without actually quitting"); + QuitHandler.setResponse(QResponse.FORCE_QUIT); + return null; + }, QuitHandler.defaultCancelQuit); + long end = System.currentTimeMillis(); + + Assert.assertEquals(response, QResponse.FORCE_QUIT); + // if the wait (min wait is 1s) wasn't long enough... + Assert.assertTrue(end - start > 1000, + "Force-Quit-whilst-saving was too short (" + (end - start) + + "ms)"); + // if the wait was too long (probably waited for file to save) + Assert.assertTrue(end - start < 9090, + "Force-Quit-whilst-saving was too long (" + (end - start) + + "ms)"); + + Desktop.instance.closeAll_actionPerformed(null); + } + } diff --git a/test/jalview/gui/quitProps.jvprops b/test/jalview/gui/quitProps.jvprops index d806eac..be2b1cb 100644 --- a/test/jalview/gui/quitProps.jvprops +++ b/test/jalview/gui/quitProps.jvprops @@ -1,4 +1,4 @@ -#DEBUG_DELAY_SAVE=true +DEBUG_DELAY_SAVE=true BACKUPFILES_ENABLED=true BACKUPFILES_FC_INCLUDE=false BACKUPFILES_PRESET=1