From 6efebec90fde64b0de4ea2a937024d24e2daaa73 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Thu, 14 Jul 2022 16:05:25 -0700 Subject: [PATCH] fix broken tests --- lib/sidekiq/web/helpers.rb | 10 +++++----- test/test_processor.rb | 2 -- test/test_retry.rb | 2 +- test/test_web_helpers.rb | 6 +++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/sidekiq/web/helpers.rb b/lib/sidekiq/web/helpers.rb index d87de3ec..6756e612 100644 --- a/lib/sidekiq/web/helpers.rb +++ b/lib/sidekiq/web/helpers.rb @@ -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 diff --git a/test/test_processor.rb b/test/test_processor.rb index b5b0142e..a52a0db3 100644 --- a/test/test_processor.rb +++ b/test/test_processor.rb @@ -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 diff --git a/test/test_retry.rb b/test/test_retry.rb index 777050ab..650cbd52 100644 --- a/test/test_retry.rb +++ b/test/test_retry.rb @@ -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 diff --git a/test/test_web_helpers.rb b/test/test_web_helpers.rb index 8856b435..dfdf7353 100644 --- a/test/test_web_helpers.rb +++ b/test/test_web_helpers.rb @@ -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