Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-04-28 18:14:51 -0400 using RuboCop version 0.35.0.
# on 2017-04-30 12:02:22 -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 @@ -80,6 +80,12 @@ Style/MultilineTernaryOperator:
Exclude:
- 'spec/support/real_time/connected_client.rb'

# Offense count: 1
# Cop supports --auto-correct.
Style/RescueModifier:
Exclude:
- 'lib/slack/real_time/concurrency/celluloid.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/SpecialGlobalVars:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.9.0 (Next)

* [#146](https://github.com/slack-ruby/slack-ruby-client/issues/146): Fix: `undefined method running?` and `ThreadError: Target thread must not be current thread` with `Celluloid::IO` - [@dblock](https://github.com/dblock).
* [#145](https://github.com/slack-ruby/slack-ruby-client/pull/145): Automatically select `rtm_connect` vs. `rtm_start` - [@dblock](https://github.com/dblock).
* Your contribution here.

Expand Down
6 changes: 3 additions & 3 deletions lib/slack/real_time/concurrency/celluloid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run_loop
logger.debug("#{self.class}##{__method__}") { e }
driver.emit(:close, WebSocket::Driver::CloseEvent.new(1001, 'server closed connection')) unless @closing
ensure
current_actor.terminate if current_actor.alive? && current_actor.running?
current_actor.terminate if current_actor.alive? rescue nil
end

def close
Expand Down Expand Up @@ -90,8 +90,8 @@ def join
end

def build_socket
socket = TCPSocket.new(addr, port)
socket = SSLSocket.new(socket, build_ssl_context) if secure?
socket = ::Celluloid::IO::TCPSocket.new(addr, port)
socket = ::Celluloid::IO::SSLSocket.new(socket, build_ssl_context) if secure?
socket
end

Expand Down
31 changes: 26 additions & 5 deletions spec/slack/real_time/concurrency/celluloid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,41 @@
context 'with url' do
let(:url) { 'wss://echo.websocket.org/websocket/xyz' }
let(:logger) { ::Logger.new(STDOUT) }
subject(:socket) { described_class.new(url, ping: 42, logger: logger) }
let(:test_socket) do
Class.new(described_class) do
def read
fail EOFError
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

describe '#disconnect!' do
it 'closes and nils the websocket' do
context 'with a driver' do
before do
socket.instance_variable_set('@driver', ws)
expect(ws).to receive(:close)
socket.disconnect!
end

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

describe '#run_loop' do
it 'runs' do
expect(ws).to receive(:emit)
expect(ws).to receive(:start)
socket.run_loop
end
end
end

Expand Down