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

Run specs with redis client #65

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ AllCops:
NewCops: enable
Exclude:
- gemfiles/**/*
- activejob-uniqueness.gemspec

Layout/LineLength:
Max: 120
Expand Down
6 changes: 2 additions & 4 deletions spec/support/locks_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# frozen_string_literal: true

require 'redis'

module LocksHelpers
def cleanup_locks(**args)
ActiveJob::Uniqueness.unlock!(**args)
end

def locks(**args)
redis.keys(ActiveJob::Uniqueness::LockKey.new(**args).wildcard_key)
redis.call('KEYS', ActiveJob::Uniqueness::LockKey.new(**args).wildcard_key)
end

def locks_count
locks.count
end

def locks_expirations(**args)
locks(**args).map { |key| redis.ttl(key) }
locks(**args).map { |key| redis.call('TTL', key) }
end

def set_lock(job_class, arguments:)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/redis_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module RedisHelpers
def redis
@redis ||= Redis.new
@redis ||= RedisClient.new(url: ENV.fetch('REDIS_URL', 'redis://localhost:6379'))
end
end

Expand Down