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

Fix access to lock #476

Merged
merged 10 commits into from
Mar 21, 2020
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
16 changes: 13 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Lint/AmbiguousBlockAssociation:
Exclude:
- "spec/**/*"

Lint/HandleExceptions:
Lint/SuppressedException:
Enabled: true

Lint/UselessAssignment:
Expand All @@ -42,7 +42,7 @@ Metrics/AbcSize:
Metrics/CyclomaticComplexity:
Max: 7

Metrics/LineLength:
Layout/LineLength:
Max: 120

Metrics/MethodLength:
Expand All @@ -54,6 +54,7 @@ Metrics/BlockLength:
- "**/spec/**/*.rb"
- "**/*.rake"
- "Rakefile"
- "Gemfile"
- "*.gemspec"

Metrics/PerceivedComplexity:
Expand All @@ -73,7 +74,7 @@ Naming/FileName:
Naming/RescuedExceptionsVariableName:
PreferredName: ex

Naming/UncommunicativeMethodParamName:
Naming/MethodParameterName:
AllowedNames:
- ex

Expand Down Expand Up @@ -134,6 +135,15 @@ Style/FrozenStringLiteralComment:
Style/GlobalVars:
Enabled: true

Style/HashEachMethods:
Enabled: false

Style/HashTransformKeys:
Enabled: false

Style/HashTransformValues:
Enabled: false

Style/ModuleFunction:
Enabled: false

Expand Down
7 changes: 4 additions & 3 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

require "simplecov-json"
require "simplecov-oj"
require "simplecov-material"

SimpleCov.command_name "RSpec"
# SimpleCov.refuse_coverage_drop
SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter,
SimpleCov::Formatter::MaterialFormatter,
SimpleCov::Formatter::OjFormatter,
]

