Skip to content

Commit cc857b4

Browse files
Merge pull request #4 from Kaligo/fix/sidekiq-7-specs
[Dev Fix] [EE] (2/2) Fix Sidekiq 7 specs [LOYAL-10414]
2 parents e57bdb9 + 2d12498 commit cc857b4

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

spec/sidekiq_adhoc_job/requests/jobs/index_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
include_context 'SidekiqAdhocJob setup'
77
include_context 'request setup'
88

9-
xit 'returns list of workers and arguments' do
9+
it 'returns list of workers and arguments' do
1010
get '/adhoc-jobs'
1111

1212
expect(last_response.status).to eq 200

spec/sidekiq_adhoc_job/requests/jobs/show_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
include_context 'SidekiqAdhocJob setup'
77
include_context 'request setup'
88

9-
xcontext 'has arguments' do
9+
context 'has arguments' do
1010
it 'generates form for running job' do
1111
get '/adhoc-jobs/sidekiq_adhoc_job_test_dummy_worker'
1212

@@ -73,7 +73,7 @@
7373
end
7474
end
7575

76-
xcontext 'has rest args' do
76+
context 'has rest args' do
7777
it 'generates form for running job' do
7878
get '/adhoc-jobs/sidekiq_adhoc_job_test_dummy_rest_args_worker'
7979

@@ -117,7 +117,7 @@
117117
end
118118
end
119119

120-
xcontext 'no argument' do
120+
context 'no argument' do
121121
it 'generates form for running job' do
122122
get '/adhoc-jobs/sidekiq_adhoc_job_test_dummy_no_arg_worker'
123123

spec/spec_helper.rb

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,19 @@
4949
# mock_redis setup
5050
config.before do
5151
require 'mock_redis'
52-
require 'sidekiq/redis_connection'
52+
require 'sidekiq'
5353

54-
redis = MockRedis.new
54+
mock_redis = MockRedis.new
55+
mock_redis.define_singleton_method(:config) { OpenStruct.new(server_url: 'redis://localhost:6379') }
5556

56-
connection = {
57-
location: '127.0.0.1:6379',
58-
db: '0'
59-
}
60-
61-
redis.define_singleton_method(:connection) { connection }
62-
63-
allow(Sidekiq::RedisConnection).to receive(:create).and_return(ConnectionPool.new({}) {
64-
redis
65-
})
66-
allow(Sidekiq).to receive(:redis) do |&block|
67-
block.call(redis)
68-
end
57+
# sscan in redis-client used by sidekiq allows calling with only the key
58+
# We intercept such calls to sscan and default the cursor to 0 when calling sscan in MockRedis
59+
#
60+
# See: https://github.com/sidekiq/sidekiq/blob/dddf20b/lib/sidekiq/api.rb#L70
61+
# See: https://github.com/redis-rb/redis-client/blob/a2f16fc/lib/redis_client.rb#L384
62+
# See: https://github.com/sds/mock_redis/blob/640f19c/lib/mock_redis/set_methods.rb#L145-L147
63+
allow(mock_redis).to receive(:sscan) { |key| mock_redis.common_scan(mock_redis.smembers(key), 0)[1] }
64+
allow(Sidekiq).to receive(:redis).and_yield(mock_redis)
6965
end
7066
# The settings below are suggested to provide a good initial experience
7167
# with RSpec, but feel free to customize to your heart's content.

0 commit comments

Comments
 (0)