Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Nov 7, 2018
1 parent 1ab5280 commit 3a4a1e1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 36 deletions.
53 changes: 53 additions & 0 deletions test/integration-serial/serial_task_run_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,57 @@ def test_run_without_verify_result_fails_if_pod_was_not_created
"Kubeclient::HttpError: Pod with same name exists"
], in_order: true)
end

# We can't ensure that all the metrics are specific test when they are running in parallel
# so we run them serially
def test_failure_statsd_metric_emitted
deploy_task_template
task_runner = build_task_runner

result = false
metrics = capture_statsd_calls do
result = task_runner.run(run_params.merge(args: ["/not/a/command"]))
end

assert_task_run_failure(result)

metric_tags = metrics.detect { |m| m.tags.include? "namespace:#{@namespace}" }.tags
assert_includes metric_tags, "namespace:#{@namespace}"
assert_includes metric_tags, "context:#{KubeclientHelper::TEST_CONTEXT}"
assert_includes metric_tags, "status:failure"
end

def test_success_statsd_metric_emitted
deploy_task_template
task_runner = build_task_runner

result = false
metrics = capture_statsd_calls do
result = task_runner.run(run_params.merge(args: ["ls"]))
end

assert_task_run_success(result)

metric_tags = metrics.detect { |m| m.tags.include? "namespace:#{@namespace}" }.tags
assert_includes metric_tags, "namespace:#{@namespace}"
assert_includes metric_tags, "context:#{KubeclientHelper::TEST_CONTEXT}"
assert_includes metric_tags, "status:success"
end

def test_timedout_statsd_metric_emitted
deploy_task_template
task_runner = build_task_runner(max_watch_seconds: 5)

result = false
metrics = capture_statsd_calls do
result = task_runner.run(run_params.merge(args: ["sleep 600"]))
end

assert_task_run_failure(result, :timed_out)

metric_tags = metrics.detect { |m| m.tags.include? "namespace:#{@namespace}" }.tags
assert_includes metric_tags, "namespace:#{@namespace}"
assert_includes metric_tags, "context:#{KubeclientHelper::TEST_CONTEXT}"
assert_includes metric_tags, "status:timeout"
end
end
3 changes: 1 addition & 2 deletions test/integration/kubernetes_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ def test_invalid_k8s_spec_that_is_valid_yaml_fails_fast_and_prints_template
"Template validation failed",
/Invalid template: ConfigMap-hello-cloud-configmap-data.*yml/,
"> Error message:",
"error validating data: ValidationError(ConfigMap.metadata): \
unknown field \"myKey\" in io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta",
/error validating data: .*myKey.* v1.ObjectMeta/,
"> Template content:",
" myKey: uhOh"
], in_order: true)
Expand Down
36 changes: 2 additions & 34 deletions test/integration/runner_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ def test_run_without_verify_result_succeeds_as_soon_as_pod_is_successfully_creat

task_runner = build_task_runner
assert_nil task_runner.pod_name
result = false
metrics = capture_statsd_calls do
result = task_runner.run(run_params(verify_result: false))
end
result =task_runner.run(run_params(verify_result: false))
assert_task_run_success(result)

assert_logs_match_all([
Expand All @@ -27,20 +24,13 @@ def test_run_without_verify_result_succeeds_as_soon_as_pod_is_successfully_creat
pods = kubeclient.get_pods(namespace: @namespace)
assert_equal 1, pods.length, "Expected 1 pod to exist, found #{pods.length}"
assert_equal task_runner.pod_name, pods.first.metadata.name, "Pod name should be available after run"

# We can't ensure that all the metrics we grab are from this specific test because they are running in parallel
metric_tags = metrics.detect { |m| m.tags.include? "namespace:#{@namespace}" }.tags
assert_includes metric_tags, "status:success"
end

def test_run_global_timeout_with_max_watch_seconds
deploy_task_template

task_runner = build_task_runner(max_watch_seconds: 5)
result = false
metrics = capture_statsd_calls do
result = task_runner.run(run_params(log_lines: 8, log_interval: 1))
end
result = task_runner.run(run_params(log_lines: 8, log_interval: 1))
assert_task_run_failure(result, :timed_out)

assert_logs_match_all([
Expand All @@ -49,10 +39,6 @@ def test_run_global_timeout_with_max_watch_seconds
%r{Pod/task-runner-\w+: GLOBAL WATCH TIMEOUT \(5 seconds\)},
/Final status\: (Pending|Running)/
], in_order: true)

# We can't ensure that all the metrics we grab are from this specific test because they are running in parallel
metric_tags = metrics.detect { |m| m.tags.include? "namespace:#{@namespace}" }.tags
assert_includes metric_tags, "status:timeout"
end

def test_run_with_verify_result_failure
Expand All @@ -76,24 +62,6 @@ def test_run_with_verify_result_failure
assert_equal task_runner.pod_name, pods.first.metadata.name, "Pod name should be available after run"
end

def test_statsd_metric_emitted
deploy_task_template
task_runner = build_task_runner

result = false
metrics = capture_statsd_calls do
result = task_runner.run(run_params.merge(args: ["/not/a/command"]))
end

assert_task_run_failure(result)

# We can't ensure that all the metrics we grab are from this specific test because they are running in parallel
metric_tags = metrics.detect { |m| m.tags.include? "namespace:#{@namespace}" }.tags
assert_includes metric_tags, "namespace:#{@namespace}"
assert_includes metric_tags, "context:#{KubeclientHelper::TEST_CONTEXT}"
assert_includes metric_tags, "status:failure"
end

def test_run_with_verify_result_success
deploy_task_template

Expand Down

0 comments on commit 3a4a1e1

Please sign in to comment.