lttng: Improve and speed-up control tests handling
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Fri, 31 Jul 2015 12:12:18 +0000 (08:12 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Tue, 29 Sep 2015 14:50:41 +0000 (10:50 -0400)
For each test a 3 seconds delay is done waiting that the ControlView
is open and initialized properly. This patch optimizes this.

Change-Id: I5308973613c23c481757fd26c84f87c0a9edf94a
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/52971
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlCreateSessionTests.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlKernelProviderTests.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlKernelSessionTests.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlPropertiesTest.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlSnapshotSessionTests.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlTestFacility.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlTreeModelNoProvidersTest.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlTreeModelTest.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlUstProviderTests.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlUstSessionTests.java
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/model/component/TraceControlUstSessionTests2.java

index 787684d1c3394504821a5d1c75e12ad812edd89f..3c26afbdd75971295c281527f2230cadc306bb10 100644 (file)
@@ -99,7 +99,7 @@ public class TraceControlCreateSessionTests {
      */
     @After
     public void tearDown() {
-        fFacility.waitForJobs();
+        fFacility.dispose();
     }
 
     /**
@@ -114,7 +114,7 @@ public class TraceControlCreateSessionTests {
         fProxy.setTestFile(fTestFile);
         fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
 
-        ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
+        ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
 
         TargetNodeComponent node = new TargetNodeComponent("myNode", root, fProxy);
 
index a4b0108564f71230767ddec2e4bdc005c0731c0b..aaa4d64bae419f25d06303d0a10a5e143d910155 100644 (file)
@@ -56,6 +56,7 @@ import org.eclipse.tracecompass.internal.lttng2.control.ui.views.property.UstPro
 import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory;
 import org.eclipse.ui.views.properties.IPropertySource;
 import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.FrameworkUtil;
 
@@ -69,6 +70,7 @@ public class TraceControlPropertiesTest {
     // Constants
     // ------------------------------------------------------------------------
 
+    private TraceControlTestFacility fFacility;
     private static final String DIRECTORY   = "testfiles";
     private static final String TEST_STREAM = "ListInfoTest.cfg";
     private static final String SCEN_LIST_INFO_TEST = "ListInfoTest";
@@ -77,12 +79,21 @@ public class TraceControlPropertiesTest {
     // Housekeeping
     // ------------------------------------------------------------------------
 
+    /**
+     * Perform pre-test initialization.
+     */
+    @Before
+    public void setUp() {
+        fFacility = TraceControlTestFacility.getInstance();
+        fFacility.init();
+    }
+
     /**
      * Perform post-test clean-up.
      */
     @After
     public void tearDown() {
-        TraceControlTestFacility.getInstance().waitForJobs();
+        fFacility.dispose();
     }
 
     /**
@@ -101,15 +112,15 @@ public class TraceControlPropertiesTest {
         proxy.setTestFile(testfile.getAbsolutePath());
         proxy.setScenario(SCEN_LIST_INFO_TEST);
 
-        ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
+        ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
 
         TargetNodeComponent node = new TargetNodeComponent("myNode", root, proxy);
 
         root.addChild(node);
         node.connect();
 
-        TraceControlTestFacility.getInstance().waitForConnect(node);
-        TraceControlTestFacility.getInstance().waitForJobs();
+        fFacility.waitForConnect(node);
+        fFacility.waitForJobs();
 
         // ------------------------------------------------------------------------
         // Verify Node Properties (adapter)
index ed588a8d9190655b22f2cc433e68c623d4ed0e91..a9b7909fc48deadd6ee1e221c32ba3f5b0e04958 100644 (file)
@@ -92,7 +92,6 @@ public class TraceControlSnapshotSessionTests {
      */
     @After
     public void tearDown() {
-        fFacility.waitForJobs();
         fFacility.dispose();
     }
 
@@ -211,7 +210,5 @@ public class TraceControlSnapshotSessionTests {
         //-------------------------------------------------------------------------
 
         fFacility.executeCommand(node, "delete");
-
-        assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
     }
 }
\ No newline at end of file
index 59bc70e19b00b4737e20492c1a78353d7a1c09f9..0eaef20b5e81a6075f5775102e5b68435bc3af2a 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;
 
+import static org.junit.Assert.assertNotNull;
+
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.NotEnabledException;
 import org.eclipse.core.commands.NotHandledException;
@@ -53,7 +55,7 @@ public class TraceControlTestFacility {
     // ------------------------------------------------------------------------
     private static TraceControlTestFacility fInstance = null;
     private ControlView fControlView = null;
-    private boolean fIsInitialized = false;
+    private volatile boolean fIsInitialized = false;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -77,30 +79,13 @@ public class TraceControlTestFacility {
     public void init() {
 
         if (!fIsInitialized) {
-
             IViewPart view;
             try {
-
-                view = PlatformUI.getWorkbench()
-                        .getActiveWorkbenchWindow()
-                        .getActivePage()
-                        .findView("org.eclipse.ui.internal.introview");
-
-                if (view != null) {
-                    PlatformUI.getWorkbench()
-                    .getActiveWorkbenchWindow()
-                    .getActivePage().hideView(view);
-                }
-
-                view = PlatformUI.getWorkbench()
-                                 .getActiveWorkbenchWindow()
-                                 .getActivePage()
-                                 .showView(ControlView.ID);
-
+                hideView("org.eclipse.ui.internal.introview");
+                view = showView(ControlView.ID);
             } catch (PartInitException e) {
                 throw new RuntimeException(e);
             }
-
             fControlView = (ControlView) view;
 
             /*
@@ -117,20 +102,18 @@ public class TraceControlTestFacility {
              */
             fControlView.getTraceControlRoot().removeAllChildren();
 
-            delay(3000);
             fIsInitialized = true;
         }
     }
 
-
     /**
      * Disposes the facility (and GUI)
      */
     public void dispose() {
         if (fIsInitialized) {
             waitForJobs();
-
-            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView);
+            hideView(ControlView.ID);
+            delay(200);
             fIsInitialized = false;
         }
     }
@@ -177,6 +160,24 @@ public class TraceControlTestFacility {
         }
     }
 
+    /**
+     * Waits for a view to be closed
+     */
+    public void waitForViewClosed(String viewId) {
+        for (int i = 1; i < 5000 && (getViewPart(viewId) != null); i *= 2) {
+            delay(i);
+        }
+    }
+
+    /**
+     * Waits for a view to be closed
+     */
+    public void waitForViewOpend(String viewId) {
+        for (int i = 1; i < 5000 && (getViewPart(viewId) == null); i *= 2) {
+            delay(i);
+        }
+    }
+
     /**
      * Waits for all Eclipse jobs to finish
      */
@@ -186,6 +187,37 @@ public class TraceControlTestFacility {
         }
     }
 
