1
0
Fork 0
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:
Mike Perham 2022-07-14 16:05:25 -07:00
parent a80a6d064a
commit 6efebec90f
4 changed files with 9 additions and 11 deletions

View file

@ -153,17 +153,17 @@ module Sidekiq
# '2.1.1.1' < '192.168.0.2' < '192.168.0.10'
def sorted_processes
@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|
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'
# 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)
end

View file

@ -106,7 +106,6 @@ describe Sidekiq::Processor do
end
assert_equal 1, errors.count
assert_instance_of TestProcessorException, errors.first[:exception]
assert_equal msg, errors.first[:context][:jobstr]
assert_equal job_hash["jid"], errors.first[:context][:job]["jid"]
end
@ -122,7 +121,6 @@ describe Sidekiq::Processor do
end
assert_equal 1, errors.count
assert_instance_of TestProcessorException, errors.first[:exception]
assert_equal msg, errors.first[:context][:jobstr]
assert_equal job_hash, errors.first[:context][:job]
end

View file

@ -294,7 +294,7 @@ describe Sidekiq::JobRetry do
it "retries with a default delay" do
strat, count = handler.__send__(:delay_for, worker, 2, StandardError.new)
assert_equal :default, strat
refute_equal 4, count
refute_equal 4, count
end
it "retries with a custom delay and exception 1" do

View file

@ -131,8 +131,8 @@ describe "Web helpers" do
end
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|
pdata = { "hostname" => hostname, "pid" => '123', "started_at" => Time.now.to_i }
["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}
key = "#{hostname}:123"
Sidekiq.redis do |conn|
@ -144,6 +144,6 @@ describe "Web helpers" do
obj = Helpers.new
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