Skip to content

Commit

Permalink
Fix TasksIT#testGetTaskWaitForCompletionWithoutStoringResult
Browse files Browse the repository at this point in the history
Make sure the `.tasks` index is created before we starting testing task completion
without storing its result. To achieve that, we store a fake task before we start
`waitForCompletionTestCase`.

Resolves #107823
  • Loading branch information
arteam committed Apr 30, 2024
1 parent f4fac1e commit bf3b27d
Showing 1 changed file with 44 additions and 31 deletions.
Expand Up @@ -562,6 +562,21 @@ public void testListTasksWaitForCompletion() throws Exception {
}

public void testGetTaskWaitForCompletionWithoutStoringResult() throws Exception {
// Need to make sure the .tasks index gets created, so let's add a fake task first
var latch = new CountDownLatch(1);
internalCluster().getInstance(TaskResultsService.class).storeResult(new TaskResult(true, fakeTask()), new ActionListener<Void>() {
@Override
public void onResponse(Void response) {
latch.countDown();
}

@Override
public void onFailure(Exception e) {
throw new RuntimeException(e);
}
});
safeAwait(latch);

waitForCompletionTestCase(false, id -> clusterAdmin().prepareGetTask(id).setWaitForCompletion(true).execute(), response -> {
assertTrue(response.getTask().isCompleted());
// We didn't store the result so it won't come back when we wait
Expand Down Expand Up @@ -844,40 +859,21 @@ public void testNodeNotFoundButTaskFound() throws Exception {
// Save a fake task that looks like it is from a node that isn't part of the cluster
CyclicBarrier b = new CyclicBarrier(2);
TaskResultsService resultsService = internalCluster().getInstance(TaskResultsService.class);
resultsService.storeResult(
new TaskResult(
new TaskInfo(
new TaskId("fake", 1),
"test",
"fake",
"test",
"",
null,
0,
0,
false,
false,
TaskId.EMPTY_TASK_ID,
Collections.emptyMap()
),
new RuntimeException("test")
),
new ActionListener<Void>() {
@Override
public void onResponse(Void response) {
try {
b.await();
} catch (InterruptedException | BrokenBarrierException e) {
onFailure(e);
}
resultsService.storeResult(new TaskResult(fakeTask(), new RuntimeException("test")), new ActionListener<Void>() {
@Override
public void onResponse(Void response) {
try {
b.await();
} catch (InterruptedException | BrokenBarrierException e) {
onFailure(e);
}
}

@Override
public void onFailure(Exception e) {
throw new RuntimeException(e);
}
@Override
public void onFailure(Exception e) {
throw new RuntimeException(e);
}
);
});
b.await();

// Now we can find it!
Expand Down Expand Up @@ -988,4 +984,21 @@ private GetTaskResponse expectFinishedTask(TaskId taskId) throws IOException {
assertNull(info.status()); // The test task doesn't have any status
return response;
}

private static TaskInfo fakeTask() {
return new TaskInfo(
new TaskId("fake", 1),
"test",
"fake",
"test",
"",
null,
0,
0,
false,
false,
TaskId.EMPTY_TASK_ID,
Collections.emptyMap()
);
}
}

0 comments on commit bf3b27d

Please sign in to comment.