Skip to content

Commit

Permalink
Fix access to lock (#476)
Browse files Browse the repository at this point in the history
* Bump gems

* Bump ruby version for coverage

## To make a commit, type your commit message and press SUPER-ENTER.
## To cancel the commit, close the window. To sign off on the commit,
## press SUPER-S.
##
## You may also reference or close a GitHub issue with this commit.
## To do so, type `#` followed by the `tab` key.  You will be shown a
## list of issues related to the current repo.  You may also type
## `owner/repo#` plus the `tab` key to reference an issue in a
## different GitHub repo.

 spec/spec_helper.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 15d8d26..6a7140b 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -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

* Fallback to UNIQUE_KEY

* Fix console spec

* Mandatory rubocop commit

* Due to bug in rack

rack/rack#1610

* Fix broken spec

* Da fork jRuby...?

* Skip spec for jruby

* sodsohdoasdhifa;sodb ;oqwuefg2398yr	2t89f	ouwefqo
  • Loading branch information
mhenrixon committed Mar 21, 2020
1 parent 87e64d4 commit c9909e7
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 61 deletions.
16 changes: 13 additions & 3 deletions .rubocop.yml
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
@@ -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
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
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
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
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
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
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
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
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
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
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
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
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
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
@@ -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
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
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
@@ -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
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

0 comments on commit c9909e7

Please sign in to comment.