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

Fix dependency error in inline testing connector #54

Conversation

salrepe
Copy link
Contributor

@salrepe salrepe commented Nov 3, 2014

After require the new version 3.0.3, I detected a dependency error in the testing_inline connector.

mhenrixon added a commit that referenced this pull request Nov 3, 2014
…uest-#53

Fix dependency error in inline testing connector
@mhenrixon mhenrixon merged commit 2c3e55b into mhenrixon:master Nov 3, 2014
@mhenrixon
Copy link
Owner

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:

  1. NetEnt::RefreshSession only allows 1 call per 10 minutes
    Failure/Error: expect(@multiple_refresh).to have_been_made.once
    The request POST "url + body" was expected to execute 1 time but it executed 101 times

So now the time constraint on unique_args seems to be broken. Suggestions?

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

@salrepe
Copy link
Contributor Author

salrepe commented Nov 3, 2014

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.
With fake mode, it would work as you are expecting here.

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 expect(@multiple_refresh).to have_been_made.twice it is ok. It is right because it is counting the first call to NetEnt::RefreshSession.perform_async(session_id) and the call NetEnt::RefreshSession.perform_async('another').

So I think that the time check that is what you want to check here was not being exercised.
Makes sense?

@mhenrixon
Copy link
Owner

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!

@mhenrixon
Copy link
Owner

I added a test for my scenario

@salrepe
Copy link
Contributor Author

salrepe commented Nov 4, 2014

👍

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

Successfully merging this pull request may close these issues.

2 participants