Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Following rails5.1.2 ActiveSupport::Duration changes #69

Merged
merged 2 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/autoload/kuroko2/workflow/task/wait.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def validate
# ex. wait: 100/daily 200/daily
def parse_option(option, start_at: Time.current)
raise_assertion_error unless option

wait_option = { "jobs" => [], "timeout" => 60.minutes.to_i / 1.minute }
wait_option = { "jobs" => [], "timeout" => 60 } # 60 minutes by default
scanner = StringScanner.new(option)
until scanner.eos?
if scanner.scan(OPTION_REGEXP)
Expand All @@ -78,7 +77,7 @@ def parse_option(option, start_at: Time.current)
"received" => false,
}
elsif scanner.scan(/timeout=(\d+)h/)
wait_option["timeout"] = scanner[1].to_i.hours / 60
wait_option["timeout"] = (scanner[1].to_i.hours / 1.minute).to_i
elsif scanner.scan(/timeout=(\d+)m/) || scanner.scan(/timeout=(\d+)/)
wait_option["timeout"] = scanner[1].to_i
elsif scanner.scan(/\s+|,/)
Expand Down
39 changes: 28 additions & 11 deletions spec/workflow/task/wait_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ module Kuroko2::Workflow::Task
it 'returns :wait' do
expect(Wait.new(node, token).execute).to eq(:pass)
expect(token.context['WAIT']).to eq({
"timeout" => 60.minutes.to_i / 60,
"jobs" => [{
"job_definition_id" => wait_definition.id,
"period" => 'daily',
"start_from" => now.beginning_of_day.to_s,
"start_to" => now.end_of_day.to_s,
"received" => false,
}]
}],
"timeout" => 60,
})
end

Expand Down Expand Up @@ -61,16 +61,33 @@ module Kuroko2::Workflow::Task
context 'if timeout' do
let(:definition) { create(:job_definition, script: "noop:") }
let(:instance) { create(:job_instance, job_definition: definition) }
let(:option) { "#{definition.id}/daily timeout=1m" }

around do |example|
Wait.new(node, token).execute
Timecop.travel((1.minutes + 1.second).since) { example.run }
context 'timeout options is `1m`' do
let(:option) { "#{definition.id}/daily timeout=1m" }

around do |example|
Wait.new(node, token).execute
Timecop.travel((1.minutes + 1.second).since) { example.run }
end

it 'fails task' do
expect(token.context['WAIT']["timeout"]).to eq(1)
expect(Wait.new(node, token).execute).to eq(:failure)
end
end

it 'fails task' do
expect(token.context['WAIT']["timeout"]).to eq(1)
expect(Wait.new(node, token).execute).to eq(:failure)
context 'timeout options is `2h`' do
let(:option) { "#{definition.id}/daily timeout=2h" }

around do |example|
Wait.new(node, token).execute
Timecop.travel((2.hours + 1.second).since) { example.run }
end

it 'fails task' do
expect(token.context['WAIT']["timeout"]).to eq(120)
expect(Wait.new(node, token).execute).to eq(:failure)
end
end
end
end
Expand All @@ -87,7 +104,6 @@ module Kuroko2::Workflow::Task
it 'returns :wait' do
expect(Wait.new(node, token).execute).to eq(:pass)
expect(token.context['WAIT']).to eq({
"timeout" => 60.minutes.to_i / 60,
"jobs" => [
{
"job_definition_id" => wait_definition1.id,
Expand All @@ -103,7 +119,8 @@ module Kuroko2::Workflow::Task
"start_to" => now.end_of_day.to_s,
"received" => false,
},
]
],
"timeout" => 60,
})
end

Expand Down