1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

fix 5514 - handle consecutive delimiters in hostnames while sorting them (#5515)

This commit is contained in:
Vikram B Kumar 2022-09-08 10:29:31 -04:00 committed by GitHub
parent f3e0640a79
commit 6fc666644e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -155,7 +155,7 @@ module Sidekiq
@sorted_processes ||= begin
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

View file

@ -131,7 +131,7 @@ 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|
["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"
@ -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