diff --git a/spec/workflow/engine_spec.rb b/spec/workflow/engine_spec.rb index 2d9225c8..184bbe91 100644 --- a/spec/workflow/engine_spec.rb +++ b/spec/workflow/engine_spec.rb @@ -119,6 +119,65 @@ module Kuroko2::Workflow end end + context 'with parallel_fork' do + let!(:definition) do + create(:job_definition_with_instances, script: <<-EOF.strip_heredoc) + env: GLOBAL_ENV=g + parallel_fork: 3 + noop: noop1 + noop: noop2 + EOF + end + + specify do + subject.process(token) + expect(token.path).to eq '/0-env' + subject.process(token) + expect(token.path).to eq '/1-parallel_fork' + + subject.process(token) + expect(token.children.size).to eq 3 + + parallel_tokens = token.children + subject.process_all + + parallel_tokens.each(&:reload) + expect(token.path).to eq '/1-parallel_fork' + expect(parallel_tokens.map(&:path)).to all(eq('/0-sequence')) + + subject.process_all + parallel_tokens.each(&:reload) + expect(token.path).to eq '/1-parallel_fork' + expect(parallel_tokens.map(&:path)).to all(eq('/0-sequence/0-noop')) + expect(parallel_tokens.map(&:status_name)).to all(eq('working')) + expect(parallel_tokens.map{ |token| token.context['ENV']['KUROKO2_PARALLEL_FORK_SIZE'] }).to all(eq('3')) + expect(parallel_tokens.map{ |token| token.context['ENV']['GLOBAL_ENV'] }).to all(eq('g')) + expect(parallel_tokens[0].context['ENV']['KUROKO2_PARALLEL_FORK_INDEX']).to eq('0') + expect(parallel_tokens[1].context['ENV']['KUROKO2_PARALLEL_FORK_INDEX']).to eq('1') + expect(parallel_tokens[2].context['ENV']['KUROKO2_PARALLEL_FORK_INDEX']).to eq('2') + + subject.process_all + parallel_tokens.each(&:reload) + expect(token.path).to eq '/1-parallel_fork' + expect(parallel_tokens.map(&:path)).to all(eq('/0-sequence/1-noop')) + expect(parallel_tokens.map(&:status_name)).to all(eq('working')) + expect(parallel_tokens.map{ |token| token.context['ENV']['KUROKO2_PARALLEL_FORK_SIZE'] }).to all(eq('3')) + expect(parallel_tokens.map{ |token| token.context['ENV']['GLOBAL_ENV'] }).to all(eq('g')) + expect(parallel_tokens[0].context['ENV']['KUROKO2_PARALLEL_FORK_INDEX']).to eq('0') + expect(parallel_tokens[1].context['ENV']['KUROKO2_PARALLEL_FORK_INDEX']).to eq('1') + expect(parallel_tokens[2].context['ENV']['KUROKO2_PARALLEL_FORK_INDEX']).to eq('2') + + subject.process_all + parallel_tokens.each(&:reload) + expect(token.path).to eq '/1-parallel_fork' + expect(parallel_tokens.map(&:path)).to all(eq('/0-sequence/1-noop')) + expect(parallel_tokens.map(&:status_name)).to all(eq('finished')) + + subject.process_all + expect(Kuroko2::Token.all.count).to eq 0 + end + end + context 'retry' do let!(:definition) do create(:job_definition_with_instances, script: <<-EOF.strip_heredoc) diff --git a/spec/workflow/task/parallel_fork_spec.rb b/spec/workflow/task/parallel_fork_spec.rb index 1cd638e2..62749367 100644 --- a/spec/workflow/task/parallel_fork_spec.rb +++ b/spec/workflow/task/parallel_fork_spec.rb @@ -5,16 +5,53 @@ module Kuroko2::Workflow::Task let(:node) { Kuroko2::Workflow::ScriptParser.new(token.script).parse.find(token.path) } let(:definition) { create(:job_definition) } let(:instance) { create(:job_instance, job_definition: definition) } + let(:script) do + <<-EOF.strip_heredoc + parallel_fork: 2 + noop: + EOF + end let(:token) do - Kuroko2::Token.create(uuid: SecureRandom.uuid, path: '/0-fork', job_definition: definition, job_instance: instance, script: <<-EOF) -parallel_fork: 2 - noop: - EOF + Kuroko2::Token.create(uuid: SecureRandom.uuid, path: '/0-fork', job_definition: definition, job_instance: instance, script: script) + end + + let(:task) { ParallelFork.new(node, token) } + + describe '#validate' do + context 'with valid script format' do + it 'passes validation' do + expect{ task.validate }.not_to raise_error + end + end + + context 'with invalid option' do + let(:script) do + <<-EOF.strip_heredoc + parallel_fork: B + noop: + EOF + end + + it 'raises AssertionError' do + expect{ task.validate }.to raise_error(Kuroko2::Workflow::AssertionError) + end + end + + context 'with invalid script format' do + let(:script) do + <<-EOF.strip_heredoc + parallel_fork: 100 + EOF + end + + it 'raises AssertionError' do + expect{ task.validate }.to raise_error(Kuroko2::Workflow::AssertionError) + end + end end describe '#execute' do - subject(:task) { ParallelFork.new(node, token) } let(:children) { token.children } it do