-
Notifications
You must be signed in to change notification settings - Fork 259
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
TESTS: Refactor memcache tests #7889
base: master
Are you sure you want to change the base?
Conversation
Need help with:
|
8decb00
to
1391c5d
Compare
""" | ||
SSSD In-Memory Cache (memcache) Test Cases. | ||
|
||
:requirement: IDM-SSSD-REQ: Client side performance improvements |
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.
some of the jobs failed on Check polarion metadata
task .. probably because it didn't find test results it was looking for most likely because of the fact that this is deleted.
ValueError: Required field 'requirement' is missing for 'tests/test_memcache.py::test_memcache__user_group_initigroup_cache_alternately_disabled[with_memcache-users] (ipa)'
https://github.com/SSSD/sssd/actions/runs/14023157007/job/39257996729?pr=7889
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.
@danlavu can you help me with that?
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.
Right now, lets change the requirement name to something else, :requirement: memcache
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.
Done
be9858f
to
52665e0
Compare
c143bf1
to
14ba349
Compare
14ba349
to
60d6b81
Compare
29b65f2
to
4b4241d
Compare
All system tests are red, including some of tests being added. |
4b4241d
to
38059b2
Compare
result = client.tools.id("user1@test") | ||
assert result is not None, "User user1@test was not found using id" | ||
assert result.user.name == "user1@test", f"User {result.user.name} has incorrect name, user1@test expected" | ||
if lookup_type in ("users", "users_and_groups") and not memcache: |
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.
This is ugly, it would be much better to have multiple stanalone tests.
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 did a bit of refactoring there, but not as much as you would like to. I hope we can find a middle ground.
38059b2
to
a5d3afa
Compare
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.
It looks like the testcases are merged/parametrized too much making them hard to read. I suggest splitting the ones that have this anti-pattern
if x:
assert abc
assert def
else:
assert ghi
assert jkl
In ideal case the asserts match 1:1 with steps/expected results.
gresult = client.tools.getent.group("group1") | ||
assert gresult is not None, "Group group1 is not found using getent" | ||
assert gresult.gid == 10001, f"Group gid {gresult.gid} is incorrect, 10001 expected" | ||
if by_gid: |
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.
This code branching suggests there should be (at least) two testcases instead.
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 agree with improving the readability of the tests, but I disagree breaking this test into 2.
Something nicer would be:
if search_type["by_gid"]:
...
if search_type["by_name"]:
wdyt?
a5d3afa
to
2a14e9c
Compare
2a14e9c
to
df37f34
Compare
https://github.com/SSSD/sssd/actions/runs/14217973656/job/39838952159?pr=7889
|
I am investigating that because it doesn't make sense what is happening. It is literally the same call I am using on other places. |
57875cc
to
a3df52d
Compare
Refactored the entire memcache tests according to the new testing plan. Improved the tests using parametrization. Removed redundant tests and included the new ones.
a3df52d
to
cb3ca3a
Compare
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.
Parametrizing test to a single assert selected by different conditions just makes it harder to read and increases overhead of the setup/teardown in comparison with making the test with more steps or keeping multiple simple and readable tests . I just can't agree with going this direction.
if memcache: | ||
if lookup_type in ("users"): | ||
assert ( | ||
client.tools.getent.passwd("user1") is not None | ||
), "`user1` should still be found after stopping SSSD." | ||
if lookup_type in ("groups"): | ||
assert ( | ||
client.tools.getent.group("group1") is not None | ||
), "`group1` should still be found after stopping SSSD." | ||
elif not memcache: | ||
if lookup_type in ("users"): | ||
assert client.tools.getent.passwd("user1") is None, "`user1` should NOT be found after stopping SSSD." | ||
if lookup_type in ("groups"): | ||
assert client.tools.getent.group("group1") is None, "`group1` should NOT be found after stopping SSSD." |
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.
This is still unsightly. How about rewriting it like this (maybe parametrize only "lookup_type", ["users", "groups"]?
- sssd is running and user and group is found.
- sssd is stopped with memcache and user and group is found.
- sssd is started again without memcache and user and group is found.
- sssd is stopped without memcache and user and group is not found.
If You make it in parametrized to 4 tests it will be all of the setup and teardown will be run 4 times for each of the provider making the overhead costly and the test less readable. It might be better to have more steps it the test instead at the cost that firs failure will stop the test.
@andreboscatto, could you please rebase? |
Refactored the entire memcache tests according to the new testing plan. Improved the tests using parametrization. Removed redundant tests and included the new ones.