Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package datadog.smoketest;

import datadog.trace.api.internal.VisibleForTesting;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -23,17 +24,26 @@ public class OutputThreads implements Closeable {
private static final int MAX_LINE_SIZE = 1024 * 1024;
private static final int DEFAULT_TIMEOUT_MILLIS = 10_000;

final ThreadGroup tg = new ThreadGroup("smoke-output");
final ThreadGroup tg;
final List<String> testLogMessages = new ArrayList<>();

public OutputThreads() {
this(new ThreadGroup("smoke-output"));
}

@VisibleForTesting
OutputThreads(ThreadGroup tg) {
this.tg = tg;
}

public void close() {
tg.interrupt();
Thread[] threads = new Thread[tg.activeCount()];
tg.enumerate(threads);
int threadCount = tg.enumerate(threads);

for (Thread thread : threads) {
for (int i = 0; i < threadCount; i++) {
try {
thread.join(THREAD_JOIN_TIMEOUT_MILLIS);
threads[i].join(THREAD_JOIN_TIMEOUT_MILLIS);
} catch (InterruptedException e) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package datadog.smoketest;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import org.junit.jupiter.api.Test;

class OutputThreadsTest {

@Test
void closeOnlyJoinsEnumeratedThreads() {
ThreadGroup shrinkingThreadGroup =
new ThreadGroup("shrinking-smoke-output") {
@Override
public int activeCount() {
return 1;
}

@Override
public int enumerate(Thread[] threads) {
return 0;
}
};

assertDoesNotThrow(() -> new OutputThreads(shrinkingThreadGroup).close());
}
}