sidekiq 3.5.0 → 3.5.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b52bf9136f69ca7203686496bcdf680f62013981
4
- data.tar.gz: 4ffaee1757a6f975e95789832d7f809f6224cd5e
3
+ metadata.gz: 92ef60dcba913bb8fdbb05e1c0a8dec0071146f3
4
+ data.tar.gz: 7c607121e01d8df3e83c09ab77876fde573cb1af
5
5
  SHA512:
6
- metadata.gz: 08a8a7b31a1f59c197c18b98c670d9991ee660397bdc09b6a5f06f73b885d5fc09e57de4d1ca60e7a2956e06e541a9245627367525d4b52f36be57040b362d79
7
- data.tar.gz: 75ad33dfa747d4d2a89bd98d2cabe601b99cc3a6085190361d134c3128d7faddfcbf182d5a278cf8cedb087ed5f0564bd7e839a1f9665a21777f31430c8264c9
6
+ metadata.gz: 980ecb9625038a8b0211d73ab6ac8176f6c7bf55c03da3c7e810016169ba76449ad43e602be337e1cc4d094aa2a9229ff565d37dd8bb6f094de62a34f61bc8e5
7
+ data.tar.gz: 420995af74088296a8ebf722f438be5b57f1a459acb0678956223d85341b8a4352a268da65b9ef4bcab3c275b5b66f7db3113fe75d6f52f6c1d2188a264d7867
data/COMM-LICENSE CHANGED
@@ -74,7 +74,7 @@ In no event will Contributed Systems' liability exceed the Software license pric
74
74
 
75
75
  13.1 Entire Agreement. This Agreement sets forth our entire agreement with respect to the Software and the subject matter hereof and supersedes all prior and contemporaneous understandings and agreements whether written or oral.
76
76
 
77
- 13.2 Amendment. Contributed Systems reserves the right, in its sole discretion, to amend this Agreement from time. Amendments to thie Agreement can be located at: https://github.com/mperham/sidekiq/blob/master/COMM-LICENSE.
77
+ 13.2 Amendment. Contributed Systems reserves the right, in its sole discretion, to amend this Agreement from time. Amendments to this Agreement can be located at: https://github.com/mperham/sidekiq/blob/master/COMM-LICENSE.
78
78
 
79
79
  13.3 Assignment. You may not assign this Agreement or any of its rights under this Agreement without the prior written consent of Contributed Systems and any attempted assignment without such consent shall be void.
80
80
 
