Skip to content

Commit

Permalink
Capture the wider SystemCallError, including broken pipe.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Oskarsson authored and dblock committed Sep 18, 2017
1 parent 385b30b commit 1a68e2b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-09-13 09:10:02 +0200 using RuboCop version 0.35.0.
# on 2017-09-18 13:40:11 -0400 using RuboCop version 0.35.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -33,7 +33,7 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 9

# Offense count: 615
# Offense count: 616
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 266
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

* [#163](https://github.com/slack-ruby/slack-ruby-client/pull/164): Use `OpenSSL::X509::DEFAULT_CERT_DIR` and `OpenSSL::X509::DEFAULT_CERT_FILE` for default ca_cert and ca_file - [@leifcr](https://github.com/leifcr).
* [#161](https://github.com/slack-ruby/slack-ruby-client/pull/161): Added support for cursor pagination - [@dblock](https://github.com/dblock).
* [#162](https://github.com/slack-ruby/slack-ruby-client/pull/162): Gracefully close websocket on `Errno::EPIPE` - [@johanoskarsson](https://github.com/johanoskarsson).
* Your contribution here.

### 0.9.1 (8/24/2017)
Expand Down
2 changes: 1 addition & 1 deletion lib/slack/real_time/concurrency/celluloid.rb
Expand Up @@ -34,7 +34,7 @@ def run_loop
@connected = @socket.connect
driver.start
loop { read } if socket
rescue EOFError => e
rescue EOFError, Errno::EPIPE => e
logger.debug("#{self.class}##{__method__}") { e }
driver.emit(:close, WebSocket::Driver::CloseEvent.new(1001, 'server closed connection')) unless @closing
ensure
Expand Down
72 changes: 41 additions & 31 deletions spec/slack/real_time/concurrency/celluloid_spec.rb
Expand Up @@ -7,45 +7,55 @@
context 'with url' do
let(:url) { 'wss://echo.websocket.org/websocket/xyz' }
let(:logger) { ::Logger.new(STDOUT) }
let(:test_socket) do
Class.new(described_class) do
def read
fail EOFError

[EOFError, Errno::EPIPE].each do |err|
context "finishing run_loop with #{err}" do
let(:test_socket) do
Class.new(described_class) do
def read
fail options[:err]
end
end
end
end
end
let(:socket) { test_socket.new(url, ping: 42, logger: logger) }
let(:driver) { WebSocket::Driver::Client }
let(:ws) { double(driver) }
subject { socket }

describe '#connect!' do
pending 'connects'
pending 'pings every 30s'
end

context 'with a driver' do
before do
socket.instance_variable_set('@driver', ws)
end
let(:socket) do
test_socket.new(url, ping: 42, logger: logger, err: err)
end

describe '#disconnect!' do
it 'closes and nils the websocket' do
expect(ws).to receive(:close)
socket.disconnect!
let(:driver) { WebSocket::Driver::Client }
let(:ws) { double(driver) }
subject { socket }

describe '#connect!' do
pending 'connects'
pending 'pings every 30s'
end
end

describe '#run_loop' do
it 'runs' do
expect(ws).to receive(:emit)
expect(ws).to receive(:start)
socket.run_loop
context 'with a driver' do
before do
socket.instance_variable_set('@driver', ws)
end

describe '#disconnect!' do
it 'closes and nils the websocket' do
expect(ws).to receive(:close)
socket.disconnect!
end
end

context 'consumes data' do
it 'runs' do
expect(ws).to receive(:emit)
expect(ws).to receive(:start)
expect(logger).to receive(:debug).with("#{test_socket}#run_loop")
socket.run_loop
end
end
end

pending 'send_data'
end
end

pending 'send_data'
end
end
rescue LoadError
Expand Down

0 comments on commit 1a68e2b

Please sign in to comment.