Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added tests. Fixes #1

  • Loading branch information...
commit 134d82eb18f79ce8874f6edc6095c75e7969592e 1 parent 43784ea
@krasnoukhov authored
View
6 .travis.yml
@@ -0,0 +1,6 @@
+language: ruby
+rvm:
+ - 1.9.3
+branches:
+ only:
+ - master
View
4 Gemfile
@@ -1,2 +1,6 @@
source 'https://rubygems.org'
gemspec
+
+group :test do
+ gem 'simplecov', :require => false
+end
View
7 Rakefile
@@ -1,2 +1,9 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
+require "rake/testtask"
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/test_*.rb'
+end
+
+task :default => :test
View
4 sidekiq-middleware.gemspec
@@ -14,5 +14,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = Sidekiq::Middleware::VERSION
- gem.add_dependency 'sidekiq'
+ gem.add_dependency 'sidekiq'
+ gem.add_development_dependency 'rake'
+ gem.add_development_dependency 'minitest', '~> 3'
end
View
17 test/helper.rb
@@ -0,0 +1,17 @@
+ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
+if ENV.has_key?('SIMPLECOV')
+ require 'simplecov'
+ SimpleCov.start
+end
+
+require 'minitest/unit'
+require 'minitest/pride'
+require 'minitest/autorun'
+
+require 'sidekiq'
+require 'sidekiq/util'
+require 'sidekiq-middleware'
+Sidekiq.logger.level = Logger::ERROR
+
+require 'sidekiq/redis_connection'
+REDIS = Sidekiq::RedisConnection.create(:url => "redis://localhost/15", :namespace => 'testy')
View
69 test/test_unique_jobs.rb
@@ -0,0 +1,69 @@
+require 'securerandom'
+require 'helper'
+require 'sidekiq/client'
+require 'sidekiq/worker'
+require 'sidekiq/processor'
+require 'sidekiq-middleware'
+
+class TestUniqueJobs < MiniTest::Unit::TestCase
+ describe 'with real redis' do
+ before do
+ @boss = MiniTest::Mock.new
+ @processor = ::Sidekiq::Processor.new(@boss)
+ Celluloid.logger = nil
+
+ Sidekiq.redis = REDIS
+ Sidekiq.redis {|c| c.flushdb }
+ end
+
+ class UniqueWorker
+ include Sidekiq::Worker
+ sidekiq_options queue: :unique_queue, unique: true
+
+ def perform(x)
+ end
+ end
+
+ it 'does not duplicate messages with enabled unique option' do
+ 5.times { UniqueWorker.perform_async('args') }
+ assert_equal 1, Sidekiq.redis { |c| c.llen('queue:unique_queue') }
+ end
+
+ class NotUniqueWorker
+ include Sidekiq::Worker
+ sidekiq_options queue: :not_unique_queue, unique: false
+
+ def perform(x)
+ end
+ end
+
+ it 'duplicates messages with disabled unique option' do
+ 5.times { NotUniqueWorker.perform_async('args') }
+ assert_equal 5, Sidekiq.redis { |c| c.llen('queue:not_unique_queue') }
+ end
+
+ class UniqueScheduledWorker
+ include Sidekiq::Worker
+ sidekiq_options queue: :unique_scheduled_queue, unique: :all, forever: true
+
+ def perform(x)
+ UniqueScheduledWorker.perform_in(60, x)
+ end
+ end
+
+ it 'does not duplicate scheduled messages with enabled unique option' do
+ 5.times { |t| UniqueScheduledWorker.perform_in((t+1)*60, 'args') }
+ assert_equal 1, Sidekiq.redis { |c| c.zrangebyscore('schedule', '-inf', '+inf').length }
+ end
+
+ it 'once schedules job in future with enabled forever option' do
+ 5.times {
+ msg = Sidekiq.dump_json({ 'class' => UniqueScheduledWorker.to_s, 'args' => ['forever'] })
+ @boss.expect(:processor_done!, nil, [@processor])
+ @processor.process(msg, 'default')
+ @boss.verify
+ }
+ assert_equal 1, Sidekiq.redis { |c| c.zrangebyscore('schedule', '-inf', '+inf').length }
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.