Skip to content
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

Add --timeout and --connection-timeout options #128

Merged
merged 3 commits into from
Dec 10, 2019

Conversation

smaeda-ks
Copy link
Collaborator

Problem

#36

Twurl currently doesn't have a way to override the default timeout values of the Net::HTTP Class. The default values are:

Solution

Introduce new options below:

  • --timeout [sec]
  • --connection-timeout [sec]

Result

Usage output

$ bundle exec twurl
Usage: twurl authorize --consumer-key key --consumer-secret secret
       twurl [options] /1.1/statuses/home_timeline.json

Supported Commands: accounts, alias, authorize, set

Getting started:
    -T, --tutorial                   Narrative overview of how to get started using Twurl

Authorization options:
    -u, --username [username]        Username of account to authorize (required)
    -p, --password [password]        Password of account to authorize (required)
    -c, --consumer-key [key]         Your consumer key (required)
    -s, --consumer-secret [secret]   Your consumer secret (required)
    -a, --access-token [token]       Your access token
    -S, --token-secret [secret]      Your token secret

Common options:
    -t, --[no-]trace                 Trace request/response traffic (default: --no-trace)
    -d, --data [data]                Sends the specified data in a POST request to the HTTP server.
    -r, --raw-data [data]            Sends the specified data as it is in a POST request to the HTTP server.
    -A, --header [header]            Adds the specified header to the request to the HTTP server.
    -H, --host [host]                Specify host to make requests to (default: api.twitter.com)
    -q, --quiet                      Suppress all output (default: output is printed to STDOUT)
    -U, --no-ssl                     Disable SSL (default: SSL is enabled)
    -X, --request-method [method]    Request method (default: GET)
    -P, --proxy [proxy]              Specify HTTP proxy to forward requests to (default: No proxy)
    -f, --file [path_to_file]        Specify the path to the file to upload
    -F, --file-field [field_name]    Specify the POST parameter name for the file upload data (default: media)
    -b, --base64                     Encode the uploaded file as base64 (default: false)
        --timeout [sec]              Number of seconds to wait for the request to be read (default: 60)
        --connection-timeout [sec]   Number of seconds to wait for the connection to open (default: 60)
    -h, --help                       Show this message
    -v, --version                    Show version

Actual test (using https://httpbin.org/#/Dynamic_data/get_delay__delay_)

$ time bundle exec twurl --timeout 5 -H httpbin.org "/delay/10"
Traceback (most recent call last):
        22: from /home/hoge/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `<main>'
        21: from /home/hoge/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `eval'
        20: from /home/hoge/.rvm/gems/ruby-2.6.5/bin/twurl:23:in `<main>'
        19: from /home/hoge/.rvm/gems/ruby-2.6.5/bin/twurl:23:in `load'
        18: from /home/hoge/Develop/GitHub/twurl/bin/twurl:4:in `<top (required)>'
        17: from /home/hoge/Develop/GitHub/twurl/lib/twurl/cli.rb:21:in `run'
        16: from /home/hoge/Develop/GitHub/twurl/lib/twurl/cli.rb:38:in `dispatch'
        15: from /home/hoge/Develop/GitHub/twurl/lib/twurl/abstract_command_controller.rb:7:in `dispatch'
        14: from /home/hoge/Develop/GitHub/twurl/lib/twurl/request_controller.rb:9:in `dispatch'
        13: from /home/hoge/Develop/GitHub/twurl/lib/twurl/request_controller.rb:13:in `perform_request'
        12: from /home/hoge/Develop/GitHub/twurl/lib/twurl/oauth_client.rb:128:in `perform_request_from_options'
        11: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http.rb:1470:in `request'
        10: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http.rb:920:in `start'
         9: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http.rb:1472:in `block in request'
         8: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http.rb:1479:in `request'
         7: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http.rb:1506:in `transport_request'
         6: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http.rb:1506:in `catch'
         5: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http.rb:1509:in `block in transport_request'
         4: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http/response.rb:29:in `read_new'
         3: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/http/response.rb:40:in `read_status_line'
         2: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/protocol.rb:201:in `readline'
         1: from /home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/protocol.rb:191:in `readuntil'
/home/hoge/.rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/net/protocol.rb:217:in `rbuf_fill': Net::ReadTimeout with #<TCPSocket:(closed)> (Net::ReadTimeout)

real    0m6.279s
user    0m0.513s
sys     0m0.084s

@smaeda-ks smaeda-ks requested a review from a team December 9, 2019 14:53
@smaeda-ks smaeda-ks self-assigned this Dec 9, 2019
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 88.491% when pulling f8c5c77 on smaeda-ks:smaeda-ks/timeout-options into c872a7d on twitter:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 88.491% when pulling f8c5c77 on smaeda-ks:smaeda-ks/timeout-options into c872a7d on twitter:master.

@coveralls
Copy link

coveralls commented Dec 9, 2019

Coverage Status

Coverage increased (+0.2%) to 88.501% when pulling b22bd20 on smaeda-ks:smaeda-ks/timeout-options into c872a7d on twitter:master.

@smaeda-ks smaeda-ks force-pushed the smaeda-ks/timeout-options branch from fe9d7b9 to d2b4884 Compare December 9, 2019 15:27
@smaeda-ks smaeda-ks added this to the Target v0.9.4 milestone Dec 9, 2019
Since the Minitest run tests concurrently, sometimes the "DispatchWithOneAuthorizedAccountTest" class runs after the "DispatchWithOneUsernameThatHasAuthorizedMultipleAccountsTest" run. In this case, "Twurl::OAuthClient.rcfile" has multiple profiles data in there and hence it fails with its mock checks.
@smaeda-ks smaeda-ks force-pushed the smaeda-ks/timeout-options branch from 58eadc3 to b22bd20 Compare December 9, 2019 19:08
Copy link
Contributor

@andypiper andypiper left a comment

Choose a reason for hiding this comment

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

Ship it!

@smaeda-ks smaeda-ks merged commit ded1136 into twitter:master Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants