Skip to content

Conversation

@ywangd
Copy link
Member

@ywangd ywangd commented Mar 17, 2025

This PR updates the different methods in TestProjectResolvers so that
their names are more accurate and behaviours to be more as expected.

For example, In MP-1749, we differentiate between single-project and
single-project only resolvers. The later should not support multi-project.

ywangd added 2 commits March 17, 2025 17:16
In MP-1749, we differentiate between single-project and single-project
only resolvers. The later should not support multi-project.
This PR updates the different methods in TestProjectResolvers so that
their names are more accurate and behaviours to be more as expected.
@ywangd ywangd added >test Issues or PRs that are addressing/adding tests :Core/Infra/Core Core issues without another label v9.1.0 labels Mar 17, 2025
@ywangd ywangd requested a review from a team March 17, 2025 06:47
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Mar 17, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Comment on lines -63 to +64
public static ProjectResolver singleProjectOnly() {
public static ProjectResolver mustExecuteFirst() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This method is used in quite a few places in tests. Majority of them (if not all) really just need a projectResolver as a placehoder. The choice of using this variant is probably based on the method name and has no need for its execute behaviour. I renamed this method and added a new singleProjectOnly which does only what the name suggests. Hopefully this should satisfy all existing usages. But if not, we can tweak the places where it needs more.

Comment on lines 112 to 119
/**
* This method returns a ProjectResolver that returns a random unique project-id.
* It also assumes it is the only project in the cluster state and throws if that is not the case.
* In addition, the ProjectResolvers returns false for supportsMultipleProjects.
*/
public static ProjectResolver singleProjectOnly() {
return singleProjectOnly(ESTestCase.randomUniqueProjectId());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I get the goal of the implementation of this method. I understand that this method is mostly used as a placeholder, so we don't actually care about the project ID. However, by supplying a random project ID and checking if it exists in the cluster state, don't we always just return an exception if any of the methods are called? Wouldn't it make more sense to create a dedicated project resolver instance that just throws on every use? That would make the intent of this method/project resolver more clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does work for getProjectId(), supportsMultipleProjects(), executeOnProject(...) etc . I am not sure whether any of the existing usages rely on any of these. Probably not, I need to check.

return singleProjectOnly(ESTestCase.randomUniqueProjectId());
}

public static ProjectResolver singleProjectOnly(ProjectId projectId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a bit of Javadoc explaining this method as well?

Comment on lines 61 to 62
* with the executeOnProject method. This is mostly useful in places where we just need a placeholder to satisfy
* the constructor signature.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think we should remove the last sentence. The "placeholder usage" is singleProjectOnly. mustExecuteFirst has a pretty niche use case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it's a leftover that should be removed.

Copy link
Contributor

@nielsbauman nielsbauman 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 Yang!

@ywangd
Copy link
Member Author

ywangd commented Mar 20, 2025

@elasticmachine update branch

@ywangd ywangd merged commit 7a0a399 into elastic:main Mar 21, 2025
17 checks passed
afoucret pushed a commit to afoucret/elasticsearch that referenced this pull request Mar 21, 2025
This PR updates the different methods in TestProjectResolvers so that
their names are more accurate and behaviours to be more as expected.

For example, In MP-1749, we differentiate between single-project and
single-project only resolvers. The later should not support multi-project.
smalyshev pushed a commit to smalyshev/elasticsearch that referenced this pull request Mar 21, 2025
This PR updates the different methods in TestProjectResolvers so that
their names are more accurate and behaviours to be more as expected.

For example, In MP-1749, we differentiate between single-project and
single-project only resolvers. The later should not support multi-project.
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
This PR updates the different methods in TestProjectResolvers so that
their names are more accurate and behaviours to be more as expected.

For example, In MP-1749, we differentiate between single-project and
single-project only resolvers. The later should not support multi-project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team >test Issues or PRs that are addressing/adding tests v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants