Skip to content

Commit

Permalink
Use TestObservationRegistry in context propagation tests (#810)
Browse files Browse the repository at this point in the history
Co-authored-by: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com>
Co-authored-by: Jonatan Ivanov <jonatan.ivanov@gmail.com>
  • Loading branch information
3 people authored Sep 5, 2024
1 parent 92795f2 commit ccb8adf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.micrometer.context.ContextSnapshot;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.tck.TestObservationRegistry;
import io.micrometer.tracing.CurrentTraceContext.Scope;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.Tracer;
Expand All @@ -44,7 +45,7 @@ class NestedScopesTests {

DefaultTracingObservationHandler handler = new DefaultTracingObservationHandler(tracer);

ObservationRegistry observationRegistry = ObservationRegistry.create();
ObservationRegistry observationRegistry = TestObservationRegistry.create();

@BeforeEach
void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
import io.micrometer.observation.tck.TestObservationRegistry;
import io.micrometer.tracing.BaggageInScope;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.Tracer;
Expand All @@ -45,12 +46,10 @@
import reactor.core.scheduler.Schedulers;
import reactor.util.context.Context;

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;

import static org.assertj.core.api.BDDAssertions.then;
Expand Down Expand Up @@ -83,7 +82,7 @@ class ScopesTests {
Tracer tracer = new BraveTracer(this.braveTracer, new BraveCurrentTraceContext(this.currentTraceContext),
new BraveBaggageManager());

ObservationRegistry observationRegistry = ObservationRegistry.create();
ObservationRegistry observationRegistry = TestObservationRegistry.create();

@BeforeEach
void setup() {
Expand Down Expand Up @@ -197,7 +196,9 @@ void should_open_and_close_scopes_with_reactor_multithreaded() {
}
else {
try {
latch.await();
if (!latch.await(1, TimeUnit.SECONDS)) {
throw new RuntimeException("Waiting for the latch timed out!");
}
}
catch (InterruptedException e) {
// ignore
Expand All @@ -217,7 +218,7 @@ void should_open_and_close_scopes_with_reactor_multithreaded() {
Span spanWOnNext = tracer.currentSpan();
logger.info("[outer-doOnNext] SPAN IN ON NEXT [" + spanWOnNext + "]");
assertInReactor(errorsInOuterOnNext, spanWOnNext, span2);
}).blockLast();
}).blockLast(Duration.ofSeconds(1));

logger.info("Checking if there were no errors in reactor");
then(errorsInFlatMap).isEmpty();
Expand Down Expand Up @@ -254,7 +255,9 @@ void should_open_and_close_scopes_with_reactor_multithreaded() {
Observation obs4 = Observation.start("4", observationRegistry);
try (Observation.Scope scope4 = obs4.openScope()) {
logger.info("FRESH SPAN AFTER [{}]", tracer.currentSpan());
cleanupLatch.await();
if (!cleanupLatch.await(1, TimeUnit.SECONDS)) {
throw new RuntimeException("Waiting for the latch timed out!");
}
}
catch (InterruptedException e) {
// ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.micrometer.context.ContextSnapshot;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.tck.TestObservationRegistry;
import io.micrometer.tracing.CurrentTraceContext.Scope;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.Tracer;
Expand Down Expand Up @@ -59,7 +60,7 @@ class NestedScopesTests {

DefaultTracingObservationHandler handler = new DefaultTracingObservationHandler(tracer);

ObservationRegistry observationRegistry = ObservationRegistry.create();
ObservationRegistry observationRegistry = TestObservationRegistry.create();

@BeforeEach
void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
import io.micrometer.observation.tck.TestObservationRegistry;
import io.micrometer.tracing.BaggageInScope;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.Tracer;
Expand Down Expand Up @@ -71,7 +72,7 @@ class ScopesTests {

DefaultTracingObservationHandler handler = new DefaultTracingObservationHandler(tracer);

ObservationRegistry observationRegistry = ObservationRegistry.create();
ObservationRegistry observationRegistry = TestObservationRegistry.create();

@BeforeEach
void setup() {
Expand Down

0 comments on commit ccb8adf

Please sign in to comment.