Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43784ea
commit 134d82e
Showing
6 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: ruby | ||
rvm: | ||
- 1.9.3 | ||
branches: | ||
only: | ||
- master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
source 'https://rubygems.org' | ||
gemspec | ||
|
||
group :test do | ||
gem 'simplecov', :require => false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |