Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 105 lines (93 sloc) 2.703 kB
57a06d0 @grosser allow every test to be run with just ruby test/xxx_test.rb
grosser authored
1 require_relative 'helper'
c779018 @jakemack Implemented a strictly ordered queue switch
jakemack authored
2 require 'sidekiq/fetch'
3
babfdc9 @mperham Backport test suite to Minitest 4 so we can test against Rails 4.
authored
4 class TestFetcher < Sidekiq::Test
03d47b3 use behavior syntax consistent with rest of test suite
Jonathan Roes authored
5 describe 'fetcher' do
6 before do
0fa82c2 @charliesome use the right redis url when reconnecting in TestFetcher
charliesome authored
7 Sidekiq.redis = { :url => REDIS_URL, :namespace => 'fuzzy' }
03d47b3 use behavior syntax consistent with rest of test suite
Jonathan Roes authored
8 Sidekiq.redis do |conn|
9 conn.flushdb
10 conn.rpush('queue:basic', 'msg')
11 end
c779018 @jakemack Implemented a strictly ordered queue switch
jakemack authored
12 end
7408387 @mperham Refactor fetch strategy, fix queueing to lpush and rpop.
authored
13
c49e1f9 @mperham Fix issues with non-deterministic global test state
authored
14 after do
15 Sidekiq.redis = REDIS
16 end
17
03d47b3 use behavior syntax consistent with rest of test suite
Jonathan Roes authored
18 it 'retrieves' do
19 fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar'])
20 uow = fetch.retrieve_work
21 refute_nil uow
22 assert_equal 'basic', uow.queue_name
23 assert_equal 'msg', uow.message
24 q = Sidekiq::Queue.new('basic')
25 assert_equal 0, q.size
26 uow.requeue
27 assert_equal 1, q.size
28 assert_nil uow.acknowledge
29 end
7408387 @mperham Refactor fetch strategy, fix queueing to lpush and rpop.
authored
30
03d47b3 use behavior syntax consistent with rest of test suite
Jonathan Roes authored
31 it 'retrieves with strict setting' do
32 fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar', 'bar'], :strict => true)
33 cmd = fetch.queues_cmd
34 assert_equal cmd, ['queue:basic', 'queue:bar', 1]
35 end
0e19aee @mperham I'm a TDD master.
authored
36
03d47b3 use behavior syntax consistent with rest of test suite
Jonathan Roes authored
37 it 'bulk requeues' do
38 q1 = Sidekiq::Queue.new('foo')
39 q2 = Sidekiq::Queue.new('bar')
40 assert_equal 0, q1.size
41 assert_equal 0, q2.size
42 uow = Sidekiq::BasicFetch::UnitOfWork
78c694b @jonhyman Move bulk_requeue back to class method.
jonhyman authored
43 Sidekiq::BasicFetch.bulk_requeue([uow.new('fuzzy:queue:foo', 'bob'), uow.new('fuzzy:queue:foo', 'bar'), uow.new('fuzzy:queue:bar', 'widget')], {:queues => []})
03d47b3 use behavior syntax consistent with rest of test suite
Jonathan Roes authored
44 assert_equal 2, q1.size
45 assert_equal 1, q2.size
46 end
9867b72 @mperham Concerted effort to increase test coverage: 86 -> 88%
authored
47
48 describe 'fetching' do
49 before do
50 Sidekiq::Fetcher.reset
51 end
52
53 it 'instantiates' do
54 begin
55 Sidekiq.options[:fetch] = NullFetch
56 mgr = Minitest::Mock.new
57 fetch = Sidekiq::Fetcher.new(mgr, {})
58 fetch.fetch
59 Sidekiq::Fetcher.done!
60 ensure
61 Sidekiq.options[:fetch] = Sidekiq::BasicFetch
62 end
63 end
64
65 class NullFetch
66 def initialize(opts)
67 end
68 def retrieve_work
69 end
70 def self.bulk_requeue(*args)
71 end
72 end
73
74 it 'handles redis network errors' do
75 begin
76 Sidekiq.logger.level = Logger::FATAL
77 Sidekiq.options[:fetch] = ErrorFetch
78 mgr = Minitest::Mock.new
79 fetch = Sidekiq::Fetcher.new(mgr, {})
80 def fetch.pause
81 end
82 refute fetch.down
83 fetch.fetch
84 Sidekiq::Fetcher.done!
85 assert fetch.down
86 ensure
87 Sidekiq.options[:fetch] = Sidekiq::BasicFetch
88 Sidekiq.logger.level = Logger::ERROR
89 end
90 end
91
92 class ErrorFetch
93 def initialize(opts)
94 end
95 def retrieve_work
96 raise IOError, "ker-BOOM"
97 end
98 def self.bulk_requeue(*args)
99 end
100 end
101 end
102
0e19aee @mperham I'm a TDD master.
authored
103 end
c779018 @jakemack Implemented a strictly ordered queue switch
jakemack authored
104 end
Something went wrong with that request. Please try again.