Skip to content

Commit

Permalink
Merge pull request #44 from enova/github-actions-ci
Browse files Browse the repository at this point in the history
Rewrite Travis CI as Github Actions; add Sidekiq versions
  • Loading branch information
rnubel authored Mar 1, 2023
2 parents 5412518 + 5b6decc commit 4848800
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 83 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions .simplecov

This file was deleted.

24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source "https://rubygems.org"

gem 'sidekiq', '~> 6.0'
gem 'sidekiq', '~> 6.0.0'

gemspec path: '../'
5 changes: 5 additions & 0 deletions gemfiles/sidekiq_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem 'sidekiq', '~> 6.1.0'

gemspec path: '../'
5 changes: 5 additions & 0 deletions gemfiles/sidekiq_6.x.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem 'sidekiq', '~> 6.5.8'

gemspec path: '../'
2 changes: 1 addition & 1 deletion lib/sidekiq-rate-limiter/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Sidekiq
module RateLimiter
VERSION = "0.1.3"
VERSION = "0.2.0"
end
end
3 changes: 2 additions & 1 deletion sidekiq-rate-limiter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 13 additions & 5 deletions spec/sidekiq-rate-limiter/fetch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand All @@ -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])
Expand Down
12 changes: 10 additions & 2 deletions spec/sidekiq-rate-limiter/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 18 additions & 41 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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|
Expand Down Expand Up @@ -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
##

0 comments on commit 4848800

Please # to comment.