-
Notifications
You must be signed in to change notification settings - Fork 278
Test loading of cached metadata in ngclient #1703
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 loading of cached metadata in ngclient #1703
Conversation
Pull Request Test Coverage Report for Build 1653759271Warning: 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 |
6d00db6
to
bd17789
Compare
@jku I addressed your comment, if something is not very correct I'll edit it. (It doesn't cover if the loaded timestamp is used to verify the new timestamp, but AFAIR it's already covered and we wanted to check only what's loaded from disk.) Thanks @kairoaraujo . With the latest change I don't check |
Could you please rebase on top of develop? |
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.
Yes, this looks ok. Left some comments on get_targetinfo() calls: please fix those.
Since you are already modifying I'll leave another nitpick: can you double check that comments and commit messages do not claim to do something that isn't done: at least one comment says "Test that timestamp, snaphot and targets are ... not downloaded" which is not true. The test only checks that local files are opened in the expected way (and that's fine, this is useful and would have caught a past issue we had).
There is a potential follow-up for
- adding a delegated target to repository (se the test can check that delegated target is also correctly loaded from local disk)
- separately testing constructor, refresh() and get_targetinfo()
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 added some comments to the code but then realized, this test does not prove much. Updater always tries to load metadata from cache. There will always be calls to open even if there are no cached files. If this is what we want to demonstrate, ok. Then we are testing that "Updater always tries to read the cache before downloading metadata" and a single call to "refresh" is enough. The whole test would be:
updater = self._run_refresh()
wrapped_open.assert_has_calls([
call(os.path.join(self.metadata_dir, "root.json"), "rb"),
call(os.path.join(self.metadata_dir, "timestamp.json"), "rb"),
call(os.path.join(self.metadata_dir, "snapshot.json"), "rb"),
call(os.path.join(self.metadata_dir, "targets.json"), "rb"),
])
Probably a way to show that it opened and used the cached metadata is to show that when cached metadata is loaded from the file system successfully, there are no calls to RepositorySimulator.fetch_metadata for snapshot and targets. This should be easier now, after the addition of RepositorySimulator.fetch_counters. "Usage" of local (intermediate) root is described in the spec and should have be covered in test_top_level_update.py. Timestamp is a special case that can be tested in another set of tests covering invalid metadata.
The test is not really consistent. It randomly calls _run_refresh
and get_targetinfo
.
In case it is not clear, the options are either:
- Test only top-level roles metadata
- create a new updater, call updater.refresh to get the metadata locally
- reset the mock
- create a new updater, call updater.refresh a second time to get the metadata loaded from the local cache dir
- check the calls to open, check the calls to RepositorySimulator.fetch_tracker.metadata
Then as Jussi suggests, add delegations as follow up.
- Test both top-level metadata and a delegated role
- add a delegated role to simulator, there is an example in
self.sim.add_delegation( - create a new updater, call updater.get_targetinfo("non_existent_target") to get the metadata locally, delegated role included
- reset the mock
- create a new updater, call updater.get_targetinfo("non_existent_target") a second time to get the metadata loaded from the local cache dir
- check the the calls to open, check the calls to RepositorySimulator.fetch_tracker.metadata
46c5731
to
a7e9c67
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.
The test makes sense to me now, thanks for updating it. Some minor comments still but it looks ok to me.
a7e9c67
to
ab47dda
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.
LGTM: @sechkova all yours to merge when you're happy
ab47dda
to
e1b42f4
Compare
@jku GH seems to believe you're still requesting changes and I cannot merge without your approval. |
e1b42f4
to
c96b488
Compare
Sorry Ivana, I just made your life a bit harder by merging Teodoras test move. Could you rebase? (test looks really nice btw) |
After making a successful update of valid metadata which stores it in cache and performing a second update with a new updater while the metadata is already stored in cache, this test verifies that timestamp, snaphot and targets are loaded from cache and not downloaded Fixes theupdateframework#1681 Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
c96b488
to
d27c0fd
Compare
@jku it's fine, I migrated it to |
After making a successful update of valid metadata which stores it
in cache and performing a second update with a new updater while
the metadata is already stored in cache, this test verifies that
timestamp, snaphot and targets are loaded from cache and not
downloaded
Addresses #1681
Signed-off-by: Ivana Atanasova iyovcheva@vmware.com