|
26 | 26 | import org.elasticsearch.core.TimeValue;
|
27 | 27 | import org.elasticsearch.rest.RestStatus;
|
28 | 28 | import org.elasticsearch.test.ESIntegTestCase;
|
29 |
| -import org.elasticsearch.test.junit.annotations.TestLogging; |
| 29 | +import org.hamcrest.Matchers; |
30 | 30 |
|
31 | 31 | import java.util.EnumSet;
|
32 | 32 | import java.util.concurrent.CancellationException;
|
|
35 | 35 | import static org.elasticsearch.action.support.ActionTestUtils.wrapAsRestResponseListener;
|
36 | 36 | import static org.elasticsearch.test.TaskAssertions.assertAllCancellableTasksAreCancelled;
|
37 | 37 | import static org.elasticsearch.test.TaskAssertions.assertAllTasksHaveFinished;
|
38 |
| -import static org.elasticsearch.test.TaskAssertions.awaitTaskWithPrefix; |
| 38 | +import static org.elasticsearch.test.TaskAssertions.awaitTaskWithPrefixOnMaster; |
39 | 39 | import static org.hamcrest.core.IsEqual.equalTo;
|
40 | 40 |
|
41 | 41 | @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0)
|
42 |
| -@TestLogging(value = "org.elasticsearch.tasks.TaskManager:TRACE,org.elasticsearch.test.TaskAssertions:TRACE", reason = "debugging") |
43 | 42 | public class RestClusterInfoActionCancellationIT extends HttpSmokeTestCase {
|
44 | 43 |
|
45 | 44 | public void testGetMappingsCancellation() throws Exception {
|
@@ -77,8 +76,18 @@ private void runTest(String actionName, String endpoint) throws Exception {
|
77 | 76 | final Cancellable cancellable = getRestClient().performRequestAsync(request, wrapAsRestResponseListener(future));
|
78 | 77 |
|
79 | 78 | assertThat(future.isDone(), equalTo(false));
|
80 |
| - awaitTaskWithPrefix(actionName); |
81 |
| - |
| 79 | + awaitTaskWithPrefixOnMaster(actionName); |
| 80 | + // To ensure that the task is executing on master, we wait until the first blocked execution of the task registers its cluster state |
| 81 | + // observer for further retries. This ensures that a task is not cancelled before we have started its execution, which could result |
| 82 | + // in the task being unregistered and the test not being able to find any cancelled tasks. |
| 83 | + assertBusy( |
| 84 | + () -> assertThat( |
| 85 | + internalCluster().getCurrentMasterNodeInstance(ClusterService.class) |
| 86 | + .getClusterApplierService() |
| 87 | + .getTimeoutClusterStateListenersSize(), |
| 88 | + Matchers.greaterThan(0) |
| 89 | + ) |
| 90 | + ); |
82 | 91 | cancellable.cancel();
|
83 | 92 | assertAllCancellableTasksAreCancelled(actionName);
|
84 | 93 |
|
|
0 commit comments