Skip to content

Commit

Permalink
swtbot: Make testOpenCloseOpen() for CFV/RV more robust
Browse files Browse the repository at this point in the history
Use timeGraphIsReadyCondition() to make sure that timegraph is populated
before getting the content.

This should fix some intermittent failures in CI.

Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
bhufmann committed Feb 12, 2024
1 parent 3e292d3 commit e1abdb7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraph;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
import org.eclipse.ui.IWorkbenchPart;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -86,7 +84,6 @@ public class ControlFlowViewTest extends KernelTimeGraphViewTestBase {
private static final String FOLLOW_CPU_FORWARD = "Follow CPU Forward";
private static final String SELECT_PREVIOUS_STATE_CHANGE = "Select Previous State Change";
private static final String SELECT_NEXT_STATE_CHANGE = "Select Next State Change";
private static final @NonNull ITmfTimestamp START_TIME = TmfTimestamp.fromNanos(1368000272650993664L);
private static final @NonNull ITmfTimestamp TID1_TIME1 = TmfTimestamp.fromNanos(1368000272651208498L);
private static final @NonNull ITmfTimestamp TID1_TIME2 = TmfTimestamp.fromNanos(1368000272656149680L);
private static final @NonNull ITmfTimestamp TID1_TIME3 = TmfTimestamp.fromNanos(1368000272656364514L);
Expand Down Expand Up @@ -740,9 +737,4 @@ public void testToolBarFollowCPUForwardBackward() {
fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(START_TIME, START_TIME)));
assertTrue(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange().contains(START_TIME));
}

private void timeGraphIsReadyCondition(@NonNull TmfTimeRange selectionRange) {
IWorkbenchPart part = getViewBot().getViewReference().getPart(false);
fBot.waitUntil(ConditionHelpers.timeGraphIsReadyCondition((AbstractTimeGraphView) part, selectionRange, selectionRange.getEndTime()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCLabel;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraph;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
import org.eclipse.ui.IWorkbenchPart;
import org.junit.Test;

/**
Expand All @@ -47,6 +55,11 @@
*/
public abstract class KernelTimeGraphViewTestBase extends KernelTestBase {

/**
* The start time
*/
protected static final @NonNull ITmfTimestamp START_TIME = TmfTimestamp.fromNanos(1368000272650993664L);

/**
* The vertical scrollbar is the first slider described in the view, so its
* slider index is equal to 0
Expand Down Expand Up @@ -133,10 +146,13 @@ public void testLegend() {
@Test
public void testOpenCloseOpen() {
SWTBotView viewBot = openView();
TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, START_TIME));
timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME));
SWTBotTimeGraph tgBot = new SWTBotTimeGraph(viewBot.bot());
Map<String, List<String>> before = getItemNames(tgBot);
viewBot.close();
viewBot = openView();
timeGraphIsReadyCondition(new TmfTimeRange(START_TIME, START_TIME));
tgBot = new SWTBotTimeGraph(viewBot.bot());
Map<String, List<String>> after = getItemNames(tgBot);
assertEquals(before, after);
Expand Down Expand Up @@ -172,6 +188,17 @@ public void testHorizontalScrollbar() {
assertEquals("Incorrect horizontal slider start position", timegraphRect.x + tgBot.getNameSpace(), sliderRect.x);
}

/**
* Wait until timegraph is ready
*
* @param selectionRange
* selection range
*/
protected void timeGraphIsReadyCondition(@NonNull TmfTimeRange selectionRange) {
IWorkbenchPart part = getViewBot().getViewReference().getPart(false);
fBot.waitUntil(ConditionHelpers.timeGraphIsReadyCondition((AbstractTimeGraphView) part, selectionRange, selectionRange.getEndTime()));
}

private @NonNull static Map<String, List<String>> getItemNames(SWTBotTimeGraph tgBot) {
Map<String, List<String>> returnStructure = new HashMap<>();
for (SWTBotTimeGraphEntry element : tgBot.getEntries()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public class ResourcesViewTest extends KernelTimeGraphViewTestBase {
private static final String ZOOM_IN = "Zoom In";
private static final String ZOOM_OUT = "Zoom Out";

private static final @NonNull ITmfTimestamp START_TIME = TmfTimestamp.fromNanos(1368000272650993664L);
private static final @NonNull ITmfTimestamp LOST_EVENT_TIME1 = TmfTimestamp.fromNanos(1368000272697356476L);
private static final @NonNull ITmfTimestamp LOST_EVENT_END1 = TmfTimestamp.fromNanos(1368000272703627994L);
private static final @NonNull ITmfTimestamp LOST_EVENT_TIME2 = TmfTimestamp.fromNanos(1368000272728168642L);
Expand Down

0 comments on commit e1abdb7

Please sign in to comment.