Cross Reference: /ontohub/spec/lib/worker_spec.rb
worker_spec.rb revision a9a53dbe70810d1bf7d91ed2af86dd6d39a13124
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
b7de308d8bc28d42249256bddb16bbace71f60favboxsyncrequire 'spec_helper'
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync# We try to be explicit when using sidekiq
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync# testing modes. However inline! is the default
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsyncdescribe Worker do
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync setup_hets
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync let(:balancer) { ConcurrencyBalancer.new }
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync context 'using the sequential queue' do
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync let(:ontology) { create :single_unparsed_ontology, locid: '/test/sequential_parse' }
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync let(:version) { ontology.versions.last }
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync before do
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync begin
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync balancer.mark_as_finished_processing(ontology.iri)
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync rescue ConcurrencyBalancer::UnmarkedProcessingError
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync end
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync balancer.mark_as_processing_or_complain(ontology.iri)
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync OntologyVersion.any_instance.stubs(:raw_path!).returns(
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync ontology_file('clif/sequential_parse'))
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync stub_hets_for('clif/sequential_parse.clif')
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync end
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync after do
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync balancer.mark_as_finished_processing(ontology.iri)
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync OntologyVersion.any_instance.unstub(:raw_path!)
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync end
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync context 'exceeding the parallel try count of an already marked iri job' do
cf57145d4697dceca3f0542b370c20f7a2c5c6e8vboxsync it 'should put the correct job in the sequential queue' do
cf57145d4697dceca3f0542b370c20f7a2c5c6e8vboxsync rest_args = ['record', OntologyVersion.to_s, 'parse', version.id]
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync Worker.new.perform(
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync *rest_args, try_count: ConcurrencyBalancer::MAX_TRIES)
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync expect(SequentialWorker.jobs.first['args']).to eq([*rest_args])
881b5ff6bc55e1fb0f4ef42f9782ccec79c0a138vboxsync end
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync end
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync context 'not exceeding the parallel try count of an already marked iri job' do
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync it 'should put the correct job in the queue once again' do
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync rest_args = ['record', OntologyVersion.to_s, 'parse', version.id]
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync Worker.new.perform(
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync *rest_args, try_count: ConcurrencyBalancer::MAX_TRIES-1)
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync # We need the String-Hash-Key syntax, because
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync # the JSON generate/parse cycle does not support
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync # symbols
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync expect(Worker.jobs.first['args']).to eq([
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync *rest_args, "try_count" => ConcurrencyBalancer::MAX_TRIES])
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync end
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync end
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync end
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsyncend
b4f03aea544c9a58d8959658b31f7bd716a3f097vboxsync