Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client#initialize specs: are they working as. expected? #154

Open
tagliala opened this issue Nov 21, 2024 · 2 comments
Open

Client#initialize specs: are they working as. expected? #154

tagliala opened this issue Nov 21, 2024 · 2 comments

Comments

@tagliala
Copy link

Hello,

while implementing #153 I've noticed that the newly instantiated redlock client is not being used by the spec, leading to false positives

it 'accepts ConnectionPool objects' do
pool = ConnectionPool.new { RedisClient.new(url: "redis://#{redis1_host}:#{redis1_port}") }
_redlock = Redlock::Client.new([pool])
lock_info = lock_manager.lock(resource_key, ttl)
expect(lock_info).to be_a(Hash)
expect(resource_key).to_not be_lockable(lock_manager, ttl)
lock_manager.unlock(lock_info)
end
it 'accepts Configuration hashes' do
config = { url: "redis://#{redis1_host}:#{redis1_port}" }
_redlock = Redlock::Client.new([config])
lock_info = lock_manager.lock(resource_key, ttl)
expect(lock_info).to be_a(Hash)
expect(resource_key).to_not be_lockable(lock_manager, ttl)
lock_manager.unlock(lock_info)
end

Example

    it 'accepts hashes responding to call like ActiveSupport::OrderedOptions' do
      callable_hash = Class.new(Hash) do
        def call; end
      end

      config = callable_hash.new.merge(url: "redis://#{redis1_host}:#{redis1_port}")
      _redlock = Redlock::Client.new([config])

      lock_info = lock_manager.lock(resource_key, ttl)
      expect(lock_info).to be_a(Hash)
      expect(resource_key).to_not be_lockable(lock_manager, ttl)
      lock_manager.unlock(lock_info)
    end

This was not failing, because lock_manager was using its own client, and the previous initialization was not used at all

  let(:lock_manager) {
    Redlock::Client.new(redis_urls_or_clients, lock_manager_opts)
  }
@tagliala tagliala changed the title Client specs: are they working? Client#initialize specs: are they working? Nov 21, 2024
@tagliala tagliala changed the title Client#initialize specs: are they working? Client#initialize specs: are they working as. expected? Nov 21, 2024
@leandromoreira
Copy link
Owner

and it should be _redlock right?

@tagliala
Copy link
Author

and it should be _redlock right?

Yes, according to the intent of what I see. But at that point _redlock does not make much sense because it is a used variable, so I would either go for redlock or redefine lock_manager.

I've used redlock in #153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants