-
Notifications
You must be signed in to change notification settings - Fork 22
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
⚡ [#4229] Cache KVKRemoteValidator result to speed up validation #4244
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4244 +/- ##
==========================================
+ Coverage 96.14% 96.15% +0.01%
==========================================
Files 732 733 +1
Lines 23501 23538 +37
Branches 2752 2760 +8
==========================================
+ Hits 22596 22634 +38
Misses 639 639
+ Partials 266 265 -1 ☔ View full report in Codecov by Sentry. |
@sergei-maertens I just saw #4239 where you update the translation stuff as well, if I should remove my commit that does the same, let me know |
Yeah I made that PR so that I could set up this template, so please undo that commit 😬 I had hoped someone would have reviewed my PR by now :( |
@@ -49,6 +50,7 @@ def test_invalid_branchNumber(self): | |||
validate_branchNumber("11223-445566") | |||
|
|||
|
|||
@freeze_time("2024-01-01T12:00:00") |
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 think I'd prefer a separate test for the caching with this decorator applied, rather than updating an existing test. Decorating the entire test case wasn't needed before, so this incorrectly makes it look like it is.
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 moved them to separate tests
with self.subTest("caching KVK result"): | ||
self.cassette.rewind() | ||
|
||
validator("69599084") | ||
|
||
# No request has been made because the result was cached | ||
self.assertEqual(self.cassette.play_count, 0) | ||
|
||
with freeze_time("2024-01-01T12:01:01"): | ||
validator("69599084") | ||
|
||
# Request is made, because cached result is timed out | ||
self.assertEqual(self.cassette.play_count, 1) |
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.
as mentioned above, let's move this into its own test: def test_kvk_lookups_are_cached(self):
I'd also test that doing a call with a different RSIN does create a new request (this tests that the argument is part of the cache key)
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.
added checks for requests with different KVK/RSIN/branchnumber
@@ -12,6 +14,8 @@ | |||
|
|||
from .client import NoServiceConfigured, SearchParams, get_kvk_search_client | |||
|
|||
KVK_LOOKUP_CACHE_TIMEOUT = 60 |
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 think we can go for 5 minutes easily :)
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.
changed it to 5 mins
513de95
to
ab9a5b5
Compare
ab9a5b5
to
40b184b
Compare
def setUp(self) -> None: | ||
super().setUp() | ||
|
||
clear_caches() |
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.
def setUp(self) -> None: | |
super().setUp() | |
clear_caches() | |
def setUp(self) -> None: | |
super().setUp() | |
clear_caches() | |
self.addCleanup(clear_caches) |
this ensures that after a test, the cache is cleared too
status: | ||
code: 200 | ||
message: '' | ||
- request: |
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 request seems to be duplicated, it's the same as the one before, I think it's because of a particular VCR record mode that just records them again even though they're already present.
Probably best to just delete the cassettes and run the tests again :)
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.
Ah okay, I didn't know you had to delete them if you record new cassettes 👍
40b184b
to
01eed37
Compare
@@ -119,3 +123,107 @@ def test_branchNumber_validator(self): | |||
ValidationError, _("Expected a numerical value.") | |||
): | |||
validator("bork") | |||
|
|||
|
|||
class KvKRemoteValidatorCachingTestCase(KVKTestMixin, SimpleTestCase): |
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.
@stevenbal I ran into test failures with VCR in either of two modes:
- Re-recording the cassettes - the
play_count
is always set to zero because it's still building the cassette - Replaying the cassettess - the
self.cassette.requests
size reports all the known interactions, and is fine when re-recording the cassettes because it's still building up the history.
There's no obvious way to make checks on which requests were made and how often with VCR, so instead I opted for requests-mock here with a dummy response to check the number of outgoing requests made at any given point.
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.
Hmm alright, I wasn't sure about the VCR approach for the caching assertions either, so this is probably the best way to fix it
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.
yeah this didn't feel very "exact" when to use which approach to me either
and add cassette for valid RSIN
01eed37
to
4687b58
Compare
Closes #4229
Changes
Checklist
Check off the items that are completed or not relevant.
Impact on features
Release management
I have updated the translations assets (you do NOT need to provide translations)
./bin/makemessages.sh
./bin/compilemessages_js.sh
Commit hygiene