Add `runFinalization` to `waitForGC`
MODIFY
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/TestUtils.java
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/TestUtils.java
@@ -212,6 +212,7 @@ public class TestUtils {
obj = null;
while (ref.get() != null) {
System.gc();
+ System.runFinalization();
}
}
}

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/PendingTrace.java
dd-trace-ot/src/main/java/datadog/opentracing/PendingTrace.java
@@ -213,20 +213,6 @@ public class PendingTrace extends ConcurrentLinkedDeque<DDSpan> {
return count > 0;
}
- /**
- * This method ensures that garbage collection takes place, unlike <code>{@link System#gc()}
- * </code>. Useful for testing.
- */
- public static void awaitGC() {
- System.gc(); // For good measure.
- Object obj = new Object();
- final WeakReference ref = new WeakReference<>(obj);
- obj = null;
- while (ref.get() != null) {
- System.gc();
- }
- }
-
static void close() {
SPAN_CLEANER.close();
}

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/PendingTraceTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/PendingTraceTest.groovy
package datadog.opentracing
+import datadog.trace.agent.test.TestUtils
import datadog.trace.common.writer.ListWriter
import spock.lang.Specification
import spock.lang.Subject
@@ -106,7 +107,7 @@ class PendingTraceTest extends Specification {
when:
child = null
while (!trace.clean()) {
- trace.awaitGC()
+ TestUtils.awaitGC()
}
then:

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/scopemanager/ScopeManagerTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/scopemanager/ScopeManagerTest.groovy
@@ -3,7 +3,7 @@ package datadog.opentracing.scopemanager
import datadog.opentracing.DDSpan
import datadog.opentracing.DDSpanContext
import datadog.opentracing.DDTracer
-import datadog.opentracing.PendingTrace
+import datadog.trace.agent.test.TestUtils
import datadog.trace.common.writer.ListWriter
import io.opentracing.Scope
import io.opentracing.Span
@@ -149,7 +149,7 @@ class ScopeManagerTest extends Specification {
continuation.activate()
if (forceGC) {
continuation = null // Continuation references also hold up traces.
- PendingTrace.awaitGC()
+ TestUtils.awaitGC()
((DDSpanContext) scope.span().context()).trace.clean()
}
if (autoClose) {
@@ -196,7 +196,7 @@ class ScopeManagerTest extends Specification {
if (forceGC) {
continuation = null // Continuation references also hold up traces.
while (!((DDSpanContext) span.context()).trace.clean()) {
- PendingTrace.awaitGC()
+ TestUtils.awaitGC()
}
writer.waitForTraces(1)
}

Add `runFinalization` to `waitForGC`