Test: improve error message on leftover tasks

After every REST test we wait for the list of pending cluster tasks
to empty before moving on to the next task. If the list doesn't
empty in 10 second we fail the test. This improves the error message
when we fail the test to include the list of running tasks.
This commit is contained in:
Nik Everett 2017-06-02 11:02:44 -04:00
parent 6ea9d83b2d
commit 18f16ba555
1 changed files with 10 additions and 3 deletions

View File

@ -40,7 +40,6 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@ -56,6 +55,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.net.ssl.SSLContext;
import static java.util.Collections.singletonMap;
import static java.util.Collections.sort;
import static java.util.Collections.unmodifiableList;
@ -262,8 +263,14 @@ public abstract class ESRestTestCase extends ESTestCase {
assertBusy(() -> {
try {
Response response = adminClient().performRequest("GET", "_cluster/pending_tasks");
List<Object> tasks = (List<Object>) entityAsMap(response).get("tasks");
assertTrue(tasks.isEmpty());
List<?> tasks = (List<?>) entityAsMap(response).get("tasks");
if (false == tasks.isEmpty()) {
StringBuilder message = new StringBuilder("there are still running tasks:");
for (Object task: tasks) {
message.append('\n').append(task.toString());
}
fail(message.toString());
}
} catch (IOException e) {
fail("cannot get cluster's pending tasks: " + e.getMessage());
}