Skip to content

Commit e20db68

Browse files
committed
Run tests in background
1 parent d2694c1 commit e20db68

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/actions/RunTestsLocallyAction.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44
import fi.helsinki.cs.tmc.core.domain.Exercise;
55
import fi.helsinki.cs.tmc.core.domain.ProgressObserver;
66
import fi.helsinki.cs.tmc.data.ResultCollector;
7+
import fi.helsinki.cs.tmc.langs.abstraction.ValidationResult;
8+
import fi.helsinki.cs.tmc.langs.domain.RunResult;
79
import fi.helsinki.cs.tmc.model.CourseDb;
810
import fi.helsinki.cs.tmc.model.ProjectMediator;
11+
import fi.helsinki.cs.tmc.model.TmcProjectInfo;
12+
import fi.helsinki.cs.tmc.utilities.AggregatingBgTaskListener;
13+
import fi.helsinki.cs.tmc.utilities.BgTask;
14+
import fi.helsinki.cs.tmc.utilities.BgTaskListener;
915

16+
import java.util.List;
17+
import java.util.logging.Level;
1018
import java.util.logging.Logger;
1119
import org.netbeans.api.project.Project;
1220
import org.openide.nodes.Node;
@@ -70,14 +78,42 @@ protected boolean enabledFor(Exercise exercise) {
7078
@Override
7179
public void run() {
7280
Exercise exercise = exerciseForProject(project);
81+
final ResultCollector resultCollector = new ResultCollector(exercise);
82+
7383
if (exercise != null) {
74-
try {
75-
ResultCollector resultCollector = new ResultCollector(exercise);
76-
resultCollector.setLocalTestResults(TmcCore.get().runTests(ProgressObserver.NULL_OBSERVER, exercise).call());
77-
resultCollector.setValidationResult(TmcCore.get().runCheckStyle(ProgressObserver.NULL_OBSERVER, exercise).call());
78-
} catch (Exception ex) {
79-
Exceptions.printStackTrace(ex);
80-
}
84+
BgTask.start("Running tests for " + exercise.getName(), TmcCore.get().runTests(ProgressObserver.NULL_OBSERVER, exercise), new BgTaskListener<RunResult>() {
85+
@Override
86+
public void bgTaskReady(RunResult result) {
87+
resultCollector.setLocalTestResults(result);
88+
}
89+
90+
@Override
91+
public void bgTaskCancelled() {
92+
// NOP
93+
}
94+
95+
@Override
96+
public void bgTaskFailed(Throwable ex) {
97+
log.log(Level.WARNING, "Test run failed:", ex);
98+
}
99+
});
81100
}
101+
102+
BgTask.start("Running code style validations", TmcCore.get().runCheckStyle(ProgressObserver.NULL_OBSERVER, exercise), new BgTaskListener<ValidationResult>() {
103+
@Override
104+
public void bgTaskReady(ValidationResult result) {
105+
resultCollector.setValidationResult(result);
106+
}
107+
108+
@Override
109+
public void bgTaskCancelled() {
110+
// NOP
111+
}
112+
113+
@Override
114+
public void bgTaskFailed(Throwable ex) {
115+
log.log(Level.WARNING, "Code style run failed:", ex);
116+
}
117+
});
82118
}
83119
}

tmc-plugin/src/fi/helsinki/cs/tmc/data/ResultCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void setLocalTestResults(RunResult runResult) {
4949
setTestCaseResults(runResult.testResults);
5050
}
5151

52-
private void showResultsIfReady() {
52+
private synchronized void showResultsIfReady() {
5353

5454
boolean ready = testCaseResultsSet && validationResultsSet;
5555
if (ready) {

0 commit comments

Comments
 (0)