Skip to content

Commit

Permalink
Wait for all analysis jobs to complete at the end of each IT
Browse files Browse the repository at this point in the history
  • Loading branch information
damien-urruty-sonarsource committed Apr 15, 2022
1 parent ff14c0c commit 194aeaf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion its/src/org/sonarlint/eclipse/its/AbstractSonarLintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public abstract class AbstractSonarLintTest {

@After
public final void cleanup() {
// first wait for previous analyzes to finish properly
// this prevents trying to clear the console in the middle of a job
waitSonarLintAnalysisJobs();

SonarLintConsole consoleView = new SonarLintConsole();
System.out.println(consoleView.getConsoleView().getConsoleText());
Expand All @@ -111,11 +114,25 @@ public final void cleanup() {
ConfigurationScope.INSTANCE.getNode(UI_PLUGIN_ID).remove(PREF_SECRETS_EVER_DETECTED);
}

private void waitSonarLintAnalysisJobs() {
sonarlintJobFamilies.forEach(jobFamily -> {
try {
Job.getJobManager().join(jobFamily, null);
} catch (Exception e) {
System.out.println("Error while waiting jobs to finish");
e.printStackTrace();
}
});
}

protected static int hotspotServerPort = -1;
private static IJobChangeListener sonarlintItJobListener;
protected static final AtomicInteger scheduledAnalysisJobCount = new AtomicInteger();
private static final List<CountDownLatch> analysisJobCountDownLatch = new CopyOnWriteArrayList<>();
private static File projectsFolder;
private static final List<String> sonarlintJobFamilies = List.of(
"org.sonarlint.eclipse.projectJob",
"org.sonarlint.eclipse.projectsJob");

@BeforeClass
public static final void beforeClass() throws BackingStoreException {
Expand Down Expand Up @@ -145,7 +162,7 @@ public void done(IJobChangeEvent event) {
}

private boolean isSonarLintAnalysisJob(IJobChangeEvent event) {
return event.getJob().belongsTo("org.sonarlint.eclipse.projectJob") || event.getJob().belongsTo("org.sonarlint.eclipse.projectsJob");
return sonarlintJobFamilies.stream().anyMatch(family -> event.getJob().belongsTo(family));
}
};
Job.getJobManager().addJobChangeListener(sonarlintItJobListener);
Expand Down

0 comments on commit 194aeaf

Please sign in to comment.