diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d91073e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,48 @@ +name: Test + +on: + push: + branches: [ main ] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + ruby-version: ['3.1', '2.7'] + sidekiq-version: ['4', '5', '6.0', '6.1', '6.x'] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108 + with: + ruby-version: ${{ matrix.ruby-version }} + + - name: Install dependencies + run: bundle install --gemfile=gemfiles/sidekiq_${{ matrix.sidekiq-version }}.gemfile + + - name: Start Redis + uses: supercharge/redis-github-action@1.5.0 + + - name: Run tests + run: bundle exec --gemfile=gemfiles/sidekiq_${{ matrix.sidekiq-version }}.gemfile rspec + + - name: Coveralls + uses: coverallsapp/github-action@v1 + with: + flag-name: run-${{ join(matrix.*, '-') }} + parallel: true + + finish: + needs: test + if: ${{ always() }} + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@v1 + with: + parallel-finished: true diff --git a/.simplecov b/.simplecov deleted file mode 100644 index 282101e..0000000 --- a/.simplecov +++ /dev/null @@ -1,6 +0,0 @@ -require 'coveralls' - -Coveralls.wear! do - add_filter "vendor" - add_filter "spec" -end diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 60a8631..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: ruby -cache: bundler -sudo: false -rvm: - - 2.5.1 - - 2.4.4 - -gemfile: - - 'gemfiles/sidekiq_4.gemfile' - - 'gemfiles/sidekiq_5.gemfile' - - 'gemfiles/sidekiq_6.gemfile' - -matrix: - exclude: - - rvm: 2.4.4 - gemfile: gemfiles/sidekiq_6.gemfile - -deploy: - provider: rubygems - api_key: - secure: "VX48kpd9UySMWSDMwjxaNZy14RW1usU7eFLGNeohjCzxUsCywn+mS5/IZHl56vDXWJp7JwnboDiIa74hGV86PcSEM7kr+DAZO33iCazMNTpoWDiH1iJfj0jZbO2rOvx0rGI9fGYcC9xfyKQ37hVb13Eo0bnKa0YX30HArnx7EFo=" - on: - tags: true - all_branches: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 132814f..933d77b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.2.0 (Mar 1, 2023) + +* Upstream fix for sidekiq 6.5.0 [#43, thanks to 5minpause] +* Add support for new Sidekiq's configuration model [#42, thanks to anero] +* gemspec: Drop defunct property rubyforge_project [#37, thanks to olleolleolle] + ## 0.1.3 (Oct 15, 2019) * Fix errors when using with redis-rb > 4.1.0 [#30, #31] diff --git a/README.md b/README.md index 5cab77b..970e4be 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,14 @@ sidekiq-rate-limiter ==================== [![Gem Version](https://badge.fury.io/rb/sidekiq-rate-limiter.svg)](https://rubygems.org/gems/sidekiq-rate-limiter) -[![Build Status](https://secure.travis-ci.org/enova/sidekiq-rate-limiter.svg?branch=master)](http://travis-ci.org/enova/sidekiq-rate-limiter) +[![Test Status](https://github.com/enova/sidekiq-rate-limiter/actions/workflows/test.yml/badge.svg)](https://github.com/enova/sidekiq-rate-limiter/actions/workflows/test.yml) [![Coverage Status](https://coveralls.io/repos/github/enova/sidekiq-rate-limiter/badge.svg?branch=master)](https://coveralls.io/github/enova/sidekiq-rate-limiter?branch=master) Redis-backed, per-worker rate limits for job processing. ## Compatibility -sidekiq-rate-limiter is actively tested against MRI versions 2.4 and 2.5. +sidekiq-rate-limiter is actively tested against MRI versions 2.7 and 3.1. sidekiq-rate-limiter works by using a custom fetch class, the class responsible for pulling work from the queue stored in Redis. Consequently you'll want to be diff --git a/gemfiles/sidekiq_6.gemfile b/gemfiles/sidekiq_6.0.gemfile similarity index 66% rename from gemfiles/sidekiq_6.gemfile rename to gemfiles/sidekiq_6.0.gemfile index c64b981..1a3591e 100644 --- a/gemfiles/sidekiq_6.gemfile +++ b/gemfiles/sidekiq_6.0.gemfile @@ -1,5 +1,5 @@ source "https://rubygems.org" -gem 'sidekiq', '~> 6.0' +gem 'sidekiq', '~> 6.0.0' gemspec path: '../' diff --git a/gemfiles/sidekiq_6.1.gemfile b/gemfiles/sidekiq_6.1.gemfile new file mode 100644 index 0000000..1e3d949 --- /dev/null +++ b/gemfiles/sidekiq_6.1.gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem 'sidekiq', '~> 6.1.0' + +gemspec path: '../' diff --git a/gemfiles/sidekiq_6.x.gemfile b/gemfiles/sidekiq_6.x.gemfile new file mode 100644 index 0000000..89010fb --- /dev/null +++ b/gemfiles/sidekiq_6.x.gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem 'sidekiq', '~> 6.5.8' + +gemspec path: '../' diff --git a/lib/sidekiq-rate-limiter/version.rb b/lib/sidekiq-rate-limiter/version.rb index 94e9a62..160f7ab 100644 --- a/lib/sidekiq-rate-limiter/version.rb +++ b/lib/sidekiq-rate-limiter/version.rb @@ -1,5 +1,5 @@ module Sidekiq module RateLimiter - VERSION = "0.1.3" + VERSION = "0.2.0" end end diff --git a/sidekiq-rate-limiter.gemspec b/sidekiq-rate-limiter.gemspec index 20231a4..baefa9c 100644 --- a/sidekiq-rate-limiter.gemspec +++ b/sidekiq-rate-limiter.gemspec @@ -23,7 +23,8 @@ Gem::Specification.new do |s| s.add_development_dependency "pry-byebug" s.add_development_dependency "rake" s.add_development_dependency "rspec", '~> 3.4' - s.add_development_dependency "coveralls", '~> 0.8' + s.add_development_dependency "simplecov" + s.add_development_dependency "simplecov-lcov", '~> 0.8.0' s.add_dependency "sidekiq", ">= 4.0", "< 7.0" s.add_dependency "redis_rate_limiter" diff --git a/spec/sidekiq-rate-limiter/fetch_spec.rb b/spec/sidekiq-rate-limiter/fetch_spec.rb index 5b4d98e..8db65e7 100644 --- a/spec/sidekiq-rate-limiter/fetch_spec.rb +++ b/spec/sidekiq-rate-limiter/fetch_spec.rb @@ -27,11 +27,14 @@ def perform(arg1, arg2); end end end - let(:options) { - s = Sidekiq - s[:queues] = [queue, another_queue, another_queue] - s - } + let(:options) do + if Sidekiq::VERSION =~ /^(4|5|6\.[0-4])/ + { queues: [queue, another_queue, another_queue] } + else + Sidekiq.tap { |s| s[:queues] = [queue, another_queue, another_queue] } + end + end + let(:queue) { 'basic' } let(:another_queue) { 'some_other_queue' } let(:args) { ['I am some args'] } @@ -50,6 +53,11 @@ def perform(arg1, arg2); end else Sidekiq::Fetcher::TIMEOUT end + + if Sidekiq::VERSION.start_with?('6.5.') + _timeout = { timeout: timeout} + timeout = _timeout + end fetch = described_class.new options.merge!(:strict => true) expect(fetch.queues_cmd).to eql(["queue:#{queue}", "queue:#{another_queue}", timeout]) diff --git a/spec/sidekiq-rate-limiter/server_spec.rb b/spec/sidekiq-rate-limiter/server_spec.rb index 3cf4f41..a7dbf56 100644 --- a/spec/sidekiq-rate-limiter/server_spec.rb +++ b/spec/sidekiq-rate-limiter/server_spec.rb @@ -8,13 +8,21 @@ it 'should set Sidekiq.options[:fetch] as desired' do Sidekiq.configure_server do |config| - expect(Sidekiq.options[:fetch]).to be_a(Sidekiq::RateLimiter::Fetch) + if Sidekiq::VERSION =~ /^(4|5|6.0)/ + expect(Sidekiq.options[:fetch]).to eql(Sidekiq::RateLimiter::Fetch) + else + expect(Sidekiq.options[:fetch]).to be_a(Sidekiq::RateLimiter::Fetch) + end end end it 'should inherit from Sidekiq::BasicFetch' do Sidekiq.configure_server do |config| - expect(Sidekiq.options[:fetch].class.ancestors[1]).to be(Sidekiq::BasicFetch) + if Sidekiq::VERSION =~ /^(4|5|6.0)/ + expect(Sidekiq.options[:fetch]).to be < Sidekiq::BasicFetch + else + expect(Sidekiq.options[:fetch].class.ancestors[1]).to be(Sidekiq::BasicFetch) + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c29688..2a42c12 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,35 +2,10 @@ require 'sidekiq/testing' require 'pry-byebug' -## Confirming presence of redis server executable -abort "## `redis-server` not in path" if %x(which redis-server).empty? -redis_dir = "#{File.dirname(__FILE__)}/support/redis" - -## Redis configuration -REDIS_CONFIG = <<-CONF - daemonize yes - pidfile #{redis_dir}/test.pid - port 6380 - timeout 300 - save 900 1 - save 300 10 - save 60 10000 - dbfilename test.rdb - dir #{redis_dir} - loglevel warning - logfile stdout - databases 1 -CONF - -%x(echo '#{REDIS_CONFIG}' > #{redis_dir}/test.conf) -redis_command = "redis-server #{redis_dir}/test.conf" -%x[ #{redis_command} ] -## - ## Configuring sidekiq options = { logger: nil, - redis: { :url => "redis://localhost:6380/0" } + redis: { url: ENV.fetch('REDIS_URL', 'redis://localhost:6379/0') } } Sidekiq.configure_client do |config| @@ -44,12 +19,27 @@ config.send("#{option}=", value) end end -## + +## Code Coverage require 'simplecov' +SimpleCov.start do + if ENV['CI'] + require 'simplecov-lcov' + + SimpleCov::Formatter::LcovFormatter.config do |c| + c.report_with_single_file = true + c.single_report_path = 'coverage/lcov.info' + end + + formatter SimpleCov::Formatter::LcovFormatter + end + + add_filter %w[version.rb spec/] +end + require File.expand_path("../../lib/sidekiq-rate-limiter", __FILE__) -## ## Hook to set Sidekiq::Testing mode using rspec tags RSpec.configure do |config| @@ -77,18 +67,5 @@ elsif Sidekiq::Testing.fake? Sidekiq::Worker.clear_all end - - end - - config.after(:all) do - ## Stopping Redis - ps = %x(ps -A -o pid,command | grep '#{redis_command}' | grep -v grep).split($/) - pids = ps.map { |p| p.split(/\s+/).reject(&:empty?).first.to_i } - pids.each { |pid| Process.kill("TERM", pid) } - - ## Cleaning up - sleep 0.1 - %x(rm -rf #{redis_dir}/*) end end -##