worker_spec.rb revision a9a53dbe70810d1bf7d91ed2af86dd6d39a13124
2058N/Arequire 'spec_helper'
2058N/A
2058N/A# We try to be explicit when using sidekiq
2058N/A# testing modes. However inline! is the default
2058N/Adescribe Worker do
2058N/A setup_hets
2058N/A
2058N/A let(:balancer) { ConcurrencyBalancer.new }
2058N/A
2058N/A context 'using the sequential queue' do
2058N/A let(:ontology) { create :single_unparsed_ontology, locid: '/test/sequential_parse' }
2058N/A let(:version) { ontology.versions.last }
2058N/A
2058N/A before do
2058N/A begin
2058N/A balancer.mark_as_finished_processing(ontology.iri)
2058N/A rescue ConcurrencyBalancer::UnmarkedProcessingError
2058N/A end
2058N/A balancer.mark_as_processing_or_complain(ontology.iri)
2058N/A OntologyVersion.any_instance.stubs(:raw_path!).returns(
2058N/A ontology_file('clif/sequential_parse'))
2058N/A stub_hets_for('clif/sequential_parse.clif')
3996N/A end
2058N/A
2058N/A after do
2058N/A balancer.mark_as_finished_processing(ontology.iri)
2058N/A OntologyVersion.any_instance.unstub(:raw_path!)
2058N/A end
2058N/A
2058N/A context 'exceeding the parallel try count of an already marked iri job' do
2058N/A it 'should put the correct job in the sequential queue' do
2058N/A rest_args = ['record', OntologyVersion.to_s, 'parse', version.id]
2058N/A Worker.new.perform(
2058N/A *rest_args, try_count: ConcurrencyBalancer::MAX_TRIES)
2058N/A expect(SequentialWorker.jobs.first['args']).to eq([*rest_args])
2058N/A end
2058N/A end
3661N/A
3661N/A context 'not exceeding the parallel try count of an already marked iri job' do
3996N/A it 'should put the correct job in the queue once again' do
3996N/A rest_args = ['record', OntologyVersion.to_s, 'parse', version.id]
3996N/A Worker.new.perform(
2058N/A *rest_args, try_count: ConcurrencyBalancer::MAX_TRIES-1)
2058N/A
2058N/A # We need the String-Hash-Key syntax, because
2058N/A # the JSON generate/parse cycle does not support
2058N/A # symbols
2058N/A expect(Worker.jobs.first['args']).to eq([
2058N/A *rest_args, "try_count" => ConcurrencyBalancer::MAX_TRIES])
2058N/A end
2058N/A end
2058N/A end
2058N/A
2058N/Aend
2058N/A