-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
Fix dependency error in inline testing connector #54
Fix dependency error in inline testing connector #54
Conversation
…uest-#53 Fix dependency error in inline testing connector
Unfortunately I get some errors in my tests now and before I jump in and start fixing stuff I thought you might be able to help @salrepe require 'rails_helper'
describe NetEnt::RefreshSession, sidekiq: :inline do
include ActiveSupport::Testing::TimeHelpers
let(:session_id) { 'abc' }
let(:api_endpoint) do
'https://some.domain.co/services/CasinoMC'
end
before(:all) do
@wsdl = File.open(CasinoSaga::Engine.root.join('spec', 'fixtures', 'casino_mc.wsdl')).read
end
before do
stub_request(:get, "#{api_endpoint}?wsdl")
.to_return(status: 200, body: @wsdl)
# rubocop:disable LineLength
multiple_body = %(<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://casinomodule.com/api" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><env:Body></env:Body></env:Envelope>)
singular_body = %(<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://casinomodule.com/api" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><env:Body></env:Body></env:Envelope>)
refresh_body = '<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://casinomodule.com/api" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><env:Body><impl:refreshUserSessionResponse><sessionId>whatever</sessionId></impl:refreshUserSessionResponse></env:Body></env:Envelope>'
# rubocop:enable LineLength
@multiple_refresh =
stub_request(:post, api_endpoint)
.with(body: multiple_body)
.to_return(status: 200, body: refresh_body)
@singular_refresh =
stub_request(:post, api_endpoint)
.with(body: singular_body)
.to_return(status: 200, body: refresh_body)
end
it 'only allows 1 call per 10 minutes', sidekiq: :inline do
NetEnt::RefreshSession.perform_async(session_id)
100.times do
NetEnt::RefreshSession.perform_async(session_id)
end
expect(@multiple_refresh).to have_been_made.once
NetEnt::RefreshSession.perform_async('another')
expect(@singular_refresh).to have_been_made.once
travel_to(11.minutes.from_now) do
NetEnt::RefreshSession.perform_async(session_id)
expect(@multiple_refresh).to have_been_made.twice
end
end
end yields the following error:
So now the time constraint on This is the class module NetEnt
class RefreshSession
include Sidekiq::Worker
sidekiq_options queue: :rare, backtrace: true, retry: false,
unique: true,
unique_job_expiration: 10 * 60
def perform(session_id)
NetEnt.refresh_session session_id if session_id
rescue Savon::SOAPFault => e
logger.info { e }
end
end
end |
Hey, following what the Sidekiq wiki says [1], I think that the inline mode is not prepared to test what you are testing here. With the inline mode the jobs are not queued, they are processed as soon as the worker perform_async method is called, so the unique option does not work with inline mode, it only works for jobs marked as :unique_unlock_order => :never. Apart from that I think that this test is not right at all, the multiple_body and singular_body strings are equal, for that reason when you check the second time for So I think that the time check that is what you want to check here was not being exercised. |
Actually you made me fix my test, I had forgotten to set the unlock order but due to unique jobs being broken before I never noticed this was happening. Thanks a lot for these updates! |
I added a test for my scenario |
👍 |
After require the new version 3.0.3, I detected a dependency error in the testing_inline connector.