Skip to content

Commit

Permalink
Fix tests after upgrading tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlledom committed Oct 24, 2023
1 parent d468417 commit de032a9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 41 deletions.
5 changes: 4 additions & 1 deletion features/support/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
require 'sidekiq/batch'

# Turn off Sidekiq logging which pollutes the CI logs
Sidekiq.logger = Sidekiq::Logger.new(nil, level: Logger::FATAL)
Sidekiq.configure_client do |config|
config.logger = Sidekiq::Logger.new(nil, level: Logger::FATAL)
end

Sidekiq::Testing.inline!

module Sidekiq
Expand Down
6 changes: 4 additions & 2 deletions test/test_helpers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
require 'sidekiq/lock/testing/inline'

# Turn off Sidekiq logging which pollutes the CI logs
Sidekiq.logger = Sidekiq::Logger.new(nil, level: Logger::FATAL)
Sidekiq.strict_args! # Fail if parameters are not valid JSON
Sidekiq.configure_client do |config|
config.logger = Sidekiq::Logger.new(nil, level: Logger::FATAL)
end

module TestHelpers
module Sidekiq
def self.included(base)
Expand Down
6 changes: 2 additions & 4 deletions test/unit/backend/storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def given_redis_config(yaml)
}
given_redis_config(yaml) do
mock = mock(id: 'redis://localhost:6389/1')
Redis::Client.expects(:new).with(host: 'example.com', port: 1337, db: 2, logger: Rails.logger).returns(mock)
Redis.expects(:new).with(host: 'example.com', port: 1337, db: 2).returns(mock)

storage = Backend::Storage.clone.instance
assert_equal 'redis://localhost:6389/1', storage.id
Expand All @@ -39,9 +39,7 @@ def given_redis_config(yaml)
db: 2
}
given_redis_config(yaml) do
assert_equal({ :logger => Rails.logger,
:host => 'example.com', :port => 1337, :db => 2 },
Backend::Storage.parse_config )
assert_equal({ :host => 'example.com', :port => 1337, :db => 2 }, Backend::Storage.parse_config )
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/unit/redis_connection_error_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'test_helper'

class RedisConnectionErrorTest < ActiveSupport::TestCase
test 'Name or service not known' do
redis_config = ThreeScale::RedisConfig.new(
url: 'redis://mymaster',
sentinels: 'invalid_host:26380,other_invalid_host:26381',
role: :master
).config

redis = Redis.new(redis_config)

exception = assert_raises(RedisClient::CannotConnectError) { redis._client.send(:connect) }
assert_equal 'No sentinels available', exception.message
end
end
33 changes: 0 additions & 33 deletions test/unit/redis_hacks_test.rb

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/system/redis_pool_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class System::RedisPoolTest < ActiveSupport::TestCase
ConnectionPool.expects(:new).with(timeout: 5, size: 5).at_least_once
pool = System::RedisPool.new
ConnectionPool.expects(:new).with(size: 3, timeout: 7).at_least_once
pool = System::RedisPool.new(pool_size: 3, pool_timeout: 7)
pool = System::RedisPool.new(size: 3, pool_timeout: 7)
end

test 'delegation' do
Expand Down
7 changes: 7 additions & 0 deletions test/unit/three_scale/redis_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@ class RedisConfigTest < ActiveSupport::TestCase
]
assert_equal expected_sentinels, config.sentinels
end

test ':pool_size is renamed to :size' do
config = RedisConfig.new(pool_size: 5)

assert config.key? :size
assert_equal 5, config[:size]
end
end
end

0 comments on commit de032a9

Please sign in to comment.