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

TESTS: Refactor memcache tests #7889

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andreboscatto
Copy link
Contributor

Refactored the entire memcache tests according to the new testing plan. Improved the tests using parametrization. Removed redundant tests and included the new ones.

@andreboscatto
Copy link
Contributor Author

andreboscatto commented Mar 23, 2025

Need help with:

  • test_memcache__lookup_users_by_fully_qualified_names for all providers
FAILED tests/test_memcache.py::test_memcache__lookup_users_by_fully_qualified_names[with_fqdn] (ad) - AssertionError: 1 - user1@test should be found when use_fully_qualified_names is True
FAILED tests/test_memcache.py::test_memcache__lookup_users_by_fully_qualified_names[without_fqdn] (ad) - AssertionError: 3 - user1@test should be found when use_fully_qualified_names is False
  • test_memcache__lookup_user_membership_with_cache -> Samba and AD are failing
FAILED tests/test_memcache.py::test_memcache__lookup_user_membership_with_cache[by_group_name] (ad) - AssertionError: `user1` should be found
FAILED tests/test_memcache.py::test_memcache__lookup_user_membership_with_cache[by_group_id] (ad) - AssertionError: `user1` should be found
FAILED tests/test_memcache.py::test_memcache__lookup_user_membership_with_cache[by_group_name] (samba) - AssertionError: `user1` should be found
FAILED tests/test_memcache.py::test_memcache__lookup_user_membership_with_cache[by_group_id] (samba) - AssertionError: `user1` should be found
  • test_memcache__case_sensitivity_affects_cache_lookup -> Failing with LDAP and IPA for case sensitive = false
tests/test_memcache.py::test_memcache__case_sensitivity_affects_cache_lookup[case_insensitive] (ipa) FAILED
FAILED tests/test_memcache.py::test_memcache__case_sensitivity_affects_cache_lookup[case_insensitive] (ipa) - AssertionError: Group info should be cached regardless of case.
tests/test_memcache.py::test_memcache__case_sensitivity_affects_cache_lookup[case_insensitive] (ldap) FAILED
FAILED tests/test_memcache.py::test_memcache__case_sensitivity_affects_cache_lookup[case_insensitive] (ldap) - AssertionError: Group info should be cached regardless of case.

@andreboscatto andreboscatto added the Help wanted Extra attention is needed label Mar 23, 2025
@andreboscatto andreboscatto force-pushed the testMemcached branch 2 times, most recently from 8decb00 to 1391c5d Compare March 23, 2025 21:26
"""
SSSD In-Memory Cache (memcache) Test Cases.

:requirement: IDM-SSSD-REQ: Client side performance improvements

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

Copy link
Contributor Author

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?

Copy link

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@andreboscatto andreboscatto force-pushed the testMemcached branch 2 times, most recently from be9858f to 52665e0 Compare March 27, 2025 07:19
@andreboscatto andreboscatto force-pushed the testMemcached branch 2 times, most recently from c143bf1 to 14ba349 Compare March 29, 2025 08:30
@andreboscatto andreboscatto added Waiting for review and removed branch: sssd-2-9 Help wanted Extra attention is needed labels Mar 29, 2025
@andreboscatto andreboscatto marked this pull request as ready for review March 29, 2025 14:22
@andreboscatto andreboscatto force-pushed the testMemcached branch 2 times, most recently from 29b65f2 to 4b4241d Compare March 29, 2025 14:58
@alexey-tikhonov
Copy link
Member

All system tests are red, including some of tests being added.

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:
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@jakub-vavra-cz jakub-vavra-cz left a 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:
Copy link
Contributor

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.

Copy link
Contributor Author

@andreboscatto andreboscatto Apr 2, 2025

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?

@alexey-tikhonov
Copy link
Member

alexey-tikhonov commented Apr 2, 2025

https://github.com/SSSD/sssd/actions/runs/14217973656/job/39838952159?pr=7889

Found 4 errors in 1 file (checked 23 source files)

@andreboscatto
Copy link
Contributor Author

https://github.com/SSSD/sssd/actions/runs/14217973656/job/39838952159?pr=7889

Found 4 errors in 1 file (checked 23 source files)

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.

Refactored the entire memcache tests according to the new testing plan.
Improved the tests using parametrization. Removed redundant tests and
included the new ones.
Copy link
Contributor

@jakub-vavra-cz jakub-vavra-cz left a 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.

Comment on lines +59 to +72
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."
Copy link
Contributor

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"]?

  1. sssd is running and user and group is found.
  2. sssd is stopped with memcache and user and group is found.
  3. sssd is started again without memcache and user and group is found.
  4. 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.

@alexey-tikhonov
Copy link
Member

@andreboscatto, could you please rebase?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants