changeset 127:35d1d67b575d

adding methods (failedTestCleanUp) and (afterGuiTestsuiteCleanUp) to ThermostatTest
author Jana Fabrikova <jfabriko@redhat.com>
date Thu, 28 Nov 2013 11:29:58 +0100
parents 567599520995
children 49c76d19d687
files ChangeLog scripts/delete_longlist_from_db.sh scripts/remove_longlist_db_commands.txt scripts/tests-cleanAllThermostats.sh src/org/thermostat/qa/framework/ThermostatTest.java
diffstat 5 files changed, 126 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Nov 28 11:04:16 2013 +0100
+++ b/ChangeLog	Thu Nov 28 11:29:58 2013 +0100
@@ -1,3 +1,17 @@
+2013-11-28  Jana Fabrikova  <jfabriko@redhat.com>
+
+	* src/org/thermostat/qa/framework/ThermostatTest.java:
+	adding methods (failedTestCleanUp) and (afterGuiTestsuiteCleanUp)
+	that are performed after failed tests and between the testsuites,
+	so that no gui/storage/web storage/agent does not interfere with other tests,
+	and the gui is not loaded with too many listed hosts and vms, so it starts
+	more quickly
+	* scripts/tests-cleanAllThermostats.sh:
+	* scripts/delete_longlist_from_db.sh:
+	auxiliary scripts
+	* scripts/remove_longlist_db_commands.txt:
+	auxiliary file with commands for the mongodb
+
 2013-11-28  Jana Fabrikova  <jfabriko@redhat.com>
 
 	* Makefile:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/delete_longlist_from_db.sh	Thu Nov 28 11:29:58 2013 +0100
@@ -0,0 +1,2 @@
+mongo --port `cat scripts/mongoPortNumber.txt` < scripts/remove_longlist_db_commands.txt
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/remove_longlist_db_commands.txt	Thu Nov 28 11:29:58 2013 +0100
@@ -0,0 +1,5 @@
+use thermostat
+db["vm-info"].remove()
+db["host-info"].remove()
+exit
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/tests-cleanAllThermostats.sh	Thu Nov 28 11:29:58 2013 +0100
@@ -0,0 +1,1 @@
+kill -9 $(jps | grep Thermostat | cut -f1 -d' ')
--- a/src/org/thermostat/qa/framework/ThermostatTest.java	Thu Nov 28 11:04:16 2013 +0100
+++ b/src/org/thermostat/qa/framework/ThermostatTest.java	Thu Nov 28 11:29:58 2013 +0100
@@ -34,13 +34,19 @@
 
 package org.thermostat.qa.framework;
 
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.List;
 
 
 
 import org.thermostat.qa.annotations.SinceVersion;
+import org.thermostat.qa.annotations.StorageType;
+import org.thermostat.qa.annotations.StorageTypes;
+import org.thermostat.qa.annotations.TestType;
+import org.thermostat.qa.annotations.TestTypes;
 import org.thermostat.qa.annotations.TillVersion;
 import org.thermostat.qa.annotations.ValidVersions;
 import org.thermostat.qa.common.Configuration;
@@ -81,6 +87,16 @@
      * Number of tests that have been ignored.
      */
     private int ignored = 0;
+    
+    /**
+     * Is the current test a gui test?
+     */
+    private boolean guiTest = false;
+    
+    /**
+     * Does the current test use web storage?
+     */
+    private boolean webStorage = false;
 
     /**
      * Set up the test suite. To be implemented by specific test cases.
@@ -103,26 +119,108 @@
 
         this.configuration = new Configuration(args);
 
+        //determine if the class contains gui tests
+        TestType testType = getClass().getAnnotation(TestType.class);
+        if(testType != null)
+        {
+            guiTest = (testType.value() == TestTypes.GUI_TEST);
+        }
+        StorageType storageType = getClass().getAnnotation(StorageType.class);
+        if(storageType != null)
+        {
+            webStorage = (storageType.value() == StorageTypes.WEBTOMCAT_STORAGE);
+        }
         // setup test
         setUp();
         try
         {
+            if( guiTest )
+            {
+                cleanDBBeforeShowingInGui();
+            }
             runAllTests();
         }
         catch (Exception e)
         {
             e.printStackTrace();
+            try
+            {
+                failedTestCleanUp();
+            }
+            catch (IOException e1)
+            {
+                // TODO Auto-generated catch block
+                e1.printStackTrace();
+            }
         }
         finally {
             // tear down test
             tearDown();
+            
             // check test duration
             long t2 = System.currentTimeMillis();
             // print all results
             printResults(t1, t2, this.passed, this.failed, this.error, this.ignored);
+
+            //cleanup after an attempt to run all tests
+            //there could be hanging gui or this testsuite class
+            if(guiTest)
+            {
+                try
+                {
+                    afterGuiTestsuiteCleanUp();
+                }
+                catch (IOException e)
+                {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
         }
     }
 
+    private void cleanDBBeforeShowingInGui() {
+        // TODO Auto-generated method stub
+        startStorage();
+        try
+        {
+            runHelperBashScript("delete_longlist_from_db.sh");
+        }
+        catch (IOException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        try
+        {
+            stopStorage();
+        }
+        catch (IOException e)
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        
+    }
+
+    private void failedTestCleanUp() throws IOException {
+        runHelperBashScript("tests-cleanAllThermostats.sh"); //agent, gui
+        if(webStorage)
+        {
+            stopWebStorage();
+        }else{
+            stopStorage();
+        }
+    }
+
+    private void afterGuiTestsuiteCleanUp() throws IOException {
+        List<String> scriptContent = new ArrayList<String>();
+        String s = "kill $(jps | grep "+this.getClass().getSimpleName()+" | cut -f1 -d' ')";
+        scriptContent.add(s);
+        runBashScriptWithContent("guitests-cleanOneTest.sh", scriptContent);
+    }
+    
+    
     /**
      * Run all tests in the test suite.
      * 
@@ -302,23 +400,27 @@
     /**
      * @param methodName
      * @param e
+     * @throws IOException 
      */
-    private void testError(String methodName, Exception e)
+    private void testError(String methodName, Exception e) throws IOException
     {
         printTestError(methodName, e);
         this.error++;
         e.printStackTrace();
+        failedTestCleanUp();
     }
 
     /**
      * @param methodName
      * @param e
+     * @throws IOException 
      */
-    private void testFailed(String methodName, Throwable e)
+    private void testFailed(String methodName, Throwable e) throws IOException
     {
         printTestFailed(methodName, e);
         this.failed++;
         e.printStackTrace();
+        failedTestCleanUp();
     }
 
     /**