From 6a77739a7b54e0b853b365aacea5d707cce924d1 Mon Sep 17 00:00:00 2001 From: Pascal Zimmermann Date: Thu, 26 Nov 2026 08:48:27 +0100 Subject: [PATCH] fix: Make TasksTest.cancel independent of the task's timing The Cloud Controller sets a canceled task to CANCELING, cancels it in Diego and then reloads it for the response. When Diego reports the canceled task as FAILED before that reload, the response shows FAILED and the test failed with "expected value: CANCELING; actual value: FAILED". The test now accepts CANCELING and FAILED, and cancels a "sleep 99" task instead of "ls", which could finish before the cancel request and make the Cloud Controller reject it. --- .../org/cloudfoundry/client/v3/TasksTest.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/TasksTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/TasksTest.java index ec5970a08b..5c929abdfa 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/TasksTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/TasksTest.java @@ -16,6 +16,7 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; import static org.cloudfoundry.client.v3.tasks.TaskState.RUNNING; import static org.cloudfoundry.util.tuple.TupleUtils.function; @@ -74,7 +75,11 @@ public void cancel() throws IOException { .flatMap( function( (applicationId, dropletId) -> - createTaskId(this.cloudFoundryClient, applicationId))) + // A short command like "ls" can finish before the cancel + // request, which then fails with "Task state is SUCCEEDED + // and therefore cannot be canceled". + createLongRunningTaskId( + this.cloudFoundryClient, applicationId))) .flatMap( taskId -> this.cloudFoundryClient @@ -82,7 +87,11 @@ public void cancel() throws IOException { .cancel(CancelTaskRequest.builder().taskId(taskId).build()) .map(CancelTaskResponse::getState)) .as(StepVerifier::create) - .expectNext(TaskState.CANCELING) + // The Cloud Controller sets the task to CANCELING, cancels it in Diego and then + // reloads it for the response. If Diego has already reported the canceled task as + // FAILED by then, the response shows FAILED instead of CANCELING. + .consumeNextWith( + state -> assertThat(state).isIn(TaskState.CANCELING, TaskState.FAILED)) .expectComplete() .verify(Duration.ofMinutes(5)); } @@ -305,6 +314,20 @@ private static Mono createTaskId( return requestCreateTask(cloudFoundryClient, applicationId).map(CreateTaskResponse::getId); } + private static Mono createLongRunningTaskId( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .tasks() + .create( + CreateTaskRequest.builder() + .applicationId(applicationId) + .command("sleep 99") + .diskInMb(64) + .memoryInMb(67) + .build()) + .map(CreateTaskResponse::getId); + } + private static Mono getApplicationId( CloudFoundryClient cloudFoundryClient, String applicationName) { return PaginationUtils.requestClientV3Resources(