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

Add tests for D&O merge strategy #638

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

Conversation

averevki
Copy link
Contributor

Refined part of #608 with merge strategy tests only

Closes #566

@averevki averevki added the Test case New test case label Feb 18, 2025
@averevki averevki self-assigned this Feb 18, 2025
raise TypeError("Strategy can only be set on defaults or overrides")

self.spec_section["strategy"] = strategy.value
self.spec_section = None
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the purpose of setting it to None here?

@@ -0,0 +1,27 @@
"""Test defaults policy aimed at the same resoure uses oldested policy."""
Copy link
Contributor

Choose a reason for hiding this comment

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

resoure / oldested - typos?

@@ -0,0 +1,27 @@
"""Test defaults policy aimed at the same resoure uses oldested policy."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Typos here too

@@ -0,0 +1,51 @@
"""Test gateway level default merging with and being patrially overriden by another policy."""
Copy link
Contributor

Choose a reason for hiding this comment

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

*partially overridden

raise TypeError("Strategy can only be set on defaults or overrides")

self.spec_section["strategy"] = strategy.value
self.spec_section = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Same again, unclear to me why there is this "None" assignment


def test_multiple_policies_merge_default_ab(client):
"""Test RateLimitPolicy with merge defaults being ignored due to age"""
responses = client.get_many("/get", MERGE_LIMIT.limit)
Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest I think that the comments need to be swapped between test_ab_strategy and test_ba_strategy. If I got it right "a" means standard policy and "b" means policy with merge defaults.

So in "ab" the "a" policy is created first, and once "b" is created the "a" gets overridden - you can see it in test that "MERGE_LIMIT" is used for both get_many calls. However, the comment in "ab" suggests that "b" is ignored which is not true - it is true in the "ba" test where the policies are created in different order.

Copy link
Contributor

Choose a reason for hiding this comment

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

I decrypted the policy names.
dmp means policy with defauls section and merge strategy (defaults merge policy)
sp means standard policy === policy without both defaults and overrides sections
omp means policy with overrides section and merge strategy (overrides merge policy)



def test_multiple_policies_merge_default_ab(client):
"""Test RateLimitPolicy with merge overrides being ignored due to age"""
Copy link
Contributor

Choose a reason for hiding this comment

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

The RateLimitPolicy with merge overrides is not ignored. On the contrary it is fully enforced

Copy link
Contributor

Choose a reason for hiding this comment

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

What is also weird is the fact that "ab" and "ba" strategy are the same, ie the order of creation of the polices does not matter, in both cases the "b" (one with overrides section and merge strategy) is fully enforced and "a" is overridden.
Not sure if this is expected behavior or not.

@trepel
Copy link
Contributor

trepel commented Mar 6, 2025

I don't like two additional things:

  1. In the bodies of test functions the policy status is not asserted (whether policy is indeed overridden/fully and/or partially enforced).
  2. The commit fixture is overloaded so that it only check for policy acceptance. I think (this is philosophical and up to wider discussion maybe) that it is better if commit fixture only deals with policies that are fully enforced (I consider this as initial test setup fixtures should be responsible for because that is what they are designed for) and policies that are overridden/partially enforced (or causes some existing policies to get overridden/partially enforced) should be created in test function bodies (I consider this test scenario rather that initial test setup so it does not belong to fixtures anymore).

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

Successfully merging this pull request may close these issues.

Defaults & Overrides: Merge strategy tests
2 participants