Skip to content

Commit

Permalink
poll instead of hardcoded sleep. 1 testcase can fail or timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sumedhpd committed Feb 8, 2024
1 parent 5df052d commit 790fb9f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 3.5.1

- Fix local run for integration tests
- Wait for creation of serviceaccount 'default' in newly created namespace to avoid race conditions with pod creation failures


# 3.5.0
Expand Down
16 changes: 15 additions & 1 deletion test/helpers/test_provisioner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,25 @@ def prepare_pv(name, storage_class_name: nil)

private

def wait_for_default_service_account(kubeclient, namespace)
30.times do
begin
sa = kubeclient.get_service_account('default', namespace)
return if sa
rescue Kubeclient::ResourceNotFoundError
# If the service account is not found, sleep for a second and then retry
sleep(1)
end
end
raise "Default service account in #{namespace} not ready after 30 seconds"
end

def create_namespace(namespace)
ns = Kubeclient::Resource.new(kind: 'Namespace')
ns.metadata = { name: namespace }
kubeclient.create_namespace(ns)
sleep(5) # wait for the serviceaccount 'default' to be created; https://github.com/kubernetes/kubernetes/issues/66689
# wait for the serviceaccount 'default' to be created; https://github.com/kubernetes/kubernetes/issues/66689
wait_for_default_service_account(kubeclient, namespace)
end
end
end
2 changes: 1 addition & 1 deletion test/integration/krane_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ def test_resource_watcher_reports_failed_after_timeout
f["missing_volumes.yml"]["Deployment"].first["spec"]["progressDeadlineSeconds"] = 30
f["cannot_run.yml"]["Deployment"].first["spec"]["replicas"] = 1
end
assert_deploy_failure(result)
assert_deploy_failure_or_timeout(result)

bad_probe_timeout = "Deployment/bad-probe: TIMED OUT (progress deadline: 5s)"

Expand Down
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ def assert_deploy_failure(result, cause = nil)
alias_method :assert_restart_failure, :assert_deploy_failure
alias_method :assert_task_run_failure, :assert_deploy_failure

def assert_deploy_failure_or_timeout(result)
assert_equal(false, result, "Deploy succeeded when it was expected to fail.#{logs_message_if_captured}")
logging_assertion do |logs|
assert(logs.include?("Result: FAILURE") || logs.include?("Result: TIMED OUT"),
"'Result: FAILURE' or 'Result: TIMED OUT' not found in the following logs:\n#{logs}")
end
end

def assert_deploy_success(result)
assert_equal(true, result, "Deploy failed when it was expected to succeed.#{logs_message_if_captured}")
logging_assertion do |logs|
Expand Down

0 comments on commit 790fb9f

Please sign in to comment.