From: Marc-Andre Laperle Date: Fri, 22 Jul 2016 21:41:07 +0000 (-0400) Subject: tmf: Fix PatternScatterChartViewTest intermittent failure X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=1b9a8a8c4c2fcbb7470c59117feba0d2366c5cff;p=deliverable%2Ftracecompass.git tmf: Fix PatternScatterChartViewTest intermittent failure 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 Reviewed-on: https://git.eclipse.org/r/77800 Reviewed-by: Hudson CI Reviewed-by: Jean-Christian Kouame Tested-by: Jean-Christian Kouame --- diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/swtbot/tests/latency/PatternLatencyViewTestBase.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/swtbot/tests/latency/PatternLatencyViewTestBase.java index 62f0d84f36..866597e56e 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/swtbot/tests/latency/PatternLatencyViewTestBase.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/swtbot/tests/latency/PatternLatencyViewTestBase.java @@ -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(); } /** diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java index 07f4aa0a68..f34b4a2d18 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java @@ -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() }); + } + } } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java index c5d25f03f4..6185cc3c6e 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java @@ -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];