Skip to content

Allow user to set a request timeout - #178

Merged
ShariqT merged 1 commit into
lob:masterfrom
Kilo59:timeouts
Jan 25, 2022
Merged

Allow user to set a request timeout#178
ShariqT merged 1 commit into
lob:masterfrom
Kilo59:timeouts

Conversation

@Kilo59

@Kilo59 Kilo59 commented Oct 28, 2021

Copy link
Copy Markdown
Contributor

Fixes #162

TODO

@Kilo59
Kilo59 marked this pull request as ready for review January 19, 2022 19:50
@ShariqT ShariqT added Approved and removed Approved labels Jan 20, 2022
@ShariqT ShariqT added Approved and removed Approved labels Jan 20, 2022
Comment thread lob/api_requestor.py Outdated
timeout=timeout
)
return self.parse_response(resp)
except requests.exceptions.Timeout:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think we should be catching and re-raising a custom Timeout exception.
Just let the request Timeout bubble up.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was having trouble creating a test for this. The requests_mock package doesn't trigger timeouts when you do a slowed down response using time.sleep. You can raise a requests.exception with the mock, but our library doesn't really take any action based on that exception. I figured since we are using timeout as one of the parameters that we are passing in now, we could have our custom exception for our library. And its easier to test, since our library does some action based on the exception.

@Kilo59 Kilo59 Jan 20, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't need to use time.sleep, requests-mock has a dedicated method of simulating timeouts.
https://requests-mock.readthedocs.io/en/latest/response.html#raising-exceptions.

I can try to set this up as a pytest fixture so it's easy to use/re-use in our tests.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Kilo59 I'm gonna try a different approach and see if I intercept the http request and supply my own response function. If that doesn't work, I'll see if I can put spy to make sure that we are passing down the timeout value.

@@ -0,0 +1,25 @@
name: Run tests from Forked Repo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ShariqT nice work.
I totally forgot about this problem.

@ShariqT ShariqT removed the Approved label Jan 21, 2022
Comment thread lob/constants.py
@@ -0,0 +1 @@
TIMEOUT_DEFAULT = 30

@Kilo59 Kilo59 Jan 24, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would assume 30 seconds it a reasonable default. Still seems hight to me but much better than never/infinite.

@ShariqT
ShariqT merged commit 99c3465 into lob:master Jan 25, 2022
@Kilo59
Kilo59 deleted the timeouts branch January 25, 2022 16:32
@ShariqT ShariqT mentioned this pull request Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Is there a way to specify a timeout for requests?

4 participants