Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlledom committed Oct 25, 2023
1 parent 08e5a3b commit be9c1e6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
6 changes: 3 additions & 3 deletions spec/unit/queue_storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ module Backend
private

def is_sentinel?(connection)
connector = connection.instance_variable_get(:@inner)
config = connection.instance_variable_get(:@inner)
.instance_variable_get(:@client)
.instance_variable_get(:@connector)
.instance_variable_get(:@config)

connector.instance_of?(Redis::Client::Connector::Sentinel)
!!config&.sentinel?
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/stats/cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ module Stats
it 'deletes only the stats of services marked to be deleted' do
Cleaner.delete!(non_proxied_instances)

expect(keys_not_to_be_deleted.keys.all? { |key| storage.exists(key) })
expect(keys_not_to_be_deleted.keys.all? { |key| storage.exists?(key) })
.to be true

expect(keys_to_be_deleted.keys.none? { |key| storage.exists(key) })
expect(keys_to_be_deleted.keys.none? { |key| storage.exists?(key) })
.to be true
end

Expand All @@ -94,7 +94,7 @@ module Stats
before { storage.del(redis_set_marked_to_be_deleted) }

it 'does not delete any keys' do
expect(all_keys.keys.all? {|key| storage.exists(key) })
expect(all_keys.keys.all? {|key| storage.exists?(key) })
end
end

Expand All @@ -120,10 +120,10 @@ module Stats
it 'deletes only the stats of services marked to be deleted' do
Cleaner.delete!(non_proxied_instances, log_deleted_keys: log_to)

expect(keys_not_to_be_deleted.keys.all? { |key| storage.exists(key) })
expect(keys_not_to_be_deleted.keys.all? { |key| storage.exists?(key) })
.to be true

expect(keys_to_be_deleted.keys.none? { |key| storage.exists(key) })
expect(keys_to_be_deleted.keys.none? { |key| storage.exists?(key) })
.to be true
end

Expand Down Expand Up @@ -180,17 +180,17 @@ module Stats

it 'deletes the stats with usage 0' do
Cleaner.delete_stats_keys_set_to_0(non_proxied_instances)
expect(stats_with_usage_0.keys.none? { |k| storage.exists(k) }).to be true
expect(stats_with_usage_0.keys.none? { |k| storage.exists?(k) }).to be true
end

it 'does not delete the stats with usage != 0' do
Cleaner.delete_stats_keys_set_to_0(non_proxied_instances)
expect(stats_with_non_zero_usage.keys.all? { |k| storage.exists(k) }). to be true
expect(stats_with_non_zero_usage.keys.all? { |k| storage.exists?(k) }). to be true
end

it 'does not delete non-stats keys' do
Cleaner.delete_stats_keys_set_to_0(non_proxied_instances)
expect(non_stats_keys.keys.all? { |k| storage.exists(k) }).to be true
expect(non_stats_keys.keys.all? { |k| storage.exists?(k) }).to be true
end

context 'with the option to log deleted keys enabled' do
Expand Down
2 changes: 1 addition & 1 deletion test/integration/authrep/basic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def setup
assert_equal 200, last_response.status

