Skip to content
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

Replace mocks with test implementation in RepositoriesServiceTests #108589

Merged
merged 3 commits into from
May 14, 2024

Conversation

mhl-b
Copy link
Contributor

@mhl-b mhl-b commented May 13, 2024

I observed that testRegisterRepositorySuccessAfterCreationFailed test never invokes assertion blocks, because listener is not invoked.

There are 2 problems:

  1. Test setup used mocks. Mocks interrupt listener chain propagation, so registerRepository never returned Response or Failure.
  2. We silently ignore assertions in listener because it is not invoked. Test pass successfully.

PutRepositories method relies on cluster state update. I replace mocked ClusterService and ThreadPool with test implementation of these. Also add blocking call on listener to ensure we get result.

Address comment to break down larger PR into smaller pieces in #108531

@elasticsearchmachine elasticsearchmachine added v8.15.0 needs:triage Requires assignment of a team area label labels May 13, 2024
@mhl-b mhl-b changed the title Repo ut mocks Replace mocks with test implementation in RepositoriesServiceTest May 13, 2024
@mhl-b mhl-b changed the title Replace mocks with test implementation in RepositoriesServiceTest Replace mocks with test implementation in RepositoriesServiceTests May 13, 2024
@mhl-b mhl-b added >test Issues or PRs that are addressing/adding tests :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Meta label for distributed team and removed needs:triage Requires assignment of a team area label labels May 13, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM2, one nit

Comment on lines +102 to +103
// cluster utils publisher does not call AckListener, making some method calls hang indefinitely
// in this test we have a single master node, and it acknowledges cluster state immediately
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 319 to 320
var resp = safeAwait(resultListener);
assertTrue(resp.isAcknowledged());
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would rather not use abbrs. for var. names wherever poss. :)

Suggested change
var resp = safeAwait(resultListener);
assertTrue(resp.isAcknowledged());
var response = safeAwait(resultListener);
assertTrue(response.isAcknowledged());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ofc

@mhl-b mhl-b added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label May 14, 2024
@elasticsearchmachine elasticsearchmachine merged commit a3b25a9 into elastic:main May 14, 2024
15 checks passed
@mhl-b mhl-b deleted the repo-ut-mocks branch May 14, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Meta label for distributed team >test Issues or PRs that are addressing/adding tests v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants