Skip to content

Commit 03b5d7c

Browse files
committed
Complete incomplete future after test and do not use non-completed futures where not necessary
1 parent 1a47a5b commit 03b5d7c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/test/java/GoblintAnalysisTest.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import analysis.GoblintAnalysis;
22
import api.GoblintService;
3+
import api.messages.GoblintAnalysisResult;
34
import api.messages.params.AnalyzeParams;
45
import com.ibm.wala.classLoader.Module;
56
import goblintserver.GoblintConfWatcher;
@@ -43,8 +44,8 @@ void analyzeFailed() {
4344
doReturn(true).when(goblintServer).isAlive();
4445
when(goblintConfWatcher.refreshGoblintConfig()).thenReturn(true);
4546

46-
// Mock that the analyses of Goblint have started but not completed (still run)
47-
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(new CompletableFuture<>());
47+
// Mock that the analyses of Goblint have started and completed
48+
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(CompletableFuture.completedFuture(null));
4849

4950
// Mock that the incremental analysis is turned off (TODO: not sure why this is checked in reanalyze?)
5051
when(gobPieConfiguration.useIncrementalAnalysis()).thenReturn(true);
@@ -81,7 +82,8 @@ void abortAnalysis() throws IOException {
8182
when(goblintConfWatcher.refreshGoblintConfig()).thenReturn(true);
8283

8384
// Mock that the analyses of Goblint have started but not completed (still run)
84-
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(new CompletableFuture<>());
85+
CompletableFuture<GoblintAnalysisResult> runningProcess = new CompletableFuture<>();
86+
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(runningProcess);
8587

8688
// Mock that the incremental analysis is turned off (TODO: not sure why this is checked in reanalyze?)
8789
when(gobPieConfiguration.useIncrementalAnalysis()).thenReturn(true);
@@ -96,6 +98,7 @@ void abortAnalysis() throws IOException {
9698
// Verify that abortAnalysis was indeed called once
9799
verify(goblintServer).abortAnalysis();
98100
assertTrue(systemOut.getLines().anyMatch(line -> line.contains("--------------- This analysis has been aborted -------------")));
101+
runningProcess.complete(null);
99102
}
100103

101104
/**
@@ -121,8 +124,8 @@ void preAnalyseTest() {
121124
String[] preAnalyzeCommand = new String[]{"cmake", "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", "-B", "build"};
122125
when(gobPieConfiguration.getPreAnalyzeCommand()).thenReturn(preAnalyzeCommand);
123126

124-
// Mock that the analyses of Goblint have started but not completed (still run)
125-
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(new CompletableFuture<>());
127+
// Mock that the analyses of Goblint have started and completed
128+
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(CompletableFuture.completedFuture(null));
126129

127130
// Mock that the incremental analysis is turned off (TODO: not sure why this is checked in reanalyze?)
128131
when(gobPieConfiguration.useIncrementalAnalysis()).thenReturn(true);
@@ -162,8 +165,8 @@ void preAnalyseEmptyString() {
162165
String[] preAnalyzeCommand = new String[]{""};
163166
when(gobPieConfiguration.getPreAnalyzeCommand()).thenReturn(preAnalyzeCommand);
164167

165-
// Mock that the analyses of goblint have started but not completed (still run)
166-
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(new CompletableFuture<>());
168+
// Mock that the analyses of Goblint have started and completed
169+
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(CompletableFuture.completedFuture(null));
167170

168171
// Mock that the incremental analysis is turned off (TODO: not sure why this is checked in reanalyze?)
169172
when(gobPieConfiguration.useIncrementalAnalysis()).thenReturn(true);
@@ -195,8 +198,8 @@ void preAnalyseNull() {
195198
// Mock that the command to execute is null
196199
when(gobPieConfiguration.getPreAnalyzeCommand()).thenReturn(null);
197200

198-
// Mock that the analyses of goblint have started but not completed (still run)
199-
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(new CompletableFuture<>());
201+
// Mock that the analyses of Goblint have started and completed
202+
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(CompletableFuture.completedFuture(null));
200203

201204
// Mock that the incremental analysis is turned off (TODO: not sure why this is checked in reanalyze?)
202205
when(gobPieConfiguration.useIncrementalAnalysis()).thenReturn(true);
@@ -230,8 +233,8 @@ void preAnalyseError() {
230233
String[] preAnalyzeCommand = new String[]{"cmake", "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", "-B", "build"};
231234
when(gobPieConfiguration.getPreAnalyzeCommand()).thenReturn(preAnalyzeCommand);
232235

233-
// Mock that the analyses of goblint have started but not completed (still run)
234-
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(new CompletableFuture<>());
236+
// Mock that the analyses of Goblint have started and completed
237+
when(goblintService.analyze(new AnalyzeParams(false))).thenReturn(CompletableFuture.completedFuture(null));
235238
//.throw
236239

237240
// Mock that the incremental analysis is turned off (TODO: not sure why this is checked in reanalyze?)

0 commit comments

Comments
 (0)