tmf: Fix PatternScatterChartViewTest intermittent failure
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Fri, 22 Jul 2016 21:41:07 +0000 (17:41 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Mon, 25 Jul 2016 19:54:19 +0000 (15:54 -0400)
It is possible that the test tries to open the scatter chart view
before it's actually available under the Project Explorer. This is
because the trace hasn't fully opened and the analysis outputs haven't
been determined yet.

To reproduce the issue, go to TmfOpenTraceHelper.openTraceFromElement
and add Thread.sleep(5000) right before the asyncExec call. The test
should fail with:
WidgetNotFoundException:Could not find node with text: Latency vs Time

The fix is to wait until tree nodes are available in the tree before
proceeding. The tree util methods have been augmented to handle using
a tree item as the root to find other items from. It will also now
wait before children items are present before expanding, this is to
cover the case where children are not yet created.

Change-Id: Ib9070b20effb8e409d69f70513500ea5ff478778
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/77800
Reviewed-by: Hudson CI
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/swtbot/tests/latency/PatternLatencyViewTestBase.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java

index 62f0d84f363dec85dd41831e01302b1487662da8..866597e56e1336d6af8f0e66778f299505f8b52f 100644 (file)
@@ -42,6 +42,7 @@ public abstract class PatternLatencyViewTestBase {
 
     private static final String PROJECT_NAME = "test";
     private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
+    private static final String TRACE_NAME = "bug446190";
 
     /** The Log4j logger instance. */
     private static final Logger fLogger = Logger.getRootLogger();
@@ -128,12 +129,9 @@ public abstract class PatternLatencyViewTestBase {
      */
     private static void openView(final String viewTitle) {
         SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
-        treeItem = treeItem.expand();
-        treeItem = treeItem.getNode(0).expand();
-        treeItem = treeItem.expandNode("Views", "XML system call analysis");
-        treeItem = treeItem.getNode(viewTitle);
+        treeItem = SWTBotUtils.getTreeItem(fBot, treeItem, TRACE_NAME, "Views", "XML system call analysis", viewTitle);
+        treeItem.select();
         treeItem.doubleClick();
-        SWTBotUtils.waitForJobs();
     }
 
     /**
index 07f4aa0a68734cf92a0666f7ad852be6f078970e..f34b4a2d18c65899d9fe520953d41aac331f71b2 100644 (file)
@@ -699,4 +699,33 @@ public final class ConditionHelpers {
     public static ICondition numberOfSeries(Chart chart, int numberOfSeries) {
         return new NumberOfSeries(chart, numberOfSeries);
     }
+
+    /**
+     * Condition to check if the tree item has children
+     *
+     * @param treeItem
+     *            the tree item that should have children
+     * @return ICondition for verification
+     */
+    public static ICondition treeItemHasChildren(SWTBotTreeItem treeItem) {
+        return new TreeItemHasChildren(treeItem);
+    }
+
+    private static final class TreeItemHasChildren extends DefaultCondition {
+        private SWTBotTreeItem fTreeItem;
+
+        public TreeItemHasChildren(SWTBotTreeItem treeItem) {
+            fTreeItem = treeItem;
+        }
+
+        @Override
+        public boolean test() throws Exception {
+            return fTreeItem.getItems().length > 0;
+        }
+
+        @Override
+        public String getFailureMessage() {
+            return NLS.bind("No child of tree item {0} found.", new String[] { fTreeItem.toString() });
+        }
+    }
 }
index c5d25f03f467fe39d8040765b5351a7d721d8c1f..6185cc3c6edcce6491f81e5a868b262b6e83d2f0 100644 (file)
@@ -16,6 +16,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.TimeZone;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -817,7 +818,29 @@ public final class SWTBotUtils {
 
         bot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(nodeNames[0], tree));
         SWTBotTreeItem currentNode = tree.getTreeItem(nodeNames[0]);
-        for (int i = 1; i < nodeNames.length; i++) {
+        return getTreeItem(bot, currentNode, Arrays.copyOfRange(nodeNames, 1, nodeNames.length));
+    }
+
+    /**
+     * Get the tree item from a parent tree item at the specified location
+     *
+     * @param bot
+     *            the SWTBot
+     * @param treeItem
+     *            the treeItem to find the tree item under
+     * @param nodeNames
+     *            the path to the tree item, in the form of node names (from
+     *            parent to child).
+     * @return the tree item
+     */
+    public static SWTBotTreeItem getTreeItem(SWTBot bot, SWTBotTreeItem treeItem, String... nodeNames) {
+        if (nodeNames.length == 0) {
+            return treeItem;
+        }
+
+        SWTBotTreeItem currentNode = treeItem;
+        for (int i = 0; i < nodeNames.length; i++) {
+            bot.waitUntil(ConditionHelpers.treeItemHasChildren(treeItem));
             currentNode.expand();
 
             String nodeName = nodeNames[i];
This page took 0.027261 seconds and 5 git commands to generate.