data/Changes.md CHANGED
@@ -1,3 +1,11 @@
1
+ 3.5.1
2
+ -----------
3
+
4
+ - **FIX MEMORY LEAK** Under rare conditions, threads may leak [#2598]
5
+ - Add Ukranian locale [#2561, elrakita]
6
+ - Disconnect and retry Redis operations if we see a READONLY error [#2550]
7
+ - Add server middleware testing harness; see [wiki](https://github.com/mperham/sidekiq/wiki/Testing#testing-server-middleware) [#2534, ryansch]
8
+
1
9
  3.5.0
2
10
  -----------
3
11
 
@@ -401,7 +409,7 @@ middleware, see 3.0-Upgrade.md.**
401
409
  [Testing](https://github.com/mperham/sidekiq/wiki/Testing) for detail. [#1193]
402
410
  - The Retries table has a new column for the error message.
403
411
  - The Web UI topbar now contains the status and live poll button.
404
- - Orphaned worker records are now auto-vacuumed when you vist the
412
+ - Orphaned worker records are now auto-vacuumed when you visit the
405
413
  Workers page in the Web UI.
406
414
  - Sidekiq.default\_worker\_options allows you to configure default
407
415
  options for all Sidekiq worker types.
data/Ent-Changes.md CHANGED
@@ -3,6 +3,20 @@ Sidekiq Enterprise Changelog
3
3
 
4
4
  Please see [http://sidekiq.org/](http://sidekiq.org/) for more details and how to buy.
5
5
 
6
+ 0.7.3
7
+ ----------
8
+
9
+ - Rework `Sidekiq::Limiter` redis handling to match global redis handling.
10
+ - Allow user to customize rate limit backoff logic and handle custom
11
+ rate limit errors.
12
+ - Fix scalability issue with Limiter index page.
13
+
14
+
15
+ 0.7.2
16
+ ----------
17
+
18
+ - Fix typo which prevented limiters with '0' in their names.
19
+
6
20
  0.7.1
7
21
  ----------
8
22
 
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gemspec
4
4
  gem 'rails', '~> 4.2'
5
5
  gem 'simplecov'
6
6
  gem 'minitest'
7
+ gem 'toxiproxy'
7
8
 
8
9
  platforms :rbx do
9
10
  gem 'rubysl', '~> 2.0' # if using anything in the ruby standard library
data/Pro-Changes.md CHANGED
@@ -1,7 +1,18 @@
1
1
  Sidekiq Pro Changelog
2
2
  =======================
3
3
 
4
- Please see [http://sidekiq.org/pro](http://sidekiq.org/pro) for more details and how to buy.
4
+ Please see [http://sidekiq.org/](http://sidekiq.org/) for more details and how to buy.
5
+
6
+ 2.1.0
7
+ -----------
8
+
9
+ - Explicit support for sharding batches. You list your Redis shards and
10
+ Sidekiq Pro will randomly spread batches across the shards. The BID
11
+ will indicate which shard contains the batch data. Jobs within a
12
+ batch may be spread across all shards too. [#2548, jonhyman]
13
+ - Officially deprecate Sidekiq::Notifications code. Notifications have
14
+ been undocumented for months now. [#2575]
15
+
5
16
 
6
17
  2.0.8
7
18
  -----------
data/bin/sidekiqload ADDED
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Quiet some warnings we see when running in warning mode:
4
+ # RUBYOPT=-w bundle exec sidekiq
5
+ $TESTING = false
6
+ $CELLULOID_DEBUG = false
7
+
8
+ require 'celluloid/current'
9
+ puts Celluloid::VERSION
10
+ require_relative '../lib/sidekiq/cli'
11
+ require_relative '../lib/sidekiq/launcher'
12
+ Celluloid.logger = nil
13
+
14
+ include Sidekiq::Util
15
+
16
+ Sidekiq.configure_server do |config|
17
+ config.redis = { db: 13, port: 6380 }
18
+ config.options[:queues] << 'default'
19
+ config.logger.level = Logger::ERROR
20
+ config.average_scheduled_poll_interval = 2
21
+ end
22
+
23
+ class LoadWorker
24
+ include Sidekiq::Worker
25
+ sidekiq_options retry: 1
26
+ sidekiq_retry_in do |x|
27
+ 1
28
+ end
29
+
30
+ def perform(idx)
31
+ #raise idx.to_s if idx % 100 == 1
32
+ end
33
+ end
34
+
35
+ # brew tap shopify/shopify
36
+ # brew install toxiproxy
37
+ # gem install toxiproxy
38
+ require 'toxiproxy'
39
+ # simulate a non-localhost network for realer-world conditions.
40
+ # adding 1ms of network latency has an ENORMOUS impact on benchmarks
41
+ Toxiproxy.populate([{
42
+ "name": "redis",
43
+ "listen": "127.0.0.1:6380",
44
+ "upstream": "127.0.0.1:6379"
45
+ }])
46
+
47
+ self_read, self_write = IO.pipe
48
+ %w(INT TERM USR1 USR2 TTIN).each do |sig|
49
+ begin
50
+ trap sig do
51
+ self_write.puts(sig)
52
+ end
53
+ rescue ArgumentError
54
+ puts "Signal #{sig} not supported"
55
+ end
56
+ end
57
+
58
+ Sidekiq.redis {|c| c.flushdb}
59
+ def handle_signal(launcher, sig)
60
+ Sidekiq.logger.debug "Got #{sig} signal"
61
+ case sig
62
+ when 'INT'
63
+ # Handle Ctrl-C in JRuby like MRI
64
+ # http://jira.codehaus.org/browse/JRUBY-4637
65
+ raise Interrupt
66
+ when 'TERM'
67
+ # Heroku sends TERM and then waits 10 seconds for process to exit.
68
+ raise Interrupt
69
+ when 'USR1'
70
+ Sidekiq.logger.info "Received USR1, no longer accepting new work"
71
+ launcher.manager.async.stop
72
+ #fire_event(:quiet, true)
73
+ when 'USR2'
74
+ if Sidekiq.options[:logfile]
75
+ Sidekiq.logger.info "Received USR2, reopening log file"
76
+ Sidekiq::Logging.reopen_logs
77
+ end
78
+ when 'TTIN'
79
+ Thread.list.each do |thread|
80
+ Sidekiq.logger.warn "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
81
+ if thread.backtrace
82
+ Sidekiq.logger.warn thread.backtrace.join("\n")
83
+ else
84
+ Sidekiq.logger.warn "<no backtrace available>"
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ def Process.rss
91
+ `ps -o rss= -p #{Process.pid}`.chomp.to_i
92
+ end
93
+
94
+ iter = 10
95
+ count = 10_000
96
+
97
+ iter.times do
98
+ arr = Array.new(count) do
99
+ []
100
+ end
101
+ count.times do |idx|
102
+ arr[idx][0] = idx
103
+ end
104
+ Sidekiq::Client.push_bulk('class' => LoadWorker, 'args' => arr)
105
+ end
106
+ Sidekiq.logger.error "Created #{count*iter} jobs"
107
+
108
+ Monitoring = Thread.new do
109
+ watchdog("monitor thread") do
110
+ while true
111
+ sleep 2
112
+ qsize, retries = Sidekiq.redis do |conn|
113
+ conn.pipelined do
114
+ conn.llen "queue:default"
115
+ conn.zcard "retry"
116
+ end
117
+ end.map(&:to_i)
118
+ total = qsize + retries
119
+ #GC.start
120
+ Sidekiq.logger.error("RSS: #{Process.rss} Pending: #{total}")
121
+ if total == 0
122
+ Sidekiq.logger.error("Done")
123
+ exit(0)
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ begin
130
+ #RubyProf::exclude_threads = [ Monitoring ]
131
+ #RubyProf.start
132
+ Sidekiq.logger.error "Simulating 1ms of latency between Sidekiq and redis"
133
+ Toxiproxy[:redis].downstream(:latency, latency: 1).apply do
134
+ launcher = Sidekiq::Launcher.new(Sidekiq.options)
135
+ launcher.run
136
+
137
+ while readable_io = IO.select([self_read])
138
+ signal = readable_io.first[0].gets.strip
139
+ handle_signal(launcher, signal)
140
+ end
141
+ end
142
+ rescue SystemExit => e
143
+ #Sidekiq.logger.error("Profiling...")
144
+ #result = RubyProf.stop
145
+ #printer = RubyProf::GraphHtmlPrinter.new(result)
146
+ #printer.print(File.new("output.html", "w"), :min_percent => 1)
147
+ # normal
148
+ rescue => e
149
+ raise e if $DEBUG
150
+ STDERR.puts e.message
151
+ STDERR.puts e.backtrace.join("\n")
152
+ exit 1
153
+ end
data/lib/sidekiq.rb CHANGED
@@ -76,9 +76,19 @@ module Sidekiq
76
76
  defined?(Sidekiq::CLI)
77
77
  end
78
78
 
79
- def self.redis(&block)
80
- raise ArgumentError, "requires a block" unless block
81
- redis_pool.with(&block)
79
+ def self.redis
80
+ raise ArgumentError, "requires a block" unless block_given?
81
+ redis_pool.with do |conn|
82
+ retryable = true
83
+ begin
84
+ yield conn
85
+ rescue Redis::CommandError => ex
86
+ #2550 Failover can cause the server to become a slave, need
87
+ # to disconnect and reopen the socket to get back to the master.
88
+ (conn.disconnect!; retryable = false; retry) if retryable && ex.message =~ /READONLY/
89
+ raise
90
+ end
91
+ end
82
92
  end
83
93
 
84
94
  def self.redis_pool
data/lib/sidekiq/cli.rb CHANGED
@@ -105,16 +105,16 @@ module Sidekiq
105
105
  %q{
106
106
  m,
107
107
  `$b
108
- .ss, $$b .,d$
109
- `$$P,d$P' .,md$$P' ____ _ _ _ _
110
- ,$$$$$$bmmd$$$^' / ___|(_) __| | ___| | _(_) __ _
111
- ,d$$$$$$$$$$$P \___ \| |/ _` |/ _ \ |/ / |/ _` |
112
- $s^' `"^$$$' ___) | | (_| | __/ <| | (_| |
113
- $: ,$$P |____/|_|\__,_|\___|_|\_\_|\__, |
114
- `b :$$ |_|
115
- $$:
116
- $$
117
- .d$$
108
+ .ss, $$: .,d$
109
+ `$$P,d$P' .,md$P"'
110
+ ,$$$$$bmmd$$$P^'
111
+ .d$$$$$$$$$$P'
112
+ $$^' `"^$$$' ____ _ _ _ _
113
+ $: ,$$: / ___|(_) __| | ___| | _(_) __ _
114
+ `b :$$ \___ \| |/ _` |/ _ \ |/ / |/ _` |
115
+ $$: ___) | | (_| | __/ <| | (_| |
116
+ $$ |____/|_|\__,_|\___|_|\_\_|\__, |
117
+ .d$$ |_|
118
118
  }
119
119
  end
120
120
 
@@ -132,7 +132,7 @@ module Sidekiq
132
132
  # get handle to the underlying thread performing work for a processor
133
133
  # so we have it call us and tell us.
134
134
  def real_thread(proxy_id, thr)
135
- @threads[proxy_id] = thr
135
+ @threads[proxy_id] = thr if thr.alive?
136
136
  end
137
137
 
138
138
  PROCTITLES = [
@@ -181,7 +181,7 @@ module Sidekiq
181
181
 
182
182
  def retry_in(worker, count)
183
183
  begin
184
- worker.sidekiq_retry_in_block.call(count)
184
+ worker.sidekiq_retry_in_block.call(count).to_i
185
185
  rescue Exception => e
186
186
  handle_exception(e, { context: "Failure scheduling retry using the defined `sidekiq_retry_in` in #{worker.class.name}, falling back to default" })
187
187
  nil
@@ -40,18 +40,23 @@ module Sidekiq
40
40
 
41
41
  @boss.async.real_thread(proxy_id, Thread.current)
42
42
 
43
- ack = true
43
+ ack = false
44
44
  begin
45
45
  msg = Sidekiq.load_json(msgstr)
46
- klass = msg['class'].constantize
46
+ klass = msg['class'.freeze].constantize
47
47
  worker = klass.new
48
- worker.jid = msg['jid']
48
+ worker.jid = msg['jid'.freeze]
49
49
 
50
50
  stats(worker, msg, queue) do
51
51
  Sidekiq.server_middleware.invoke(worker, msg, queue) do
52
- execute_job(worker, cloned(msg['args']))
52
+ # Only ack if we either attempted to start this job or
53
+ # successfully completed it. This prevents us from
54
+ # losing jobs if a middleware raises an exception before yielding
55
+ ack = true
56
+ execute_job(worker, cloned(msg['args'.freeze]))
53
57
  end
54
58
  end
59
+ ack = true
55
60
  rescue Sidekiq::Shutdown
56
61
  # Had to force kill this job because it didn't finish
57
62
  # within the timeout. Don't acknowledge the work since
@@ -94,14 +99,15 @@ module Sidekiq
94
99
  end
95
100
  end
96
101
 
102
+ nowdate = Time.now.utc.strftime("%Y-%m-%d".freeze)
97
103
  begin
98
104
  yield
99
105
  rescue Exception
100
106
  retry_and_suppress_exceptions do
101
- failed = "stat:failed:#{Time.now.utc.to_date}"
107
+ failed = "stat:failed:#{nowdate}"
102
108
  Sidekiq.redis do |conn|
103
109
  conn.multi do
104
- conn.incrby("stat:failed", 1)
110
+ conn.incrby("stat:failed".freeze, 1)
105
111
  conn.incrby(failed, 1)
106
112
  conn.expire(failed, STATS_TIMEOUT)
107
113
  end
@@ -110,11 +116,11 @@ module Sidekiq
110
116
  raise
111
117
  ensure
112
118
  retry_and_suppress_exceptions do
113
- processed = "stat:processed:#{Time.now.utc.to_date}"
119
+ processed = "stat:processed:#{nowdate}"
114
120
  Sidekiq.redis do |conn|
115
121
  conn.multi do
116
122
  conn.hdel("#{identity}:workers", thread_identity)
117
- conn.incrby("stat:processed", 1)
123
+ conn.incrby("stat:processed".freeze, 1)
118
124
  conn.incrby(processed, 1)
119
125
  conn.expire(processed, STATS_TIMEOUT)
120
126
  end
@@ -48,6 +48,12 @@ module Sidekiq
48
48
  def inline?
49
49
  self.__test_mode == :inline
50
50
  end
51
+
52
+ def server_middleware
53
+ @server_chain ||= Middleware::Chain.new
54
+ yield @server_chain if block_given?
55
+ @server_chain
56
+ end
51
57
  end
52
58
  end
53
59
 
@@ -150,10 +156,7 @@ module Sidekiq
150
156
  # Drain and run all jobs for this worker
151
157
  def drain
152
158
  while job = jobs.shift do
153
- worker = new
154
- worker.jid = job['jid']
155
- worker.bid = job['bid'] if worker.respond_to?(:bid=)
156
- execute_job(worker, job['args'])
159
+ process_job(job)
157
160
  end
158
161
  end
159
162
 
@@ -161,10 +164,16 @@ module Sidekiq
161
164
  def perform_one
162
165
  raise(EmptyQueueError, "perform_one called with empty job queue") if jobs.empty?
163
166
  job = jobs.shift
167
+ process_job(job)
168
+ end
169
+
170
+ def process_job(job)
164
171
  worker = new
165
172
  worker.jid = job['jid']
166
173
  worker.bid = job['bid'] if worker.respond_to?(:bid=)
167
- execute_job(worker, job['args'])
174
+ Sidekiq::Testing.server_middleware.invoke(worker, job, job['queue']) do
175
+ execute_job(worker, job['args'])
176
+ end
168
177
  end
169
178
 
170
179
  def execute_job(worker, args)
@@ -1,3 +1,3 @@
1
1
  module Sidekiq
2
- VERSION = "3.5.0"
2
+ VERSION = "3.5.1"
3
3
  end
data/sidekiq.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency 'redis', '~> 3.2', '>= 3.2.1'
19
19
  gem.add_dependency 'redis-namespace', '~> 1.5', '>= 1.5.2'
20
20
  gem.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.0'
21
- gem.add_dependency 'celluloid', '~> 0.17.0'
21
+ gem.add_dependency 'celluloid', '~> 0.17.2'
22
22
  gem.add_dependency 'json', '~> 1.0'
23
23
  gem.add_development_dependency 'sinatra', '~> 1.4', '>= 1.4.6'
24
24
  gem.add_development_dependency 'minitest', '~> 5.7', '>= 5.7.0'
data/test/test_api.rb CHANGED
@@ -3,23 +3,16 @@ require_relative 'helper'
3
3
  class TestApi < Sidekiq::Test
4
4
 
5
5
  describe "stats" do
6
- before do
7
- @before = DateTime::DATE_FORMATS[:default]
8
- DateTime::DATE_FORMATS[:default] = "%d/%m/%Y %H:%M:%S"
9
- Sidekiq.redis = REDIS
10
- Sidekiq.redis {|c| c.flushdb }
11
- end
12
6
 
13
- after do
14
- DateTime::DATE_FORMATS[:default] = @before
7
+ it "is initially zero" do
8
+ Sidekiq.redis {|c| c.flushdb }
9
+ s = Sidekiq::Stats.new
10
+ assert_equal 0, s.processed
11
+ assert_equal 0, s.failed
12
+ assert_equal 0, s.enqueued
15
13
  end
16
14
 
17
15
  describe "processed" do
18
- it "is initially zero" do
19
- s = Sidekiq::Stats.new
20
- assert_equal 0, s.processed
21
- end
22
-
23
16
  it "returns number of processed jobs" do
24
17
  Sidekiq.redis { |conn| conn.set("stat:processed", 5) }
25
18
  s = Sidekiq::Stats.new
@@ -28,11 +21,6 @@ class TestApi < Sidekiq::Test
28
21
  end
29
22
 
30
23
  describe "failed" do
31
- it "is initially zero" do
32
- s = Sidekiq::Stats.new
33
- assert_equal 0, s.failed
34
- end
35
-
36
24
  it "returns number of failed jobs" do
37
25
  Sidekiq.redis { |conn| conn.set("stat:failed", 5) }
38
26
  s = Sidekiq::Stats.new
@@ -50,40 +38,36 @@ class TestApi < Sidekiq::Test
50
38
 
51
39
  it 'will reset all stats by default' do
52
40
  Sidekiq::Stats.new.reset
53
- Sidekiq.redis do |conn|
54
- assert_equal '0', conn.get('stat:processed')
55
- assert_equal '0', conn.get('stat:failed')
56
- end
41
+ s = Sidekiq::Stats.new
42
+ assert_equal 0, s.failed
43
+ assert_equal 0, s.processed
57
44
  end
58
45
 
59
46
  it 'can reset individual stats' do
60
47
  Sidekiq::Stats.new.reset('failed')
61
- Sidekiq.redis do |conn|
62
- assert_equal '5', conn.get('stat:processed')
63
- assert_equal '0', conn.get('stat:failed')
64
- end
48
+ s = Sidekiq::Stats.new
49
+ assert_equal 0, s.failed
50
+ assert_equal 5, s.processed
65
51
  end
66
52
 
67
53
  it 'can accept anything that responds to #to_s' do
68
54
  Sidekiq::Stats.new.reset(:failed)
69
- Sidekiq.redis do |conn|
70
- assert_equal '5', conn.get('stat:processed')
71
- assert_equal '0', conn.get('stat:failed')
72
- end
55
+ s = Sidekiq::Stats.new
56
+ assert_equal 0, s.failed
57
+ assert_equal 5, s.processed
73
58
  end
74
59
 
75
60
  it 'ignores anything other than "failed" or "processed"' do
76
61
  Sidekiq::Stats.new.reset((1..10).to_a, ['failed'])
77
- Sidekiq.redis do |conn|
78
- assert_equal '5', conn.get('stat:processed')
79
- assert_equal '0', conn.get('stat:failed')
80
- end
62
+ s = Sidekiq::Stats.new
63
+ assert_equal 0, s.failed
64
+ assert_equal 5, s.processed
81
65
  end
82
66
  end
83
67
 
84
68
  describe "queues" do
85
- it "returns all queues" do
86
- assert_equal Sidekiq::Stats.new.queues, Sidekiq::Stats::Queues.new.lengths
69
+ before do
70
+ Sidekiq.redis {|c| c.flushdb }
87
71
  end
88
72
 
89
73
  it "is initially empty" do
@@ -103,17 +87,15 @@ class TestApi < Sidekiq::Test
103
87
  s = Sidekiq::Stats::Queues.new
104
88
  assert_equal ({ "foo" => 1, "bar" => 3 }), s.lengths
105
89
  assert_equal "bar", s.lengths.first.first
90
+
91
+ assert_equal Sidekiq::Stats.new.queues, Sidekiq::Stats::Queues.new.lengths
106
92
  end
107
93
  end
108
94
 
109
95
  describe "enqueued" do
110
- it "is initially empty" do
111
- s = Sidekiq::Stats.new
112
- assert_equal 0, s.enqueued
113
- end
114
-
115
96
  it "returns total enqueued jobs" do
116
97
  Sidekiq.redis do |conn|
98
+ conn.flushdb
117
99
  conn.rpush 'queue:foo', '{}'
118
100
  conn.sadd 'queues', 'foo'
119
101
 
@@ -127,6 +109,15 @@ class TestApi < Sidekiq::Test
127
109
  end
128
110
 
129
111
  describe "over time" do
112
+ before do
113
+ @before = DateTime::DATE_FORMATS[:default]
114
+ DateTime::DATE_FORMATS[:default] = "%d/%m/%Y %H:%M:%S"
115
+ end
116
+
117
+ after do
118
+ DateTime::DATE_FORMATS[:default] = @before
119
+ end
120
+
130
121
  describe "processed" do
131
122
  it 'retrieves hash of dates' do
132
123
  Sidekiq.redis do |c|
@@ -137,13 +128,13 @@ class TestApi < Sidekiq::Test
137
128
  end
138
129
  Time.stub(:now, Time.parse("2012-12-26 1:00:00 -0500")) do
139
130
  s = Sidekiq::Stats::History.new(2)
140
- assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1 }), s.processed
131
+ assert_equal({ "2012-12-26" => 6, "2012-12-25" => 1 }, s.processed)
141
132
 
142
133
  s = Sidekiq::Stats::History.new(3)
143
- assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1, "2012-12-24" => 4 }), s.processed
134
+ assert_equal({ "2012-12-26" => 6, "2012-12-25" => 1, "2012-12-24" => 4 }, s.processed)
144
135
 
145
136
  s = Sidekiq::Stats::History.new(2, Date.parse("2012-12-25"))
146
- assert_equal ({ "2012-12-25" => 1, "2012-12-24" => 4 }), s.processed
137
+ assert_equal({ "2012-12-25" => 1, "2012-12-24" => 4 }, s.processed)
147
138
  end
148
139
  end
149
140
  end
@@ -172,10 +163,7 @@ class TestApi < Sidekiq::Test
172
163
  end
173
164
 
174
165
  describe 'with an empty database' do
175
- include Sidekiq::Util
176
-
177
166
  before do
178
- Sidekiq.redis = REDIS
179
167
  Sidekiq.redis {|c| c.flushdb }
180
168
  end
181
169
 
@@ -389,7 +377,7 @@ class TestApi < Sidekiq::Test
389
377
  identity_string = "identity_string"
390
378
  odata = {
391
379
  'pid' => 123,
392
- 'hostname' => hostname,
380
+ 'hostname' => Socket.gethostname,
393
381
  'key' => identity_string,
394
382
  'identity' => identity_string,
395
383
  'started_at' => Time.now.to_f - 15,
@@ -424,8 +412,9 @@ class TestApi < Sidekiq::Test
424
412
  assert false
425
413
  end
426
414
 
427
- key = "#{hostname}:#{$$}"
428
- pdata = { 'pid' => $$, 'hostname' => hostname, 'started_at' => Time.now.to_i }
415
+ hn = Socket.gethostname
416
+ key = "#{hn}:#{$$}"
417
+ pdata = { 'pid' => $$, 'hostname' => hn, 'started_at' => Time.now.to_i }
429
418
  Sidekiq.redis do |conn|
430
419
  conn.sadd('processes', key)
431
420
  conn.hmset(key, 'info', Sidekiq.dump_json(pdata), 'busy', 0, 'beat', Time.now.to_f)