feat!: reuse TCP connection by default#49
Conversation
There was a problem hiding this comment.
Pull request overview
This PR changes the client’s default HTTP behavior to reuse TCP connections (persistent connections) without requiring explicit keep_alive: true, improving performance with reduced configuration.
Changes:
- Switch
Configuration#configuredefaultkeep_alivefromfalsetotrue. - Update specs to reflect the new default and validate adapter selection.
- Update README to reflect that connection reuse is enabled by default and simplify the
max_connectionsexample.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/incognia_api/configuration.rb | Changes default keep_alive to true, making persistent connections the default. |
| spec/incognia_spec.rb | Updates configuration specs to assert keep_alive defaults to true and adjusts the max_connections/keep_alive validation scenario. |
| spec/client_spec.rb | Adds a spec asserting the persistent adapter is selected by default. |
| README.md | Updates documentation to state connection reuse is enabled by default and removes keep_alive: true from the example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fdd151b to
7de4389
Compare
7de4389 to
64b91ec
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
lib/incognia_api.rb:38
format_messagecan returnnilwhenerrorsisnilbecause the conditional append is the last expression in the method. That makesAPIError#message/to_spotentiallynilfor cases like timeouts (whereresponse_infois{}), which is surprising and can break consumers expecting a string. Consider explicitly returningmessageat the end offormat_message(or usingtap) so it always returns a String.
def initialize(message, response_info = {})
response_info ||= {}
@status = response_info[:status]
@errors = response_info[:body]
@message = format_message(message)
end
There was a problem hiding this comment.
Can you bump the version, update the lock, and CHANGELOG, please?
https://github.com/inloco/incognia-ruby#development
update the version number in version.rb, run bundle to update the gemfile.lock, add one description on CHANGELOG.md if necessary
| def initialize(message, response_info = {}) | ||
| response_info ||= {} |
There was a problem hiding this comment.
Was it sent as null?
As you're already treating nil, we can change the default to be nil, wdyt?
| def initialize(message, response_info = {}) | |
| response_info ||= {} | |
| def initialize(message, response_info = nil) | |
| response_info ||= {} |
| attr_accessor :client_id, :client_secret, :host, :keep_alive, :max_connections | ||
|
|
||
| def configure(client_id:, client_secret:, host: nil, keep_alive: false, max_connections: nil) | ||
| def configure(client_id:, client_secret:, host: nil, keep_alive: true, max_connections: nil) |
There was a problem hiding this comment.
Is it a breaking change, or is it okay to assume it as the default?
I'm asking so we can decide about the version.
| host: 'https://api.incognia.com/api' | ||
| ) | ||
|
|
||
| allow_any_instance_of(Faraday::RackBuilder).to receive(:adapter).and_call_original |
There was a problem hiding this comment.
Why did we need to mock it before the expect_any_instance_of? Does it have another call, with different params?
Change TCP connection reuse to be default behavior so that clients have better performance with less configuration.