diff --git a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java index f4255b95a6..279bdd6ab7 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/retrying/ScheduledRetryingExecutorTest.java @@ -288,6 +288,11 @@ public void testCancelOuterFutureAfterStart() throws Exception { boolean res = future.cancel(false); assertTrue(res); assertFutureCancel(future); + + // Verify that the cancelled future is traced. Every attempt increases the number + // of cancellation attempts from the tracer. + Mockito.verify(tracer, Mockito.times(executionsCount + 1)).attemptCancelled(); + // Assert that future has at least been attempted once // i.e. The future from executor.submit() has been run by the ScheduledExecutor assertTrue(future.getAttemptSettings().getAttemptCount() > 0); @@ -297,34 +302,6 @@ public void testCancelOuterFutureAfterStart() throws Exception { localExecutor.awaitTermination(10, TimeUnit.SECONDS); } - @Test - public void testCancelIsTraced() throws Exception { - ScheduledExecutorService localExecutor = Executors.newSingleThreadScheduledExecutor(); - FailingCallable callable = new FailingCallable(4, "request", "SUCCESS", tracer); - RetrySettings retrySettings = - FAST_RETRY_SETTINGS - .toBuilder() - .setInitialRetryDelay(Duration.ofMillis(1_000L)) - .setMaxRetryDelay(Duration.ofMillis(1_000L)) - .setTotalTimeout(Duration.ofMillis(10_0000L)) - .build(); - RetryingExecutorWithContext executor = - getRetryingExecutor(getAlgorithm(retrySettings, 0, null), localExecutor); - RetryingFuture future = - executor.createFuture(callable, FakeCallContext.createDefault().withTracer(tracer)); - callable.setExternalFuture(future); - future.setAttemptFuture(executor.submit(future)); - - Thread.sleep(30L); - - boolean res = future.cancel(false); - assertTrue(res); - assertFutureCancel(future); - - Mockito.verify(tracer).attemptCancelled(); - localExecutor.shutdownNow(); - } - @Test public void testCancelProxiedFutureAfterStart() throws Exception { // this is a heavy test, which takes a lot of time, so only few executions.