@Test
public void testTracingAsync() throws ExecutionException, InterruptedException {

  final RequestContext requestContext = mock(RequestContext.class);
  final Request request = Request.forUri("/bar", "GET");
  final MockSpan span = new MockSpan();
  when(requestContext.request()).thenReturn(request);
  when(tracer.spanBuilder("foo-service//bar")).thenReturn(spanBuilder);
  when(spanBuilder.startSpan()).thenReturn(span);
  final CompletableFuture<Response<Object>> handlerFuture = new CompletableFuture<>();
  final CompletableFuture<Response<Object>> responseFuture = Middlewares.tracer(tracer, "foo-service")
      .apply(rc -> handlerFuture)
      .invoke(requestContext)
      .toCompletableFuture();
  // Request handling is not complete, span should not be ended
  assertThat(span.ended, is(false));
  // Complete request handling future and wait for response
  handlerFuture.complete(Response.ok());
  responseFuture.get();
  // Span should now be ended
  assertThat(span.ended, is(true));
  assertThat(span.status, is(nullValue()));
}