SimpleCov.start do
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ after_script:
- if [[ "${COV}" = "true" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi;

rvm:
- 2.4.8
- 2.4.9

matrix:
fast_finish: true

exclude:
- rvm: 2.4.8
- rvm: 2.4.9
gemfile: gemfiles/sidekiq_6.0.gemfile
- rvm: 2.4.8
- rvm: 2.4.9
gemfile: gemfiles/sidekiq_develop.gemfile

include:
- rvm: 2.5.7
gemfile: gemfiles/sidekiq_6.0.gemfile
- rvm: jruby-9.2.8.0
- rvm: jruby-9.2.11.0
gemfile: gemfiles/sidekiq_6.0.gemfile
- rvm: 2.6.5
gemfile: gemfiles/sidekiq_develop.gemfile
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
8 changes: 7 additions & 1 deletion gemfiles/sidekiq_4.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ gem "rspec-eventually", require: false
gem "rspec-its", require: false
gem "sidekiq", "~> 4.0.0"

platforms :jruby do
gem "pry-debugger-jruby"
end

platforms :mri do
gem "benchmark-ips"
gem "fasterer"
Expand All @@ -26,7 +30,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
8 changes: 7 additions & 1 deletion gemfiles/sidekiq_4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ gem "rspec-eventually", require: false
gem "rspec-its", require: false
gem "sidekiq", "~> 4.1.0"

platforms :jruby do
gem "pry-debugger-jruby"
end

platforms :mri do
gem "benchmark-ips"
gem "fasterer"
Expand All @@ -26,7 +30,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
8 changes: 7 additions & 1 deletion gemfiles/sidekiq_4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ gem "rspec-eventually", require: false
gem "rspec-its", require: false
gem "sidekiq", "~> 4.2.0"

platforms :jruby do
gem "pry-debugger-jruby"
end

platforms :mri do
gem "benchmark-ips"
gem "fasterer"
Expand All @@ -26,7 +30,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
8 changes: 7 additions & 1 deletion gemfiles/sidekiq_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ gem "rspec-eventually", require: false
gem "rspec-its", require: false
gem "sidekiq", "~> 5.0.0"

platforms :jruby do
gem "pry-debugger-jruby"
end

platforms :mri do
gem "benchmark-ips"
gem "fasterer"
Expand All @@ -26,7 +30,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
8 changes: 7 additions & 1 deletion gemfiles/sidekiq_5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ gem "rspec-eventually", require: false
gem "rspec-its", require: false
gem "sidekiq", "~> 5.1.0"

platforms :jruby do
gem "pry-debugger-jruby"
end

platforms :mri do
gem "benchmark-ips"
gem "fasterer"
Expand All @@ -26,7 +30,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
8 changes: 7 additions & 1 deletion gemfiles/sidekiq_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ gem "rspec-eventually", require: false
gem "rspec-its", require: false
gem "sidekiq", "~> 5.2.0"

platforms :jruby do
gem "pry-debugger-jruby"
end

platforms :mri do
gem "benchmark-ips"
gem "fasterer"
Expand All @@ -26,7 +30,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
8 changes: 7 additions & 1 deletion gemfiles/sidekiq_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ gem "rspec-eventually", require: false
gem "rspec-its", require: false
gem "sidekiq", ">= 6.0.pre", "< 6.1"

platforms :jruby do
gem "pry-debugger-jruby"
end

platforms :mri do
gem "benchmark-ips"
gem "fasterer"
Expand All @@ -26,7 +30,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
8 changes: 7 additions & 1 deletion gemfiles/sidekiq_develop.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ gem "rspec-eventually", require: false
gem "rspec-its", require: false
gem "sidekiq", git: "https://github.com/mperham/sidekiq.git"

platforms :jruby do
gem "pry-debugger-jruby"
end

platforms :mri do
gem "benchmark-ips"
gem "fasterer"
Expand All @@ -26,7 +30,9 @@ platforms :mri do
gem "rubocop-performance"
gem "rubocop-rspec"
gem "ruby-prof"
gem "simplecov-json"
gem "simplecov", "< 0.18"
gem "simplecov-material"
gem "simplecov-oj"
gem "stackprof"
gem "terminal-notifier-guard"
gem "test-prof"
Expand Down
5 changes: 4 additions & 1 deletion lib/sidekiq_unique_jobs/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def console

no_commands do
def console_class
return IRB if RUBY_PLATFORM == JAVA
if RUBY_PLATFORM == "JAVA"
require "irb"
return IRB
end

require "pry"
Pry
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/locksmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(item, redis_pool = nil)
@ttl = item[LOCK_EXPIRATION_KEY]
@jid = item[JID_KEY]
@unique_digest = item[UNIQUE_DIGEST_KEY]
@lock_type = item[LOCK_KEY]
@lock_type = item[LOCK_KEY] || item[UNIQUE_KEY]
@lock_type &&= @lock_type.to_sym
@redis_pool = redis_pool
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/version_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module SidekiqUniqueJobs
# @author Mikael Henriksson <mikael@zoolutions.se>
#
class VersionCheck
PATTERN = /(?<operator1>[<>=]+)?\s?(?<version1>(\d+.?)+)(\s+&&\s+)?(?<operator2>[<>=]+)?\s?(?<version2>(\d+.?)+)?/m.freeze # rubocop:disable Metrics/LineLength
PATTERN = /(?<operator1>[<>=]+)?\s?(?<version1>(\d+.?)+)(\s+&&\s+)?(?<operator2>[<>=]+)?\s?(?<version2>(\d+.?)+)?/m.freeze # rubocop:disable Layout/LineLength

#
# Checks if a version is consrtaint is satisfied
Expand Down
4 changes: 3 additions & 1 deletion lib/sidekiq_unique_jobs/web.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

begin
require "delegate"
require "rack"
require "sidekiq/web"
rescue LoadError # rubocop:disable Lint/HandleExceptions
rescue LoadError # rubocop:disable Lint/SuppressedException
# client-only usage
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.do_it(_one)
)

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].each do |x|
ShitClass.delay_for(x, unique: :while_executing).do_it(1)
ShitClass.delay_for(x, queue: 'custom', unique: :while_executing).do_it(1)
end

expect(schedule_count).to eq(20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
RSpec.describe SidekiqUniqueJobs::Lock::WhileExecuting, redis: :redis do
include SidekiqHelpers

let(:process_one) { described_class.new(item_one, callback_one) }
let(:process_two) { described_class.new(item_two, callback_two) }
let(:process_one) { described_class.new(item_one, callback_one) }
let(:process_two) { described_class.new(item_two, callback_two) }
let(:strategy_one) { nil }
let(:strategy_two) { nil }

Expand Down
1 change: 0 additions & 1 deletion spec/integration/sidekiq_unique_jobs/web_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "sidekiq/web"
require "sidekiq_unique_jobs/web"
require "rack/test"

Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "bundler/setup"

if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.5" && RUBY_VERSION < "2.6"
if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.6" && RUBY_VERSION < "2.7"
require "simplecov" unless %w[false 0].include?(ENV["COV"])

begin
Expand All @@ -27,8 +27,8 @@

require "sidekiq/redis_connection"

Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].each { |f| require f }
Dir[File.join(File.dirname(__FILE__), "..", "examples", "**", "*.rb")].each { |f| require f }
Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].sort.each { |f| require f }
Dir[File.join(File.dirname(__FILE__), "..", "examples", "**", "*.rb")].sort.each { |f| require f }

RSpec.configure do |config|
config.define_derived_metadata do |meta|
Expand Down
Loading