Skip to content

Commit

Permalink
more test + pretty_timeout_type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
timothysmith0609 committed Jan 21, 2019
1 parent 488b6ca commit c9d037c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
8 changes: 7 additions & 1 deletion lib/kubernetes-deploy/kubernetes_resource/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ def timeout_message
end

def pretty_timeout_type
progress_deadline.present? ? "progress deadline: #{progress_deadline}s" : super
if timeout_override
"timeout override: #{timeout_override}s"
elsif progress_deadline.present?
"progress deadline: #{progress_deadline}s"
else
super
end
end

def deploy_timed_out?
Expand Down
4 changes: 2 additions & 2 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ def test_deployment_with_timeout_override
container['readinessProbe'] = { "exec" => { "command" => ['- ls'] } }
end
assert_deploy_failure(result, :timed_out)

assert_logs_match_all(KubernetesDeploy::KubernetesResource::STANDARD_TIMEOUT_MESSAGE.split("\n"))
assert_logs_match_all(KubernetesDeploy::KubernetesResource::STANDARD_TIMEOUT_MESSAGE.split("\n") +
["timeout override: 10s"])
end

def test_wait_false_ignores_non_priority_resource_failures
Expand Down
26 changes: 22 additions & 4 deletions test/unit/kubernetes-deploy/kubernetes_resource/deployment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def test_deploy_timed_out_with_hard_timeout
template: build_deployment_template(status: { "replicas" => 3, "conditions" => [] }),
replica_sets: [build_rs_template(status: { "replica" => 1 })]
)

deploy.deploy_started_at = Time.now.utc - KubernetesDeploy::Deployment::TIMEOUT
refute deploy.deploy_timed_out?

Expand Down Expand Up @@ -309,17 +310,34 @@ def test_deploy_timed_out_based_on_progress_deadline

def test_deploy_timed_out_based_on_timeout_override
Timecop.freeze do
template = build_deployment_template
template["metadata"]["annotations"][KubernetesDeploy::KubernetesResource::TIMEOUT_OVERRIDE_ANNOTATION] = "10S"
template = build_deployment_template(
status: {
"replicas" => 3,
"observedGeneration" => 2,
"conditions" => [{
"type" => "Progressing",
"status" => 'False',
"lastUpdateTime" => Time.now.utc - 10.seconds,
"reason" => "ProgressDeadlineExceeded",
}],
}
)
template["metadata"]["annotations"][KubernetesDeploy::KubernetesResource::TIMEOUT_OVERRIDE_ANNOTATION] = "15S"
template["spec"]["progressDeadlineSeconds"] = "10"
deploy = build_synced_deployment(
template: template,
replica_sets: [build_rs_template(status: { "replica" => 1 })]
)
refute deploy.deploy_timed_out?, "Deploy not started shouldn't have timed out"
deploy.deploy_started_at = Time.now.utc - 3.minutes

assert_equal(deploy.timeout, 15)
refute(deploy.deploy_timed_out?, "Deploy not started shouldn't have timed out")
deploy.deploy_started_at = Time.now.utc - 11.seconds
refute(deploy.deploy_timed_out?, "Deploy should not timeout based on progressDeadlineSeconds")
deploy.deploy_started_at = Time.now.utc - 16.seconds
assert(deploy.deploy_timed_out?, "Deploy should timeout according to timoeout override")
assert_equal(KubernetesDeploy::KubernetesResource::STANDARD_TIMEOUT_MESSAGE + "\nLatest ReplicaSet: web-1",
deploy.timeout_message.strip)
assert_equal(deploy.pretty_timeout_type, "timeout override: 15s")
end
end

Expand Down

0 comments on commit c9d037c

Please sign in to comment.