mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
fix broken tests
This commit is contained in:
parent
a80a6d064a
commit
6efebec90f
4 changed files with 9 additions and 11 deletions
|
@ -153,17 +153,17 @@ module Sidekiq
|
||||||
# '2.1.1.1' < '192.168.0.2' < '192.168.0.10'
|
# '2.1.1.1' < '192.168.0.2' < '192.168.0.10'
|
||||||
def sorted_processes
|
def sorted_processes
|
||||||
@sorted_processes ||= begin
|
@sorted_processes ||= begin
|
||||||
return processes unless processes.all? { |p| p['hostname'] }
|
return processes unless processes.all? { |p| p["hostname"] }
|
||||||
|
|
||||||
split_characters = /[\._-]/
|
split_characters = /[._-]/
|
||||||
|
|
||||||
padding = processes.flat_map { |p| p['hostname'].split(split_characters) }.map(&:size).max
|
padding = processes.flat_map { |p| p["hostname"].split(split_characters) }.map(&:size).max
|
||||||
|
|
||||||
processes.to_a.sort_by do |process|
|
processes.to_a.sort_by do |process|
|
||||||
process['hostname'].split(split_characters).map do |substring|
|
process["hostname"].split(split_characters).map do |substring|
|
||||||
# Left-pad the substring with '0' if it starts with a number or 'a'
|
# Left-pad the substring with '0' if it starts with a number or 'a'
|
||||||
# otherwise, so that '25' < 192' < 'a' ('025' < '192' < 'aaa')
|
# otherwise, so that '25' < 192' < 'a' ('025' < '192' < 'aaa')
|
||||||
padding_char = substring.chars.first.match?(/\d/) ? '0' : 'a'
|
padding_char = substring[0].match?(/\d/) ? "0" : "a"
|
||||||
|
|
||||||
substring.rjust(padding, padding_char)
|
substring.rjust(padding, padding_char)
|
||||||
end
|
end
|
||||||
|
|
|
@ -106,7 +106,6 @@ describe Sidekiq::Processor do
|
||||||
end
|
end
|
||||||
assert_equal 1, errors.count
|
assert_equal 1, errors.count
|
||||||
assert_instance_of TestProcessorException, errors.first[:exception]
|
assert_instance_of TestProcessorException, errors.first[:exception]
|
||||||
assert_equal msg, errors.first[:context][:jobstr]
|
|
||||||
assert_equal job_hash["jid"], errors.first[:context][:job]["jid"]
|
assert_equal job_hash["jid"], errors.first[:context][:job]["jid"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,7 +121,6 @@ describe Sidekiq::Processor do
|
||||||
end
|
end
|
||||||
assert_equal 1, errors.count
|
assert_equal 1, errors.count
|
||||||
assert_instance_of TestProcessorException, errors.first[:exception]
|
assert_instance_of TestProcessorException, errors.first[:exception]
|
||||||
assert_equal msg, errors.first[:context][:jobstr]
|
|
||||||
assert_equal job_hash, errors.first[:context][:job]
|
assert_equal job_hash, errors.first[:context][:job]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -131,8 +131,8 @@ describe "Web helpers" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sorts processes using the natural sort order" do
|
it "sorts processes using the natural sort order" do
|
||||||
['a.10.2', 'a.2', 'busybee-10_1', 'a.23', 'a.10.1', 'a.1', '192.168.0.10', '192.168.0.2', '2.1.1.1', 'busybee-2_34'].each do |hostname|
|
["a.10.2", "a.2", "busybee-10_1", "a.23", "a.10.1", "a.1", "192.168.0.10", "192.168.0.2", "2.1.1.1", "busybee-2_34"].each do |hostname|
|
||||||
pdata = { "hostname" => hostname, "pid" => '123', "started_at" => Time.now.to_i }
|
pdata = {"hostname" => hostname, "pid" => "123", "started_at" => Time.now.to_i}
|
||||||
key = "#{hostname}:123"
|
key = "#{hostname}:123"
|
||||||
|
|
||||||
Sidekiq.redis do |conn|
|
Sidekiq.redis do |conn|
|
||||||
|
@ -144,6 +144,6 @@ describe "Web helpers" do
|
||||||
obj = Helpers.new
|
obj = Helpers.new
|
||||||
|
|
||||||
assert obj.sorted_processes.all? { |process| assert_instance_of Sidekiq::Process, process }
|
assert obj.sorted_processes.all? { |process| assert_instance_of Sidekiq::Process, process }
|
||||||
assert_equal ['2.1.1.1', '192.168.0.2', '192.168.0.10', 'a.1', 'a.2', 'a.10.1', 'a.10.2', 'a.23', 'busybee-2_34', 'busybee-10_1'], obj.sorted_processes.map { |process| process['hostname'] }
|
assert_equal ["2.1.1.1", "192.168.0.2", "192.168.0.10", "a.1", "a.2", "a.10.1", "a.10.2", "a.23", "busybee-2_34", "busybee-10_1"], obj.sorted_processes.map { |process| process["hostname"] }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue