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

Updating test-go.sh and test-integration.sh to be able to run the tests for multiple API versions #5687

Merged
merged 1 commit into from
Mar 25, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ sudo: false

language: go

go:
- 1.4
- 1.3
matrix:
include:
- go: 1.4
env: KUBE_TEST_API_VERSIONS="v1beta1"
- go: 1.3
env: KUBE_TEST_API_VERSIONS="v1beta3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was there any particular pattern to using v1beta3 with go1.3 and v1beta1 with go1.4? or were they just semi-randomly chosen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular pattern.
Chosen randomly.


install:
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
Expand All @@ -18,10 +21,10 @@ install:
- GOPATH=$PWD/Godeps/_workspace:$GOPATH go install ./...

script:
- KUBE_RACE="-race" KUBE_COVER="y" KUBE_GOVERALLS_BIN="$HOME/gopath/bin/goveralls" KUBE_TIMEOUT='-timeout 300s' KUBE_COVERPROCS=8 ./hack/test-go.sh -- -p=2
- KUBE_RACE="-race" KUBE_COVER="y" KUBE_GOVERALLS_BIN="$HOME/gopath/bin/goveralls" KUBE_TIMEOUT='-timeout 300s' KUBE_COVERPROCS=8 KUBE_TEST_API_VERSIONS=$KUBE_TEST_API_VERSIONS ./hack/test-go.sh -- -p=2
- PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/test-cmd.sh
- PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/verify-gendocs.sh
- PATH=$HOME/gopath/bin:./third_party/etcd:$PATH ./hack/test-integration.sh
- PATH=$HOME/gopath/bin:./third_party/etcd:$PATH KUBE_TEST_API_VERSIONS=$KUBE_TEST_API_VERSIONS ./hack/test-integration.sh

notifications:
irc: "chat.freenode.net#google-containers"
182 changes: 102 additions & 80 deletions hack/test-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ KUBE_COVERPROCS=${KUBE_COVERPROCS:-4}
KUBE_RACE=${KUBE_RACE:-} # use KUBE_RACE="-race" to enable race testing
# Set to the goveralls binary path to report coverage results to Coveralls.io.
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
# Comma separated list of API Versions that should be tested.
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1beta1,v1beta3"}

