diff --git a/dip.yml b/dip.yml index b529fcc..35d1ff5 100644 --- a/dip.yml +++ b/dip.yml @@ -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: "" diff --git a/docker-compose.yml b/docker-compose.yml index a0b685d..da73b6b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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' diff --git a/resque-integration.gemspec b/resque-integration.gemspec index 70588fb..a593631 100644 --- a/resque-integration.gemspec +++ b/resque-integration.gemspec @@ -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 diff --git a/spec/resque/integration_spec.rb b/spec/resque/integration_spec.rb index bc98b87..9f04dab 100644 --- a/spec/resque/integration_spec.rb +++ b/spec/resque/integration_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0737de5..1b2dfe3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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