Skip to content

Commit

Permalink
chore: use redis image istead of mock
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarinEA committed Jul 21, 2021
1 parent 21aa6ba commit 933115d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
1 change: 1 addition & 0 deletions dip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '1'
environment:
DOCKER_RUBY_VERSION: 2.3
RUBY_IMAGE_TAG: 2.3-latest
REDIS_IMAGE_TAG: 4-alpine
COMPOSE_FILE_EXT: development
RAILS_ENV: test
APRESS_GEMS_CREDENTIALS: ""
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ services:
image: abakpress/ruby-app:$RUBY_IMAGE_TAG
environment:
- BUNDLE_PATH=/bundle/$DOCKER_RUBY_VERSION
- TEST_REDIS_HOST=redis
command: bash
volumes:
- .:/app
depends_on:
- redis

redis:
image: redis:$REDIS_IMAGE_TAG
command: 'redis-server --bind 0.0.0.0'
1 change: 0 additions & 1 deletion resque-integration.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'appraisal', '>= 1.0.2'
gem.add_development_dependency 'combustion', '>= 0.5.5'
gem.add_development_dependency 'mock_redis'
gem.add_development_dependency 'timecop'
gem.add_development_dependency 'pry-byebug'
end
45 changes: 30 additions & 15 deletions spec/resque/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,49 @@ def self.execute(id, params)
end
end

it 'enqueues only one job' do
UniqueJob.enqueue(1, param: 'one')
let(:redis) { Resque.redis }
let(:travel_redis) do
->(time) do
redis.keys.each do |key|
ttl = redis.ttl(key)
next if ttl <= 0

redis.expire(key, ttl - time.to_i)
end
end
end

Timecop.travel(10.hours.since) do
context 'when enqueues only one job' do
before do
UniqueJob.enqueue(1, param: 'one')

expect(Resque.peek(:test, 0, 100).size).to eq(1)
travel_redis.call(10.hours)

UniqueJob.enqueue(1, param: 'one')
end
end

it 'enqueues two jobs with differ args' do
UniqueJob.enqueue(1, param: 'one')
it { expect(Resque.peek(:test, 0, 100).size).to eq(1) }
end

Timecop.travel(10.hours.since) do
context 'when enqueues two jobs with differ args' do
before do
UniqueJob.enqueue(1, param: 'one')
UniqueJob.enqueue(1, param: 'two')

expect(Resque.peek(:test, 0, 100).size).to eq(2)
end
end

it 'enqueues two jobs after expire lock timeout' do
UniqueJob.enqueue(1, param: 'one')
it { expect(Resque.peek(:test, 0, 100).size).to eq(2) }
end

Timecop.travel(4.days.since) do
context 'when enqueues two jobs after expire lock timeout' do
before do
UniqueJob.enqueue(1, param: 'one')

expect(Resque.peek(:test, 0, 100).size).to eq(2)
travel_redis.call(4.days)

UniqueJob.enqueue(1, param: 'one')
end

it { expect(Resque.peek(:test, 0, 100).size).to eq(2) }
end

describe 'unlock' do
Expand Down
5 changes: 3 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
require 'rspec/its'
require 'resque'
require 'simplecov'
require 'mock_redis'
require 'timecop'
require 'pry-byebug'
require 'combustion'

Resque.redis = MockRedis.new
redis = Redis.new(host: ENV['TEST_REDIS_HOST'])
Redis.current = redis
Resque.redis = redis

SimpleCov.start

Expand Down

0 comments on commit 933115d

Please sign in to comment.