Skip to content

Commit

Permalink
[test] Fix unreliable LockedModelExplorerTest
Browse files Browse the repository at this point in the history
The test "testRefreshJobForModelExplorerView()" of
"org.eclipse.sirius.tests.swtbot.modelexplorer.LockedModelExplorerTest"
has failed at least once on a CI server with this stack:
```
junit.framework.AssertionFailedError: The job should be scheduled as one
lock notification has been send and ModelExplorer view is opened.
	at junit.framework.Assert.fail(Assert.java:57)
	at junit.framework.Assert.assertTrue(Assert.java:22)
	at junit.framework.TestCase.assertTrue(TestCase.java:192)
	at org.eclipse.sirius.tests.swtbot.modelexplorer.LockedModelExplorerTest.testRefreshJobForModelExplorerView(LockedModelExplorerTest.java:132)
```

Maybe the job has not been scheduled before test on
"refreshJobScheduled". The "wait until condition" should solve this
random case.
  • Loading branch information
lredor committed Aug 29, 2024
1 parent cda18c1 commit b833d35
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2021 THALES GLOBAL SERVICES and others.
* Copyright (c) 2015, 2024 THALES GLOBAL SERVICES and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@
package org.eclipse.sirius.tests.swtbot.modelexplorer;

import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
Expand Down Expand Up @@ -40,6 +41,7 @@
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;

/**
* Verify that ModelExplorer view is refreshed on notifications about lock
Expand All @@ -63,7 +65,7 @@ public class LockedModelExplorerTest extends AbstractSiriusSwtBotGefTestCase {

IJobChangeListener jobChangeListener;

boolean refreshJobScheduled;
AtomicBoolean refreshJobScheduled = new AtomicBoolean(false);

StandalonePermissionProviderDescriptor permissionProviderDescriptor;

Expand Down Expand Up @@ -100,7 +102,7 @@ protected void onSetUpAfterOpeningDesignerPerspective() throws Exception {
jobChangeListener = new JobChangeAdapter() {
@Override
public void scheduled(IJobChangeEvent event) {
refreshJobScheduled = event.getJob().belongsTo(RefreshLabelImageJob.FAMILY);
refreshJobScheduled.set(event.getJob().belongsTo(RefreshLabelImageJob.FAMILY));
}
};
Job.getJobManager().addJobChangeListener(jobChangeListener);
Expand All @@ -127,24 +129,35 @@ protected void tearDown() throws Exception {
*/
public void testRefreshJobForModelExplorerView() {

assertFalse("The job should not be scheduled as no notification has been send.", refreshJobScheduled);
assertFalse("The job should not be scheduled as no notification has been send.", refreshJobScheduled.get());
lockRepresentation(true);
assertTrue("The job should be scheduled as one lock notification has been send and ModelExplorer view is opened.", refreshJobScheduled);
bot.waitUntil(new DefaultCondition() {
@Override
public boolean test() throws Exception {
return refreshJobScheduled.get();
}

@Override
public String getFailureMessage() {
return "The job should be scheduled as one lock notification has been send and ModelExplorer view is opened.";
}
});
try {
Job.getJobManager().join(RefreshLabelImageJob.FAMILY, new NullProgressMonitor());
} catch (OperationCanceledException e) {
fail("Problem during waiting of RefreshLabelImageJob: " + e.getMessage());
} catch (InterruptedException e) {
fail("Problem during waiting of RefreshLabelImageJob: " + e.getMessage());
}
refreshJobScheduled = false;
refreshJobScheduled.set(false);
modelExplorerView.setFocus();
SWTBotUtils.waitAllUiEvents();
modelExplorerView.close();
try {
SWTBotUtils.waitAllUiEvents();
lockRepresentation(false);
assertFalse("The job should not be scheduled as one unlock notification has been send and ModelExplorer view is not opened.", refreshJobScheduled);
SWTBotUtils.waitAllUiEvents();
assertFalse("The job should not be scheduled as one unlock notification has been send and ModelExplorer view is not opened.", refreshJobScheduled.get());
} finally {
// Reopen the model explorer view (for following tests in suite)
Display.getDefault().syncExec(new Runnable() {
Expand Down

0 comments on commit b833d35

Please sign in to comment.