Skip to content

Commit

Permalink
Stop ping on inactive_account and invalid_auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Dec 23, 2019
1 parent 2692773 commit 614665f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 139 deletions.
159 changes: 22 additions & 137 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,143 +1,56 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000`
# on 2019-08-20 22:22:29 -0700 using RuboCop version 0.73.0.
# `rubocop --auto-gen-config`
# on 2019-12-23 15:50:03 -0500 using RuboCop version 0.73.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
# versions of RuboCop, may require this file to be generated again.

# Offense count: 5
# Offense count: 3
# Configuration parameters: AllowComments.
Lint/HandleExceptions:
Exclude:
- 'lib/slack/real_time/concurrency/async.rb'
- 'lib/slack_ruby_client.rb'
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'

# Offense count: 9
# Configuration parameters: Max.
# Offense count: 10
Metrics/AbcSize:
Exclude:
- 'lib/slack/real_time/client.rb'
- 'lib/slack/real_time/concurrency/async.rb'
- 'lib/slack/real_time/stores/store.rb'
- 'lib/slack/web/api/mixins/users.search.rb'
- 'lib/slack/web/faraday/connection.rb'
- 'lib/slack/web/pagination/cursor.rb'
- 'spec/integration/integration_spec.rb'
Max: 39

# Offense count: 1
# Configuration parameters: Max.
Metrics/CyclomaticComplexity:
Exclude:
- 'lib/slack/web/faraday/connection.rb'
Max: 9

# Offense count: 13
# Configuration parameters: CountComments, Max, ExcludedMethods.
# Offense count: 14
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Exclude:
- 'lib/slack/messages/formatting.rb'
- 'lib/slack/real_time/client.rb'
- 'lib/slack/real_time/concurrency/async.rb'
- 'lib/slack/real_time/concurrency/celluloid.rb'
- 'lib/slack/real_time/config.rb'
- 'lib/slack/real_time/stores/store.rb'
- 'lib/slack/web/api/mixins/users.search.rb'
- 'lib/slack/web/config.rb'
- 'lib/slack/web/faraday/connection.rb'
- 'lib/slack/web/faraday/request.rb'
- 'lib/slack/web/pagination/cursor.rb'
- 'spec/integration/integration_spec.rb'
Max: 32

# Offense count: 1
# Configuration parameters: Max.
Metrics/PerceivedComplexity:
Exclude:
- 'lib/slack/web/faraday/connection.rb'
Max: 9

# Offense count: 1
RSpec/AnyInstance:
Exclude:
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'

# Offense count: 69
# Offense count: 70
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/integration/integration_spec.rb'
- 'spec/slack/events/config_spec.rb'
- 'spec/slack/events/request_spec.rb'
- 'spec/slack/messages/formatting_spec.rb'
- 'spec/slack/real_time/client_spec.rb'
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
- 'spec/slack/real_time/event_handlers/bot_spec.rb'
- 'spec/slack/real_time/event_handlers/channel_spec.rb'
- 'spec/slack/real_time/event_handlers/group_spec.rb'
- 'spec/slack/real_time/event_handlers/im_spec.rb'
- 'spec/slack/real_time/event_handlers/team_spec.rb'
- 'spec/slack/real_time/event_handlers/user_spec.rb'
- 'spec/slack/slack_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/channels_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/groups_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
- 'spec/slack/web/api/mixins/channels_spec.rb'
- 'spec/slack/web/api/mixins/groups_spec.rb'
- 'spec/slack/web/api/mixins/users_spec.rb'
- 'spec/slack/web/api/pagination/cursor_spec.rb'
- 'spec/slack/web/client_spec.rb'
- 'spec/support/real_time/connected_client.rb'
Enabled: false

# Offense count: 63
# Offense count: 64
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/integration/integration_spec.rb'
- 'spec/slack/real_time/client_spec.rb'
- 'spec/slack/real_time/event_handlers/bot_spec.rb'
- 'spec/slack/real_time/event_handlers/channel_spec.rb'
- 'spec/slack/real_time/event_handlers/event_handlers_spec.rb'
- 'spec/slack/real_time/event_handlers/group_spec.rb'
- 'spec/slack/real_time/event_handlers/im_spec.rb'
- 'spec/slack/real_time/event_handlers/team_spec.rb'
- 'spec/slack/real_time/event_handlers/user_spec.rb'
- 'spec/slack/slack_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
- 'spec/slack/web/api/error_spec.rb'
- 'spec/slack/web/api/errors/service_unavailable_spec.rb'
- 'spec/slack/web/api/errors/slack_error_spec.rb'
- 'spec/slack/web/api/pagination/cursor_spec.rb'
- 'spec/slack/web/client_spec.rb'
- 'spec/slack/web/faraday/response/raise_error_spec.rb'
Enabled: false

# Offense count: 16
# Offense count: 17
# Configuration parameters: CustomTransform, IgnoreMethods.
RSpec/FilePath:
Exclude:
- 'spec/slack/real_time/api/message_spec.rb'
- 'spec/slack/real_time/api/ping_spec.rb'
- 'spec/slack/real_time/api/typing_spec.rb'
- 'spec/slack/real_time/event_handlers/bot_spec.rb'
- 'spec/slack/real_time/event_handlers/channel_spec.rb'
- 'spec/slack/real_time/event_handlers/event_handlers_spec.rb'
- 'spec/slack/real_time/event_handlers/group_spec.rb'
- 'spec/slack/real_time/event_handlers/im_spec.rb'
- 'spec/slack/real_time/event_handlers/user_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/channels_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/groups_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/views_spec.rb'
- 'spec/slack/web/api/errors/service_unavailable_spec.rb'
Enabled: false

# Offense count: 13
# Configuration parameters: AssignmentOnly.
Expand All @@ -147,48 +60,20 @@ RSpec/InstanceVariable:
- 'spec/slack/real_time/client_spec.rb'
- 'spec/slack/slack_spec.rb'

# Offense count: 66
# Offense count: 75
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 92
# Configuration parameters: Max, AggregateFailuresByDefault.
# Offense count: 93
# Configuration parameters: AggregateFailuresByDefault.
RSpec/MultipleExpectations:
Exclude:
- 'spec/integration/integration_spec.rb'
- 'spec/slack/events/config_spec.rb'
- 'spec/slack/events/request_spec.rb'
- 'spec/slack/real_time/client_spec.rb'
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
- 'spec/slack/real_time/event_handlers/bot_spec.rb'
- 'spec/slack/real_time/event_handlers/channel_spec.rb'
- 'spec/slack/real_time/event_handlers/event_handlers_spec.rb'
- 'spec/slack/real_time/event_handlers/group_spec.rb'
- 'spec/slack/real_time/event_handlers/im_spec.rb'
- 'spec/slack/real_time/event_handlers/team_spec.rb'
- 'spec/slack/real_time/event_handlers/user_spec.rb'
- 'spec/slack/real_time/store_spec.rb'
- 'spec/slack/slack_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
- 'spec/slack/web/api/error_spec.rb'
- 'spec/slack/web/api/errors/service_unavailable_spec.rb'
- 'spec/slack/web/api/errors/slack_error_spec.rb'
- 'spec/slack/web/api/pagination/cursor_spec.rb'
- 'spec/slack/web/client_spec.rb'
Max: 5

# Offense count: 32
# Configuration parameters: Max.
# Offense count: 34
RSpec/NestedGroups:
Exclude:
- 'spec/slack/real_time/client_spec.rb'
- 'spec/slack/web/api/pagination/cursor_spec.rb'
- 'spec/slack/web/client_spec.rb'
Max: 6

# Offense count: 3
RSpec/SubjectStub:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [#297](https://github.com/slack-ruby/slack-ruby-client/pull/297): Various Rubocop fixes - [@jcraigk](https://github.com/jcraigk).
* [#298](https://github.com/slack-ruby/slack-ruby-client/pull/298): Add `admin.apps`, `admin.app.requests` and `views` endpoints - [@jmanian](https://github.com/jmanian).
* [#302](https://github.com/slack-ruby/slack-ruby-client/pull/302): Add `oauth.v2.access` and `views.published` endpoints - [@jwright](https://github.com/jwright).
* [#309](https://github.com/slack-ruby/slack-ruby-client/pull/309): Stop ping on `inactive_account` and `invalid_auth` - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.14.4 (2019/7/28)
Expand Down
8 changes: 8 additions & 0 deletions lib/slack/real_time/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ def run_ping!
logger.warn(to_s) { 'is offline' }

restart_async
rescue Slack::Web::Api::Errors::SlackError => e
# stop pinging if bot was uninstalled
case e.message
when 'account_inactive', 'invalid_auth' then
logger.warn(to_s) { e.message }
raise e
end
logger.debug("#{self}##{__method__}") { e }
rescue StandardError => e
# disregard all ping worker failures, keep pinging
logger.debug("#{self}##{__method__}") { e }
Expand Down
2 changes: 1 addition & 1 deletion lib/slack/web/api/errors/slack_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class SlackError < ::Faraday::Error
attr_reader :response

def initialize(message, response = nil)
@response = response
super message
@response = response
end
end
end
Expand Down
23 changes: 22 additions & 1 deletion spec/slack/real_time/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@
expect(socket).to receive(:restart_async)
client.run_ping!
end
[EOFError, Errno::ECONNRESET, Errno::EPIPE, Faraday::ClientError].each do |err|
[
EOFError,
Errno::ECONNRESET,
Errno::EPIPE,
Faraday::ClientError,
Slack::Web::Api::Errors::SlackError
].each do |err|
context "raising #{err}" do
it 'does not terminate the ping worker' do
allow(socket).to receive(:time_since_last_message) { raise err }
Expand All @@ -202,6 +208,21 @@
end
end
end
context 'raising Slack::Web::Api::Errors::SlackError' do
%w[invalid_auth account_inactive].each do |code|
context code do
it 'does not terminate the ping worker' do
allow(socket).to receive(:time_since_last_message) {
raise Slack::Web::Api::Errors::SlackError, code
}
expect(socket).not_to receive(:send_data)
expect do
client.run_ping!
end.to raise_error Slack::Web::Api::Errors::SlackError, code
end
end
end
end
end
end

Expand Down

0 comments on commit 614665f

Please sign in to comment.