-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Use opaque id in task cancellation assertion #110680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use opaque id in task cancellation assertion #110680
Conversation
Pinging @elastic/es-distributed (Team:Distributed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good idea to me. I left some inline comments mainly about checking expectations more strictly.
@@ -70,6 +72,14 @@ public static void assertAllCancellableTasksAreCancelled(String actionPrefix) th | |||
for (CancellableTask cancellableTask : taskManager.getCancellableTasks().values()) { | |||
if (cancellableTask.getAction().startsWith(actionPrefix)) { | |||
logger.trace("--> found task with prefix [{}]: [{}]", actionPrefix, cancellableTask); | |||
if (taskOpaqueIdMatches(cancellableTask.headers(), opaqueId) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather not leniently skip non-matching tasks: we shouldn't have any such tasks in the first place. If this is the problem then I'd prefer to track down where those tasks are coming from and get rid of them at source.
Let's assert that the task ID matches here instead.
// returns new or existing id | ||
private static String setOpaqueIdIfNotExists(Request request) { | ||
String opaqueId; | ||
if (request.getOptions().containsHeader(Task.X_OPAQUE_ID_HTTP_HEADER)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is dead code today since none of the requests include an opaque-id header. Let's just assert it's absent.
} | ||
|
||
private static boolean taskOpaqueIdMatches(Map<String, String> taskHeaders, @Nullable String opaqueId) { | ||
if (opaqueId == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should assert the opaque ID is missing if we didn't expect to see one.
@DaveCTurner thank you for feedback. I added assertions and test names to the opaque id. Also added more explicit exception message in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, one suggestion about how to identify the test more neatly
@@ -71,11 +72,16 @@ protected boolean addMockInternalEngine() { | |||
return false; | |||
} | |||
|
|||
void runTest(Request request, String actionPrefix) throws Exception { | |||
void runTest(String testName, Request request, String actionPrefix) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than passing in a string that (hopefully) identifies the test, I'd suggest using org.apache.lucene.tests.util.LuceneTestCase#getTestName
(and maybe org.apache.lucene.tests.util.LuceneTestCase#getTestClass
).
@@ -19,9 +19,9 @@ | |||
*/ | |||
public class CancellableTask extends Task { | |||
|
|||
private final SubscribableListener<Void> listeners = new SubscribableListener<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: did you mean to move this field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applied formatting to entire file...
public static void assertAllTasksHaveFinished(String actionPrefix) throws Exception { | ||
logger.info("--> checking that all tasks with prefix {} have finished", actionPrefix); | ||
assertBusy(() -> { | ||
final List<TaskInfo> tasks = client().admin().cluster().prepareListTasks().get().getTasks(); | ||
assertTrue(tasks.toString(), tasks.stream().noneMatch(t -> t.action().startsWith(actionPrefix))); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Add use of Opaque ID HTTP header in task cancellation assertion. In some tests, like this #88201 `testCatSegmentsRestCancellation`, we assert that all tasks related to specific HTTP request are cancelled. But we do blanket approach in assertion block catching all tasks by action name. I think narrowing down assertion to specific http request in this case would be more accurate. It is still not clear why test mentioned above failing, but after hours of investigation and injecting random delays, I'm inclining more to @DaveCTurner's comment about interference from other tests or cluster activity. I added additional log that will report when we spot task with different opaque id.
Add use of Opaque ID HTTP header in task cancellation assertion. In some tests, like this #88201 `testCatSegmentsRestCancellation`, we assert that all tasks related to specific HTTP request are cancelled. But we do blanket approach in assertion block catching all tasks by action name. I think narrowing down assertion to specific http request in this case would be more accurate. It is still not clear why test mentioned above failing, but after hours of investigation and injecting random delays, I'm inclining more to @DaveCTurner's comment about interference from other tests or cluster activity. I added additional log that will report when we spot task with different opaque id.
Add use of Opaque ID HTTP header in task cancellation assertion. In some tests, like this #88201
testCatSegmentsRestCancellation
, we assert that all tasks related to specific HTTP request are cancelled. But we do blanket approach in assertion block catching all tasks by action name. I think narrowing down assertion to specific http request in this case would be more accurate.It is still not clear why test mentioned above failing, but after hours of investigation and injecting random delays, I'm inclining more to @DaveCTurner's comment about interference from other tests or cluster activity. I added additional log that will report when we spot task with different opaque id.