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

Support testing by mocking MockRedis#evalsha #11

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

vu-hoang-kaligo
Copy link
Collaborator

Context

Application uses MockRedis will have test cases related to Idempotency cache failing due to the Idempotency::Cache#evalsha method always return nil, which causes the release_lock logic to always fail:

    def release_lock(fingerprint, acquired_lock)
      with_redis do |r|
        lock_released = r.evalsha(COMPARE_AND_DEL_SCRIPT_SHA, keys: [lock_key(fingerprint)], argv: [acquired_lock])
		# lock_released is always `nil` which will differ from `acquired_lock` value
        raise LockConflict if lock_released != acquired_lock

As such, I've created a new helper in this PR to override the evalsha implementation of MockRedis to work similar to the LUA script logic

@vu-hoang-kaligo vu-hoang-kaligo force-pushed the feature/mock-redis-support branch 2 times, most recently from 345aca3 to a8e4b1e Compare January 13, 2025 04:44
@vu-hoang-kaligo vu-hoang-kaligo force-pushed the feature/mock-redis-support branch from a8e4b1e to 36eb08a Compare January 13, 2025 04:45
@vu-hoang-kaligo vu-hoang-kaligo merged commit c972f6e into master Jan 14, 2025
1 check passed
@vu-hoang-kaligo vu-hoang-kaligo deleted the feature/mock-redis-support branch January 14, 2025 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants