-
Notifications
You must be signed in to change notification settings - Fork 278
Test expired metadata from cache #1707
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
Test expired metadata from cache #1707
Conversation
I'm leaving this with the non-matching description on purpose, as the expected behaviour in |
Pull Request Test Coverage Report for Build 1865335270Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
I have some ideas about this pr and will have a conversation with Ivana soon. |
This may have been clarified already but I'l say it here: We do load expired metadata with one big caveat: the expired metadata can only be used to validate a newer version of the same type of metadata. In practice:
|
8bd6065
to
c86ad65
Compare
the core issue here is that verifying that local files are opened does not mean they are actually used to verify new downloaded metadata (this is made clear even in the test itself: it opens Just to be clear: I think this is a useful test that probably does not exist yet... but test_updater_top_level_update.py has some clearly related tests like Also (and this is a small detail in comparison), I've been trying to advocate not meddling with the client metadata cache manually: in this case I think it would be better to not do that and instead mock current time (pretend that time now > expiry). Search for mock_time in tests for examples of this. |
7b15487
to
e12a4a6
Compare
I admit I find it hard to follow the intentions here, I am sorry if I've put a misleading issue description. |
@sechkova the idea was to simulate an expired metadata in cache without manually modifying the cache files. I might have misunderstood this mock - the intention is to simulate change in system time, so that what's stored in cache is considered expired, without need of directly touching the local metadata. |
It is pretty similar, except that I think we don't actually persist downloaded non-root metadata if it's expired, even though we probably could (rado pointed this out to me -- I had not noticed). This difference isn't that important for actual working repos but for testing it means we need to mock system time (or utcnow() as you point out) to "make the local metadata expired". |
Thanks, now I think I got all pieces together. So I agree, |
ef136d4
to
ae0ee2e
Compare
I'm marking this a draft since the issue pointed out by Teodora (mocking the wrong thing) is still there: I might have other comments but I've been postponing review until the basics are there. I'm available for a chat if anything is unclear. |
ae0ee2e
to
7e56b0c
Compare
@jku I changed to mocking |
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.
marking request changes so it's visible on PR list: we talked about this over zoom, and found an issue with the timeline of expiries and the mocked refresh: ivana promised to fix
ba6ef64
to
ed0d0b8
Compare
I've pushed an update. |
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.
Nice, all test code seems correct and clear.
- Left some minor tweak suggestions in code
- These tests should have a docstring to explain what they are testing: they are some of the trickiest tests we have. Something like "Local timestamp must be used in rollback checks even if it is expired" -- maybe the same text that's already before the actual assertRaises
Additionally maybe the dosctring should also include a timeline, example of one test:
* day 0: first updater refresh
* day 0 (a bit later): repository publishes timestamp v2
* day 7: timestamp v1 expiry
* day 18: second updater refresh: assert that rollback check uses expired v1 here
* day 21: timestamp v2 expiry
not sure about that last thing though: it's a lot of lines... but may be helpful to understand what's going on? I'll leave decision to you
This tests that an expired timestamp/snapshot/targets when loaded from cache is not stored as final but is used to verify the new timestamp Fixes theupdateframework#1681 Signed-off-by: Ivana Atanasova <[email protected]>
This change verifies that when local metadata has expired, it is still used to verify new metadata that's pulled from remote Signed-off-by: Ivana Atanasova <[email protected]>
This change fixes the expired metadata tests to mock `datetime` as previously they mocked `time` incorrectly, which did not affect update methods, as they use `datetime.datetime.utcnow()` to calculate now Signed-off-by: Ivana Atanasova <[email protected]>
ed0d0b8
to
0f6c961
Compare
This change improves the logic of expired metadata tests, so that it is explicitly visible what the expiry time and the versions are and when update/refresh is called in that period Signed-off-by: Ivana Atanasova <[email protected]>
0f6c961
to
8d4d9af
Compare
Thank you @jku , I added docstrings to all the test methods for clarification. |
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.
my comment about reusing the datetime.datetime.utcnow()
result is marked resolved but all functions still call utcnow() twice...
That is a trivial complaint so let's go with this version, I think it's a good set of very tricky tests. Thanks.
@jku ah, I resolved by inertia with the microseconds updates... will note to address in following changes. Thanks |
This tests that an expired timestamp/snapshot/targets when loaded
from cache is not stored as final but is used to verify the new
timestamp
Addresses #1681