# 'Hits' was 0, so there shouldn't be a stats key for it.
hits_key_created = @storage.exists(
hits_key_created = @storage.exists?(
application_key(
@service_id,
@application.id,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/authrep/set_usage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def setup
end

stats_keys = app_keys_for_all_periods(@service_id, @application.id, hits_id, current_time)
stats_keys_created = stats_keys.any? { |key| @storage.exists(key) }
stats_keys_created = stats_keys.any? { |key| @storage.exists?(key) }
assert_false stats_keys_created
end

Expand Down Expand Up @@ -304,7 +304,7 @@ def setup
end

stats_keys = app_keys_for_all_periods(@service_id, @application.id, hits_id, current_time)
stats_keys_created = stats_keys.any? { |key| @storage.exists(key) }
stats_keys_created = stats_keys.any? { |key| @storage.exists?(key) }
assert_false stats_keys_created
end
end
6 changes: 3 additions & 3 deletions test/integration/report_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def setup
assert_equal 202, last_response.status

# 'Hits' was 0, so there shouldn't be a stats key for it.
hits_key_created = @storage.exists(
hits_key_created = @storage.exists?(
application_key(
@service_id,
@application.id,
Expand Down Expand Up @@ -331,7 +331,7 @@ def setup
assert_equal 202, last_response.status

stats_keys = app_keys_for_all_periods(@service_id, @application.id, hits_id, current_time)
stats_keys_created = stats_keys.any? { |key| @storage.exists(key) }
stats_keys_created = stats_keys.any? { |key| @storage.exists?(key) }
assert_false stats_keys_created
end

Expand Down Expand Up @@ -371,7 +371,7 @@ def setup
assert_equal 202, last_response.status

stats_keys = app_keys_for_all_periods(@service_id, @application.id, hits_id, current_time)
stats_keys_created = stats_keys.any? { |key| @storage.exists(key) }
stats_keys_created = stats_keys.any? { |key| @storage.exists?(key) }
assert_false stats_keys_created
end

Expand Down
8 changes: 4 additions & 4 deletions test/test_helpers/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ def flushall
end
end

def method_missing(m, *args, &blk)
def method_missing(m, *args, **kwargs, &blk)
# define and delegate the missing method
self.class.send(:define_method, m) do |*a, &b|
inner.send(m, *a, &b)
self.class.send(:define_method, m) do |*a, **kwa, &b|
inner.send(m, *a, **kwa, &b)
end
inner.send(m, *args, &blk)
inner.send(m, *args, **kwargs, &blk)
end

def respond_to_missing?(m)
Expand Down
37 changes: 20 additions & 17 deletions test/unit/storage_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_sentinels_connection_string
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: [{ host: '127.0.0.1', port: 26_379 },
{ host: '127.0.0.1', port: 36_379 }])
Expand All @@ -62,7 +62,7 @@ def test_sentinels_connection_string_escaped
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: [{ host: '127.0.0.1', port: 26_379, password: 'passw,ord' },
{ host: '127.0.0.1', port: 36_379 }])
Expand All @@ -75,7 +75,7 @@ def test_sentinels_connection_array_strings
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: [{ host: '127.0.0.1', port: 26_379 },
{ host: '127.0.0.1', port: 36_379 }])
Expand All @@ -91,7 +91,7 @@ def test_sentinels_connection_array_hashes
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: config_obj[:sentinels].compact.reject(&:empty?))
end
Expand All @@ -113,7 +113,7 @@ def test_sentinels_simple_url
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: "redis://#{config_obj[:url]}",
sentinels: [{ host: '127.0.0.1', port: 26_379 }])
end
Expand All @@ -128,7 +128,7 @@ def test_sentinels_array_hashes_default_port
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: [{ host: '127.0.0.1', port: default_sentinel_port },
{ host: '192.168.1.1', port: default_sentinel_port },
Expand All @@ -146,7 +146,7 @@ def test_sentinels_array_strings_default_port
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: [{ host: '127.0.0.2', port: default_sentinel_port },
{ host: '127.0.0.1', port: default_sentinel_port },
Expand All @@ -164,7 +164,7 @@ def test_sentinels_array_hashes_password
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: [{ host: '192.168.1.1', port: 3333, password: 'abc' },
{ host: '192.168.1.2', port: 4444 },
Expand All @@ -180,7 +180,7 @@ def test_sentinels_array_strings_password
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: [{ host: '192.168.1.1', port: 3333, password: 'abc' },
{ host: '192.168.1.2', port: 4444 },
Expand All @@ -196,7 +196,7 @@ def test_sentinels_correct_role
}

conn = StorageSync.send :new, Storage::Helpers.config_with(config_obj)
assert_sentinel_connector(conn)
assert_sentinel_config(conn)
assert_client_config(conn, url: config_obj[:url],
sentinels: [{ host: '127.0.0.1', port: 26_379 }],
role: role)
Expand Down Expand Up @@ -255,16 +255,19 @@ def assert_connection(client)
assert_equal 'bar', client.get('foo')
end

def assert_sentinel_connector(client)
connector = client.instance_variable_get(:@inner).instance_variable_get(:@client).instance_variable_get(:@connector)
assert_instance_of Redis::Client::Connector::Sentinel, connector
def assert_sentinel_config(client)
config = client.instance_variable_get(:@inner).instance_variable_get(:@client).instance_variable_get(:@config)
assert config.sentinel?
end

def assert_client_config(conn, url:, **conf)
client = conn.instance_variable_get(:@inner).instance_variable_get(:@client)
assert_equal client.options[:url], url
conf.each do |k, v|
assert_equal v, client.options[k]
config = conn.instance_variable_get(:@inner).instance_variable_get(:@client).instance_variable_get(:@config)
assert_equal URI(url).host, config.name
assert_equal conf[:role] || :master, config.instance_variable_get(:@role)
conf[:sentinels].each_with_index do |s, i|
assert_equal s[:host], config.sentinels[i].host
assert_equal s[:port], config.sentinels[i].port
assert_equal s[:password], config.sentinels[i].password
end
end

Expand Down

0 comments on commit be9c1e6

Please sign in to comment.