worker_spec.rb revision 20d7141b5fbf4ea48eeadae9d6a9a88465ac6b8b
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlenrequire 'spec_helper'
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen# We try to be explicit when using sidekiq
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen# testing modes. However inline! is the default
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlendescribe Worker do
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen let(:balancer) { ConcurrencyBalancer.new }
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen context 'using the sequential queue' do
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen let(:ontology) { create :single_unparsed_ontology, iri: 'http://example.com/test/sequential_parse' }
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen let(:version) { ontology.versions.last }
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen before do
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen begin
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen balancer.mark_as_finished_processing(ontology.iri)
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen rescue ConcurrencyBalancer::UnmarkedProcessingError
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen end
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen balancer.mark_as_processing_or_complain(ontology.iri)
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen OntologyVersion.any_instance.stubs(:raw_path!).returns(
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen Rails.root + 'test/fixtures/ontologies/clif/sequential_parse.clif')
eb11fe3584b7b243fb0641da4ab2e157610bb767Lubos Kosco end
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen after do
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen balancer.mark_as_finished_processing(ontology.iri)
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen OntologyVersion.any_instance.unstub(:raw_path!)
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen end
1c377666fe7591e06614ee1340bb31d831b60c59Knut Anders Hatlen
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen context 'exceeding the parallel try count of an already marked iri job' do
6fb29c51593eb4622f537cd43c1a81ffb36a8ff7Knut Anders Hatlen it 'should put the correct job in the sequential queue' do
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen rest_args = ['record', OntologyVersion.to_s, 'parse', version.id]
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen Worker.new.perform(
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen *rest_args, try_count: ConcurrencyBalancer::MAX_TRIES)
6fd168587048fe0e2cb37acdcc9ae9764c83b2d2Trond Norbye expect(SequentialWorker.jobs.first['args']).to eq([*rest_args])
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen end
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen end
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen
eb11fe3584b7b243fb0641da4ab2e157610bb767Lubos Kosco context 'not exceeding the parallel try count of an already marked iri job' do
eb11fe3584b7b243fb0641da4ab2e157610bb767Lubos Kosco it 'should put the correct job in the queue once again' do
eb11fe3584b7b243fb0641da4ab2e157610bb767Lubos Kosco rest_args = ['record', OntologyVersion.to_s, 'parse', version.id]
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen Worker.new.perform(
722820d7fc7cef11b744d2c2a9e680cee7d292ffAsCatgz *rest_args, try_count: ConcurrencyBalancer::MAX_TRIES-1)
722820d7fc7cef11b744d2c2a9e680cee7d292ffAsCatgz
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen # We need the String-Hash-Key syntax, because
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen # the JSON generate/parse cycle does not support
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen # symbols
eb11fe3584b7b243fb0641da4ab2e157610bb767Lubos Kosco expect(Worker.jobs.first['args']).to eq([
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen *rest_args, "try_count" => ConcurrencyBalancer::MAX_TRIES])
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen end
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen end
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen end
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlen
ca13a2073cb9936daab594cd277550783ac2e6b6Knut Anders Hatlenend
56a2e680c9f75f55a0286143272a7cd392040873mrate