Skip to content

Remove max_length parameter from fetch - #1519

Merged
jku merged 2 commits into
theupdateframework:developfrom
sechkova:fetcher-max-length
Sep 1, 2021
Merged

jku merged 2 commits into
theupdateframework:developfrom
sechkova:fetcher-max-length

Conversation

@sechkova

Copy link
Copy Markdown
Contributor

Fixes #1502

Description of the changes being introduced by the pull request:

If a file has a bigger size than expected, RequestFetcher.fetch
downloads it up to max_length without any errors. Only the
consecutive hash check raises exception. A better behavior
in such case would be to raise a DownloadLengthMismatchError.

For this reason this PR:

  • removes max_length from the fetch() definition,
  • modifies download_file to check the downloaded length after
    each chunk and raise an error accordingly.

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@jku jku left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This breaks FetcherInterface API but the result looks like the API we should have made in the first place: it's a cleaner separation of duties and simplifies the fetcher implementation. LGTM in general.

Is it possible to make a test for the case you are fixing?

Comment thread tuf/ngclient/fetcher.py Resolved
@jku

jku commented Aug 17, 2021

Copy link
Copy Markdown
Member

Is it possible to make a test for the case you are fixing?

It would make sense to add tests for ngclient fetcher: not just the ones that already exist for fetcher in legacy code but for download_bytes() and download_file() -- where testing this issue would make sense

@sechkova
sechkova force-pushed the fetcher-max-length branch 2 times, most recently from b821f3c to 1846291 Compare August 27, 2021 11:13
@sechkova

Copy link
Copy Markdown
Contributor Author

Added some tests, mostly copied from test_fetcher.py but modified for the implementation. There's some duplication, maybe unneeded ...
Do we want to open another issue for testing the networking side of RequestsFetcher? I suppose we do.

@jku

jku commented Aug 27, 2021 •

Copy link
Copy Markdown
Member

Do we want to open another issue for testing the networking side of RequestsFetcher?

What do you mean specifically -- this PR seems to test the complete RequestsFetcher surface? Obviously more tests doesn't hurt but it looks like coverage wise we're ok.

@sechkova

Copy link
Copy Markdown
Contributor Author

What do you mean specifically -- this PR seems to test the complete RequestsFetcher surface? Obviously more tests doesn't hurt but it looks like coverage wise we're ok.

We still miss tests for urllib3.exceptions.ReadTimeoutError (and sleep but we want to remove it anyway) at least from the coverage report ... I should just add it to this PR

@sechkova

Copy link
Copy Markdown
Contributor Author

That's what I could do with the available test utils: 0f19815

@jku jku left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks fine otherwise but I refuse to accept a test that takes 5 seconds to run. I can accept either not testing slow retrieval here or making the test runtime more reasonable

@jku

jku commented Aug 30, 2021

Copy link
Copy Markdown
Member

Actually I do have a question: is it necessary to setup and teardown the server for each individual test?

@sechkova

Copy link
Copy Markdown
Contributor Author

Actually I do have a question: is it necessary to setup and teardown the server for each individual test?

Hmm ... no, I don't think so ... let me fix it.

@sechkova

sechkova commented Aug 30, 2021 •

Copy link
Copy Markdown
Contributor Author

This looks fine otherwise but I refuse to accept a test that takes 5 seconds to run. I can accept either not testing slow retrieval here or making the test runtime more reasonable

I was kind of expecting it 😁 I'll remove the test and open an issue so that we do it properly (maybe tweak the current slow_retreival_server.py)

Edit: my mistake, the timeout is a socket parameter, so tweak the socket timeouts: #1552

If a file has a bigger size than expected, RequestFetcher.fetch
downloads it up to max_length without any errors. Only the
consecutive hash check raises exception. A better behaviour
in such case would be to raise a DownloadLengthMismatchError.

For this reason this commit:
- removes max_length from the fetch() definition,
- modifies download_file to check the downloaded length after
  each chunk and raise an error accordingly.

Signed-off-by: Teodora Sechkova <[email protected]>
Add tests for the file/data download.

Signed-off-by: Teodora Sechkova <[email protected]>
@sechkova
sechkova force-pushed the fetcher-max-length branch from 0f19815 to 35ef056 Compare August 30, 2021 13:22
@sechkova

sechkova commented Aug 30, 2021 •

Copy link
Copy Markdown
Contributor Author

So test commits are squashed in a single one 35ef056:

I think the test setup can be further improved since the temp data file can be created once per class too but currently Modified_TestCase overrides setUp only and does not work in class methods.

@jku jku left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the Fetcher change is correct, and the tests look like a good basic set of tests for Fetcher/RequestsFetcher.

Both of the last two test changes independently improve the test runtime about 10x: that looks ok now.

@jku
jku merged commit deec2ea into theupdateframework:develop Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ngclient requestsfetcher result when length > max_length

2 participants