-
Notifications
You must be signed in to change notification settings - Fork 332
fix(auth): Make auth client respect app options httpTimeout #536
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
Conversation
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.
Thanks for the PR @daniellehanks. Looks pretty good to me. One suggestion on tests, but we can merge without that change too. Let me know what you think.
assert len(recorder) == 1 | ||
req = recorder[0] | ||
assert req.method == 'POST' | ||
assert req.url == '{0}{1}'.format(USER_MGT_URL_PREFIX, want_url) | ||
if want_body: | ||
body = json.loads(req.body.decode()) | ||
assert body == want_body | ||
if want_timeout: | ||
assert recorder[0]._extra_kwargs['timeout'] == pytest.approx(want_timeout, 0.001) |
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.
Should we add the following assertion?
timeout_arg = recorder[0]._extra_kwargs['timeout']
if want_timeout:
assert timeout_arg == pytest.approx(want_timeout, 0.01)
else:
assert timeout_arg == pytest.approx(_http_client.DEFAULT_TIMEOUT, 0.01)
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 problem I see with that is it would force any test not using the default to pass that argument. I aligned with the other want
args, if it's specified, check it, otherwise don't. That said, it's your code base so I defer to you. Lmk if you want me to change 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.
The problem I see with that is it would force any test not using the default to pass that argument.
It doesn't. It can default to None
, in which case we assert against _http_client.DEFAULT_TIMEOUT
.
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.
That's what I'm saying, if someone added a test using user_mgt_app_with_timeout
, but didn't pass a timeout to this function (presumably because they didn't care about asserting the value), it would fail.
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.
In the implementation we already default the client to _http_client.DEFAULT_TIMEOUT
. In what scenario do we expect that assertion to not hold?
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.
If an app is used with a non-default timeout, but someone is either unaware of the want_timeout
parameter or explicitly does not wish to make an assertion around it. Just biasing towards explicit > implicit per BDFL. Implementing the suggested behavior would implicitly check timeout. It also adds assertions to existing tests, whereas the original implementation results in no change to existing tests/assertions.
For a concrete example, if I removed the TEST_TIMEOUT
from test_get_user_with_timeout
, the test would fail, but, IMO, it would not be readily obvious just inspecting the test function why (nowhere did I make an assertion or ask an assertion to be made around timeout, so why is that happening?).
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.
It also adds assertions to existing tests, whereas the original implementation results in no change to existing tests/assertions.
That was my intended goal. Ideally, the _check_request()
helper function should make assertions about the traits that are common to all requests made by the auth client. We probably should have had the timeout assertion there to begin with. The want_body
shouldn't be an optional argument. It's always specified.
Anyway, all these changes can probably be lumped into a separate PR. For now I'm happy with where this stands.
#535
This takes care of half of the above ticket, the other half being to specify a timeout on the http transport given to google.oauth2.id_token.verify_token().
I tried to stay locally consistent and tried not to change the test setup too much.