Skip to content

Commit

Permalink
Modify notCreateLongLivedThreadsAfterExecution to count live threads.
Browse files Browse the repository at this point in the history
  • Loading branch information
corneil committed Oct 15, 2024
1 parent fe11a77 commit 09f7cfe
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -90,10 +92,12 @@ void giveTheOutputToTheSpecifiedConsumerAsItIsAvailable() throws Exception {

@Test
void notCreateLongLivedThreadsAfterExecution() throws Exception {
int preThreadCount = Thread.getAllStackTraces().entrySet().size();
Set<Thread> preEntries = Thread.getAllStackTraces().keySet().stream().filter(Thread::isAlive).collect(Collectors.toSet());
int preThreadCount = preEntries.size();
dockerComposeCommand.execute(errorHandler, true, "rm", "-f");
int postThreadCount = Thread.getAllStackTraces().entrySet().size();
assertThat(preThreadCount == postThreadCount).as("command thread pool has exited").isTrue();
Set<Thread> postEntries = Thread.getAllStackTraces().keySet().stream().filter(Thread::isAlive).collect(Collectors.toSet());
int postThreadCount = postEntries.size();
assertThat(postThreadCount).as(()-> "command thread pool has exited with extra threads:" + postEntries.removeAll(preEntries)).isEqualTo(preThreadCount);
}

private void givenTheUnderlyingProcessHasOutput(String output) {
Expand Down

0 comments on commit 09f7cfe

Please sign in to comment.