Skip to content

Refactor tests to check only relevant tasks#86351

Merged
gmarouli merged 5 commits intoelastic:masterfrom
gmarouli:assert-only-relevant-tasks
May 4, 2022
Merged

Refactor tests to check only relevant tasks#86351
gmarouli merged 5 commits intoelastic:masterfrom
gmarouli:assert-only-relevant-tasks

Conversation

@gmarouli
Copy link
Copy Markdown
Contributor

@gmarouli gmarouli commented May 2, 2022

With #86131 we introduce a persistent task that will be always running. This is interfering with the current way the tests included in this PR are written. These tests are expecting that the tasks related to the test are the only tasks running. This assumption will not hold soon. For this reason, we refactor the tests so that the assertions are handling only the tasks that are related to the test.

There is only one exception BaseMlIntegTestCase, in this case it was easier to exclude unrelated tasks than to include all the possible tasks created as a side effect of the ML jobs. The constant UNRELATED_TASKS enabled developers to add tasks that need to be excluded, for example the new task we are introducing in #86131.

@gmarouli gmarouli added >non-issue :Distributed/Health Issues for the health report API v8.3.0 labels May 2, 2022
@elasticmachine elasticmachine added the Team:Data Management (obsolete) DO NOT USE. This team no longer exists. label May 2, 2022
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

Copy link
Copy Markdown
Contributor

@andreidan andreidan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Mary. Left a couple of minor suggestions

*/
public static List<PersistentTasksCustomMetadata.PersistentTask<?>> findTasks(ClusterState clusterState, String taskName) {
PersistentTasksCustomMetadata tasks = clusterState.metadata().custom(PersistentTasksCustomMetadata.TYPE);
return tasks.tasks().stream().filter(t -> t.getTaskName().equals(taskName)).toList();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this method is a special case of the other findTasks method, should we call the other one instead of reimplementing it here?
e.g.

findTasks(clusterState, Set.of(taskName))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid creating extra collections, but on second thought it's not worth the benefit. I will change it.

* Retrieves the persistent tasks with the requested task names from the given cluster state.
*/
public static List<PersistentTasksCustomMetadata.PersistentTask<?>> findTasks(ClusterState clusterState, Set<String> taskNames) {
PersistentTasksCustomMetadata tasks = clusterState.metadata().custom(PersistentTasksCustomMetadata.TYPE);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be null? Should we check for null and return List.of() ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, I didn't think that it could be null. I will double check it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@gmarouli
Copy link
Copy Markdown
Contributor Author

gmarouli commented May 4, 2022

@elasticmachine update branch

@gmarouli gmarouli merged commit a29bd8d into elastic:master May 4, 2022
@gmarouli gmarouli deleted the assert-only-relevant-tasks branch August 20, 2024 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Health Issues for the health report API >non-issue Team:Data Management (obsolete) DO NOT USE. This team no longer exists. v8.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants