Sha256: bc3b7856e6a2d6de27d7dfcfcac28868839e995959e48cad42b589262dc02334

Contents?: true

Size: 1.75 KB

Versions: 10

Compression:

Stored size: 1.75 KB

Contents

require 'rails_helper'

module Kuroko2::Workflow::Task
  describe Retry do

    subject(:task) { Retry.new(node, token) }
    let(:node) { Kuroko2::Workflow::ScriptParser.new(token.script).parse.find(token.path).next }
    let(:definition) { create(:job_definition) }
    let(:instance) { create(:job_instance, job_definition: definition) }
    let(:token) do
      Kuroko2::Token.create(uuid: SecureRandom.uuid, job_definition: definition, job_instance: instance, script: script)
    end

    describe '#validate' do
      context 'with valid script format' do
        let(:script) do
          <<-EOF.strip_heredoc
            retry: count=3 sleep_time=10
              noop:
              noop:
            noop:
          EOF
        end

        it 'passes validation' do
          expect { task.validate }.not_to raise_error
        end
      end

      context 'with invalid option' do
        let(:script) do
          <<-EOF.strip_heredoc
            retry: sleep_time=10
              noop:
          EOF
        end

        it 'raises AssertionError' do
          expect { task.validate }.to raise_error(Kuroko2::Workflow::AssertionError)
        end
      end
    end

    describe '#execute' do
      context 'with valid script format' do
        let(:script) do
          <<-EOF.strip_heredoc
            retry: count=3 sleep_time=10
              noop:
              noop:
            noop:
          EOF
        end

        it 'passes validation' do
          expect(task.execute).to eq :next
          token.context['RETRY'].each do |path, retry_option|
            expect(retry_option[:retried_count]).to eq 0
            expect(retry_option[:count]).to eq 3
            expect(retry_option[:sleep_time]).to eq 10
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kuroko2-0.8.0 spec/workflow/task/retry_spec.rb
kuroko2-0.7.0 spec/workflow/task/retry_spec.rb
kuroko2-0.6.0 spec/workflow/task/retry_spec.rb
kuroko2-0.5.2 spec/workflow/task/retry_spec.rb
kuroko2-0.5.1 spec/workflow/task/retry_spec.rb
kuroko2-0.5.0 spec/workflow/task/retry_spec.rb
kuroko2-0.4.6 spec/workflow/task/retry_spec.rb
kuroko2-0.4.5 spec/workflow/task/retry_spec.rb
kuroko2-0.4.4 spec/workflow/task/retry_spec.rb
kuroko2-0.4.3 spec/workflow/task/retry_spec.rb