+    private IViewPart showView(String viewId) throws PartInitException {
+        IViewPart view = getViewPart(viewId);
+
+        if (view == null) {
+            view = PlatformUI.getWorkbench()
+            .getActiveWorkbenchWindow()
+            .getActivePage().showView(viewId);
+
+            waitForViewOpend(viewId);
+        }
+        assertNotNull(view);
+        return view;
+    }
+
+    private void hideView(String viewId) {
+        IViewPart view = getViewPart(viewId);
+        if (view != null) {
+            PlatformUI.getWorkbench()
+            .getActiveWorkbenchWindow()
+            .getActivePage().hideView(view);
+        }
+        waitForViewClosed(viewId);
+    }
+
+    private static IViewPart getViewPart(String viewId) {
+        return PlatformUI.getWorkbench()
+        .getActiveWorkbenchWindow()
+        .getActivePage()
+        .findView(viewId);
+    }
+
     /**
      * @return current control view
      */
index b1acdedc1300971a23552e0c6e239b16b820fcf6..6d86517d6de89182e0c4df3d9b0f80e1a53faa12 100644 (file)
@@ -61,7 +61,7 @@ public class TraceControlTreeModelNoProvidersTest {
     // ------------------------------------------------------------------------
     // Test data
     // ------------------------------------------------------------------------
-
+    private TraceControlTestFacility fFacility;
     private IRemoteConnection fHost = TmfRemoteConnectionFactory.getLocalConnection();
     private @NonNull TestRemoteSystemProxy fProxy = new TestRemoteSystemProxy(fHost);
     private String fTestFile;
@@ -78,6 +78,8 @@ public class TraceControlTreeModelNoProvidersTest {
      */
     @Before
     public void setUp() throws Exception {
+        fFacility = TraceControlTestFacility.getInstance();
+        fFacility.init();
         URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
         File testfile = new File(FileLocator.toFileURL(location).toURI());
         fTestFile = testfile.getAbsolutePath();
@@ -88,7 +90,7 @@ public class TraceControlTreeModelNoProvidersTest {
      */
     @After
     public void tearDown()  {
-        TraceControlTestFacility.getInstance().waitForJobs();
+        fFacility.dispose();
     }
 
     /**
@@ -100,15 +102,15 @@ public class TraceControlTreeModelNoProvidersTest {
         fProxy.setTestFile(fTestFile);
         fProxy.setScenario(SCEN_LIST_INFO_TEST);
 
-        ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
+        ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
 
         TargetNodeComponent node = new TargetNodeComponent(TARGET_NODE_NAME, root, fProxy);
 
         root.addChild(node);
         node.connect();
 
-        TraceControlTestFacility.getInstance().waitForConnect(node);
-        TraceControlTestFacility.getInstance().waitForJobs();
+        fFacility.waitForConnect(node);
+        fFacility.waitForJobs();
 
         // ------------------------------------------------------------------------
         // Verify Parameters of TargetNodeComponent
index e323130098321816fc0ab474d06aa2ba84f91e70..60cd336c2046b1f6bd2313c73de0e427eb06a02c 100644 (file)
@@ -66,6 +66,7 @@ public class TraceControlTreeModelTest {
     // ------------------------------------------------------------------------
     // Constants
     // ------------------------------------------------------------------------
+    private TraceControlTestFacility fFacility;
 
     private static final String TEST_STREAM = "ListInfoTest.cfg";
     private static final String SCEN_LIST_INFO_TEST = "ListInfoTest";
@@ -91,6 +92,8 @@ public class TraceControlTreeModelTest {
      */
     @Before
     public void setUp() throws Exception {
+        fFacility = TraceControlTestFacility.getInstance();
+        fFacility.init();
         URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
         File testfile = new File(FileLocator.toFileURL(location).toURI());
         fTestFile = testfile.getAbsolutePath();
@@ -101,7 +104,7 @@ public class TraceControlTreeModelTest {
      */
     @After
     public void tearDown() {
-        TraceControlTestFacility.getInstance().waitForJobs();
+        fFacility.dispose();
     }
 
     /**
@@ -113,15 +116,15 @@ public class TraceControlTreeModelTest {
         fProxy.setTestFile(fTestFile);
         fProxy.setScenario(SCEN_LIST_INFO_TEST);
 
-        ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
+        ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
 
         TargetNodeComponent node = new TargetNodeComponent(TARGET_NODE_NAME, root, fProxy);
 
         root.addChild(node);
         node.connect();
 
-        TraceControlTestFacility.getInstance().waitForConnect(node);
-        TraceControlTestFacility.getInstance().waitForJobs();
+        fFacility.waitForConnect(node);
+        fFacility.waitForJobs();
 
         // ------------------------------------------------------------------------
         // Verify Parameters of TargetNodeComponent
index 00e929efbed79c38d53253155abf5381afc44e93..c6e0d98d9af31bf0107372ee5cd77730f2a29677 100644 (file)
@@ -100,7 +100,6 @@ public class TraceControlUstSessionTests {
      */
     @After
     public void tearDown() {
-        fFacility.waitForJobs();
         fFacility.dispose();
     }
 
@@ -539,7 +538,6 @@ public class TraceControlUstSessionTests {
         //-------------------------------------------------------------------------
 
         fFacility.executeCommand(node, "delete");
-
         assertEquals("Node not deleted.", 0, fFacility.getControlView().getTraceControlRoot().getChildren().length);
     }
 }
\ No newline at end of file
index b4b0d56f71cc46e463a81dec898d79b0301407d6..157ebca588b63a14a02a4b42d810afb03ffa55c1 100644 (file)
@@ -92,7 +92,6 @@ public class TraceControlUstSessionTests2 {
      */
     @After
     public void tearDown() {
-        fFacility.waitForJobs();
         fFacility.dispose();
     }
 
@@ -299,7 +298,6 @@ public class TraceControlUstSessionTests2 {
         //-------------------------------------------------------------------------
 
         fFacility.executeCommand(node, "delete");
-
         assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
     }
 }
\ No newline at end of file
This page took 0.033859 seconds and 5 git commands to generate.