Skip to content

Commit f18cf41

Browse files
committed
chore: Properly shutdown executor service that checks for updates
1 parent cfe188e commit f18cf41

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/main/java/com/endava/cats/command/CatsCommand.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.util.concurrent.ExecutorService;
5656
import java.util.concurrent.Executors;
5757
import java.util.concurrent.Future;
58+
import java.util.concurrent.TimeUnit;
5859
import java.util.stream.Collectors;
5960

6061
import static org.fusesource.jansi.Ansi.ansi;
@@ -116,7 +117,7 @@
116117
GenerateCommand.class,
117118
ExplainCommand.class
118119
})
119-
public class CatsCommand implements Runnable, CommandLine.IExitCodeGenerator {
120+
public class CatsCommand implements Runnable, CommandLine.IExitCodeGenerator, AutoCloseable {
120121

121122
private final PrettyLogger logger;
122123
private static final String SEPARATOR = "-".repeat(ConsoleUtils.getConsoleColumns(22));
@@ -494,4 +495,17 @@ private List<FuzzingData> filterFuzzingData(List<FuzzingData> fuzzingDataListWit
494495
public int getExitCode() {
495496
return exitCodeDueToErrors + executionStatisticsListener.getErrors();
496497
}
498+
499+
@Override
500+
public void close() throws Exception {
501+
executor.shutdown();
502+
try {
503+
if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
504+
executor.shutdownNow();
505+
}
506+
} catch (InterruptedException e) {
507+
executor.shutdownNow();
508+
Thread.currentThread().interrupt();
509+
}
510+
}
497511
}

src/test/java/com/endava/cats/command/LintCommandTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ class LintCommandTest {
2828
TestCaseListener testCaseListener;
2929
@Inject
3030
FilterArguments filterArguments;
31+
picocli.CommandLine.Model.CommandSpec spec;
3132

3233

3334
@BeforeEach
3435
void init() {
36+
picocli.CommandLine commandLine = new picocli.CommandLine(lintCommand);
37+
spec = commandLine.getCommandSpec();
3538
ReflectionTestUtils.setField(lintCommand, "contract", "contract");
3639
ReflectionTestUtils.setField(filterArguments, "fuzzersToBeRunComputed", false);
40+
ReflectionTestUtils.setField(filterArguments, "profile", "full");
3741
ReflectionTestUtils.setField(lintCommand, "catsCommand", catsCommand);
42+
ReflectionTestUtils.setField(catsCommand, "spec", spec);
3843
ReflectionTestUtils.setField(lintCommand, "skipLinters", Collections.emptyList());
3944
ReflectionTestUtils.setField(testCaseListener, "testReportsGenerator", Mockito.mock(TestReportsGenerator.class));
40-
4145
}
4246

4347
@Test

0 commit comments

Comments
 (0)