kube::test::usage() {
kube::log::usage_from_stdin <<EOF
Expand Down Expand Up @@ -109,87 +111,107 @@ if [[ ${#testcases[@]} -eq 0 ]]; then
fi
set -- "${testcases[@]+${testcases[@]}}"

# TODO: this should probably be refactored to avoid code duplication with the
# coverage version.
if [[ $iterations -gt 1 ]]; then
if [[ $# -eq 0 ]]; then
set -- $(kube::test::find_dirs)
runTests() {
# TODO: this should probably be refactored to avoid code duplication with the
# coverage version.
if [[ $iterations -gt 1 ]]; then
if [[ $# -eq 0 ]]; then
set -- $(kube::test::find_dirs)
fi
kube::log::status "Running ${iterations} times"
fails=0
for arg; do
trap 'exit 1' SIGINT
pkg=${KUBE_GO_PACKAGE}/${arg}
kube::log::status "${pkg}"
# keep going, even if there are failures
pass=0
count=0
for i in $(seq 1 ${iterations}); do
if go test "${goflags[@]:+${goflags[@]}}" \
${KUBE_RACE} ${KUBE_TIMEOUT} "${pkg}"; then
pass=$((pass + 1))
else
fails=$((fails + 1))
fi
count=$((count + 1))
done 2>&1
kube::log::status "${pass} / ${count} passed"
done
if [[ ${fails} -gt 0 ]]; then
return 1
else
return 0
fi
fi
kube::log::status "Running ${iterations} times"
fails=0
for arg; do
trap 'exit 1' SIGINT
pkg=${KUBE_GO_PACKAGE}/${arg}
kube::log::status "${pkg}"
# keep going, even if there are failures
pass=0
count=0
for i in $(seq 1 ${iterations}); do
if go test "${goflags[@]:+${goflags[@]}}" \
${KUBE_RACE} ${KUBE_TIMEOUT} "${pkg}"; then
pass=$((pass + 1))
else
fails=$((fails + 1))
fi
count=$((count + 1))
done 2>&1
kube::log::status "${pass} / ${count} passed"
done
if [[ ${fails} -gt 0 ]]; then
exit 1
else
exit 0

# If we're not collecting coverage, run all requested tests with one 'go test'
# command, which is much faster.
if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then
kube::log::status "Running unit tests without code coverage"
go test "${goflags[@]:+${goflags[@]}}" \
${KUBE_RACE} ${KUBE_TIMEOUT} "${@+${@/#/${KUBE_GO_PACKAGE}/}}"
return 0
fi
fi

# If we're not collecting coverage, run all requested tests with one 'go test'
# command, which is much faster.
if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then
kube::log::status "Running unit tests without code coverage"
go test "${goflags[@]:+${goflags[@]}}" \
${KUBE_RACE} ${KUBE_TIMEOUT} "${@+${@/#/${KUBE_GO_PACKAGE}/}}"
exit 0
fi
# Create coverage report directories.
cover_report_dir="/tmp/k8s_coverage/${KUBE_API_VERSION}/$(kube::util::sortable_date)"
cover_profile="coverage.out" # Name for each individual coverage profile
kube::log::status "Saving coverage output in '${cover_report_dir}'"
mkdir -p "${@+${@/#/${cover_report_dir}/}}"

# Run all specified tests, collecting coverage results. Go currently doesn't
# support collecting coverage across multiple packages at once, so we must issue
# separate 'go test' commands for each package and then combine at the end.
# To speed things up considerably, we can at least use xargs -P to run multiple
# 'go test' commands at once.
printf "%s\n" "${@}" | xargs -I{} -n1 -P${KUBE_COVERPROCS} \
go test "${goflags[@]:+${goflags[@]}}" \
${KUBE_RACE} \
${KUBE_TIMEOUT} \
-cover -covermode="${KUBE_COVERMODE}" \
-coverprofile="${cover_report_dir}/{}/${cover_profile}" \
"${cover_params[@]+${cover_params[@]}}" \
"${KUBE_GO_PACKAGE}/{}"

COMBINED_COVER_PROFILE="${cover_report_dir}/combined-coverage.out"
{
# The combined coverage profile needs to start with a line indicating which
# coverage mode was used (set, count, or atomic). This line is included in
# each of the coverage profiles generated when running 'go test -cover', but
# we strip these lines out when combining so that there's only one.
echo "mode: ${KUBE_COVERMODE}"

# Include all coverage reach data in the combined profile, but exclude the
# 'mode' lines, as there should be only one.
for x in `find "${cover_report_dir}" -name "${cover_profile}"`; do
cat $x | grep -h -v "^mode:" || true
done
} >"${COMBINED_COVER_PROFILE}"

coverage_html_file="${cover_report_dir}/combined-coverage.html"
go tool cover -html="${COMBINED_COVER_PROFILE}" -o="${coverage_html_file}"
kube::log::status "Combined coverage report: ${coverage_html_file}"
}

# Create coverage report directories.
cover_report_dir="/tmp/k8s_coverage/$(kube::util::sortable_date)"
cover_profile="coverage.out" # Name for each individual coverage profile
kube::log::status "Saving coverage output in '${cover_report_dir}'"
mkdir -p "${@+${@/#/${cover_report_dir}/}}"

# Run all specified tests, collecting coverage results. Go currently doesn't
# support collecting coverage across multiple packages at once, so we must issue
# separate 'go test' commands for each package and then combine at the end.
# To speed things up considerably, we can at least use xargs -P to run multiple
# 'go test' commands at once.
printf "%s\n" "${@}" | xargs -I{} -n1 -P${KUBE_COVERPROCS} \
go test "${goflags[@]:+${goflags[@]}}" \
${KUBE_RACE} \
${KUBE_TIMEOUT} \
-cover -covermode="${KUBE_COVERMODE}" \
-coverprofile="${cover_report_dir}/{}/${cover_profile}" \
"${cover_params[@]+${cover_params[@]}}" \
"${KUBE_GO_PACKAGE}/{}"

combined_cover_profile="${cover_report_dir}/combined-coverage.out"
{
# The combined coverage profile needs to start with a line indicating which
# coverage mode was used (set, count, or atomic). This line is included in
# each of the coverage profiles generated when running 'go test -cover', but
# we strip these lines out when combining so that there's only one.
echo "mode: ${KUBE_COVERMODE}"

# Include all coverage reach data in the combined profile, but exclude the
# 'mode' lines, as there should be only one.
for x in `find "${cover_report_dir}" -name "${cover_profile}"`; do
cat $x | grep -h -v "^mode:" || true
done
} >"${combined_cover_profile}"

coverage_html_file="${cover_report_dir}/combined-coverage.html"
go tool cover -html="${combined_cover_profile}" -o="${coverage_html_file}"
kube::log::status "Combined coverage report: ${coverage_html_file}"

if [[ -x "${KUBE_GOVERALLS_BIN}" ]]; then
${KUBE_GOVERALLS_BIN} -coverprofile="${combined_cover_profile}" || true
fi
runTestsForVersion() {
export KUBE_API_VERSION="$1"
runTests "${@:2}"
}

reportCoverageToCoveralls() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if factoring this out into its own subroutine was really necessary.

if [[ -x "${KUBE_GOVERALLS_BIN}" ]]; then
${KUBE_GOVERALLS_BIN} -coverprofile="${COMBINED_COVER_PROFILE}" || true
fi
}

# Convert the CSV to an array of API versions to test
IFS=',' read -a apiVersions <<< ${KUBE_TEST_API_VERSIONS}
for apiVersion in "${apiVersions[@]}"; do
echo "Running tests for APIVersion: $apiVersion"
runTestsForVersion $apiVersion "${@}"
done

# We might run the tests for multiple versions, but we want to report only
# one of them to coveralls. Here we report coverage from the last run.
reportCoverageToCoveralls
11 changes: 9 additions & 2 deletions hack/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
# Comma separated list of API Versions that should be tested.
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1beta1,v1beta3"}


cleanup() {
kube::etcd::cleanup
Expand All @@ -36,6 +39,7 @@ runTests() {
kube::log::status "Running integration test cases"
KUBE_GOFLAGS="-tags 'integration no-docker' " \
KUBE_RACE="-race" \
KUBE_TEST_API_VERSIONS="$1" \
"${KUBE_ROOT}/hack/test-go.sh" test/integration

kube::log::status "Running integration test scenario"
Expand All @@ -50,5 +54,8 @@ runTests() {
# Run cleanup to stop etcd on interrupt or other kill signal.
trap cleanup EXIT

runTests "v1beta1"
runTests "v1beta3"
# Convert the CSV to an array of API versions to test
IFS=',' read -a apiVersions <<< ${KUBE_TEST_API_VERSIONS}
for apiVersion in "${apiVersions[@]}"; do
runTests $apiVersion
done