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

Added unit tests for ClusterRequirer interface class #107

Merged
merged 7 commits into from
Dec 11, 2024

Conversation

lorenzo-medici
Copy link
Contributor

Issue

Missing test coverage for src/coordinated_workers/interface.py in class ClusterRequirer

Solution

Create additional tests with invalid databags, specifically when the cluster relation changes

Context

The ClusterProvider object is a relation endpoint wrapper for the 'cluster' relation interface.
That piece of code is responsible for walking through all units related over 'cluster' and collect a piece of data from their databags.

Testing Instructions

Run tox -e unit

Upgrade Notes

No code changes, only effect is increased test coverage.

@lorenzo-medici lorenzo-medici requested a review from a team as a code owner November 26, 2024 13:55
@lorenzo-medici
Copy link
Contributor Author

I forgot to run the linter before committing, I have already fixed everything locally and will push the changes together with the fixes from the review.

Copy link
Contributor

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

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

In addition to the issues I commented about, if I understand these tests correctly, you might have just found a bug.

I'm not sure why there should be a behavioural difference between 'invalid local app data' and 'invalid local unit data' when it comes to emitting 'cluster removed' events.

Could you mash those two tests into one, parametrize it with an app boolean field, depending on which value you choose what to patch and adapt your assertion?
And make a note that the assertion special-casing should not be necessary.

@lucabello do you agree that this is an issue?

Note for @lorenzo-medici: it will be out of scope for you and this PR to fix the bug, I'm just wondering if we should be opening a new one to track or not.

tests/test_coordinated_workers/test_coordinator.py Outdated Show resolved Hide resolved
tests/test_coordinated_workers/test_coordinator.py Outdated Show resolved Hide resolved
tests/test_coordinated_workers/test_coordinator.py Outdated Show resolved Hide resolved
tests/test_coordinated_workers/test_coordinator.py Outdated Show resolved Hide resolved
@lorenzo-medici
Copy link
Contributor Author

I merged the two unit tests into one with the app parameter making sure to leave a note regarding the difference in behavior.
I also applied the review suggestions.

Copy link
Contributor

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

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

one final nit

tests/test_coordinated_workers/test_worker.py Outdated Show resolved Hide resolved
tests/test_coordinated_workers/test_worker.py Outdated Show resolved Hide resolved
tests/test_coordinated_workers/test_worker.py Show resolved Hide resolved
Copy link
Contributor

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

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

much better! last pass :)

tests/test_coordinated_workers/test_worker.py Outdated Show resolved Hide resolved
tests/test_coordinated_workers/test_worker.py Show resolved Hide resolved
tests/test_coordinated_workers/test_worker.py Outdated Show resolved Hide resolved
tests/test_coordinated_workers/test_worker.py Outdated Show resolved Hide resolved
@lorenzo-medici
Copy link
Contributor Author

Is this failure my fault? All tests pass locally, and the failure point in the GH workflow is

/home/runner/work/cos-lib/cos-lib/src/charm.py
  /home/runner/work/cos-lib/cos-lib/src/charm.py:27:48 - error: "DatabagModel" is not exported from module "cosl.coordinated_workers.interface"
    Import from "cosl.interfaces.utils" instead (reportPrivateImportUsage)

which I don't know how to fix as DatabagModel is always imported from cosl.interfaces.utils.

@PietroPasotti
Copy link
Contributor

Is this failure my fault? All tests pass locally, and the failure point in the GH workflow is

/home/runner/work/cos-lib/cos-lib/src/charm.py
  /home/runner/work/cos-lib/cos-lib/src/charm.py:27:48 - error: "DatabagModel" is not exported from module "cosl.coordinated_workers.interface"
    Import from "cosl.interfaces.utils" instead (reportPrivateImportUsage)

which I don't know how to fix as DatabagModel is always imported from cosl.interfaces.utils.

No that's a recent change in cos-lib, it could be that the tempo coordinator's integration tests are broken because of it.

@PietroPasotti PietroPasotti self-requested a review December 6, 2024 07:24
@PietroPasotti PietroPasotti merged commit 23e369f into canonical:main Dec 11, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants