sidekiq-scheduler 0.4.1 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/test/manager_test.rb DELETED
@@ -1,65 +0,0 @@
1
- require 'test_helper'
2
- require 'sidekiq'
3
- require 'sidekiq/manager'
4
-
5
- class ManagerTest < MiniTest::Unit::TestCase
6
- describe 'with redis' do
7
- before do
8
- Sidekiq.redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/15', :namespace => 'testy')
9
- Sidekiq.redis {|c| c.flushdb }
10
- @scheduler = SidekiqScheduler::Manager.new
11
- $processed = 0
12
- $mutex = Mutex.new
13
- end
14
-
15
- class IntegrationWorker
16
- include Sidekiq::Worker
17
-
18
- def perform(a, b)
19
- $mutex.synchronize do
20
- $processed += 1
21
- end
22
- a + b
23
- end
24
- end
25
-
26
- it 'detects an empty schedule run' do
27
- assert_nil @scheduler.wrapped_object.send(:find_next_timestamp)
28
- end
29
-
30
- it 'processes only jobs that are due' do
31
- timestamp = Time.now + 600
32
- Sidekiq::Client.delayed_push(:foo, timestamp, 'class' => IntegrationWorker, 'args' => [1,2])
33
- assert_nil @scheduler.wrapped_object.send(:find_next_timestamp)
34
- end
35
-
36
- it 'processes queues in the right order' do
37
- Sidekiq::Client.delayed_push(:foo, 1331284491, 'class' => IntegrationWorker, 'args' => [1,2])
38
- Sidekiq::Client.delayed_push(:foo, 1331284492, 'class' => IntegrationWorker, 'args' => [1,2])
39
-
40
- assert_equal 1331284491, @scheduler.wrapped_object.send(:find_next_timestamp)
41
- end
42
-
43
- it 'moves jobs from the scheduler queues to the worker queues' do
44
- Sidekiq::Client.delayed_push(:foo, 1331284491, 'class' => IntegrationWorker, 'args' => [1,2])
45
-
46
- @scheduler.wrapped_object.send(:find_scheduled_work, 1331284491)
47
-
48
- assert_equal 0, Sidekiq.redis {|c| c.llen("delayed:1331284491") }
49
- assert_equal 1, Sidekiq.redis {|c| c.llen("queue:foo") }
50
- end
51
-
52
- it 'resets the scheduler queue' do
53
- Sidekiq::Client.delayed_push(:foo, 1331284491, 'class' => IntegrationWorker, 'args' => [1,2])
54
- Sidekiq::Client.delayed_push(:foo, 1331284492, 'class' => IntegrationWorker, 'args' => [1,2])
55
- Sidekiq::Client.delayed_push(:foo, 1331284493, 'class' => IntegrationWorker, 'args' => [1,2])
56
-
57
- @scheduler.reset
58
-
59
- assert_equal 0, Sidekiq.redis {|c| c.zcard('delayed_queue_schedule') }
60
- assert !Sidekiq.redis {|c| c.exists('delayed:1331284491') }
61
- assert !Sidekiq.redis {|c| c.exists('delayed:1331284492') }
62
- assert !Sidekiq.redis {|c| c.exists('delayed:1331284493') }
63
- end
64
- end
65
- end
data/test/testing_test.rb DELETED
@@ -1,38 +0,0 @@
1
- require 'test_helper'
2
- require 'sidekiq-scheduler/worker'
3
-
4
- class TestingTest < MiniTest::Unit::TestCase
5
- describe 'sidekiq-scheduler testing' do
6
-
7
- it 'stubs the perform_* calls when in testing mode' do
8
- begin
9
- require 'sidekiq-scheduler/testing'
10
- # perform_at
11
- assert_equal 0, DirectWorker.jobs.size
12
- assert DirectWorker.perform_at(1331759054, 1, 2)
13
- assert_equal 1, DirectWorker.jobs.size
14
- assert_equal 1331759054, DirectWorker.jobs[0]['at']
15
- DirectWorker.jobs.clear
16
-
17
- # perform_in
18
- Timecop.freeze(Time.now) do
19
- timestamp = Time.now + 30
20
- assert_equal 0, DirectWorker.jobs.size
21
- assert DirectWorker.perform_in(30, 1, 2)
22
- assert_equal 1, DirectWorker.jobs.size
23
- assert_equal timestamp.to_f, DirectWorker.jobs[0]['at']
24
- end
25
- ensure
26
- # Undo override
27
- SidekiqScheduler::Worker::ClassMethods.class_eval do
28
- remove_method :perform_at, :perform_in, :remove_delayed, :remove_delayed_from_timestamp
29
- alias_method :perform_at, :perform_at_old
30
- alias_method :perform_in, :perform_in_old
31
- alias_method :remove_delayed, :remove_delayed_old
32
- alias_method :remove_delayed_from_timestamp, :remove_delayed_from_timestamp_old
33
- remove_method :perform_at_old, :perform_in_old, :remove_delayed_old, :remove_delayed_from_timestamp_old
34
- end
35
- end
36
- end
37
- end
38
- end