tests: Move functional tests to 'tests' module.

Tested with:

PASSES="fmt functional unit" ./test
make build-docker-functional
release-3.5
Piotr Tabor 2020-09-27 09:51:09 +02:00
parent 8907b146d4
commit b382429d01
10 changed files with 72 additions and 47 deletions

View File

@ -491,7 +491,7 @@ docker-dns-srv-test-certs-wildcard-run:
build-functional:
$(info GO_VERSION: $(GO_VERSION))
$(info ETCD_VERSION: $(ETCD_VERSION))
./functional/build
./tests/functional/build
./bin/etcd-agent -help || true && \
./bin/etcd-proxy -help || true && \
./bin/etcd-runner --help || true && \
@ -500,13 +500,13 @@ build-functional:
build-docker-functional:
$(info GO_VERSION: $(GO_VERSION))
$(info ETCD_VERSION: $(ETCD_VERSION))
@sed -i.bak 's|REPLACE_ME_GO_VERSION|$(GO_VERSION)|g' ./functional/Dockerfile
@sed -i.bak 's|REPLACE_ME_GO_VERSION|$(GO_VERSION)|g' ./tests/functional/Dockerfile
docker build \
--network=host \
--tag gcr.io/etcd-development/etcd-functional:go$(GO_VERSION) \
--file ./functional/Dockerfile \
--file ./tests/functional/Dockerfile \
.
@mv ./functional/Dockerfile.bak ./functional/Dockerfile
@mv ./tests/functional/Dockerfile.bak ./tests/functional/Dockerfile
docker run \
--rm \

63
build
View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash
source ./scripts/test_lib.sh
# set some environment variables
ORG_PATH="go.etcd.io"
REPO_PATH="${ORG_PATH}/etcd/v3"
@ -16,9 +18,9 @@ GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/version.GitSHA=${GIT_SHA}"
toggle_failpoints() {
mode="$1"
if command -v gofail >/dev/null 2>&1; then
gofail "$mode" etcdserver/ mvcc/backend/
run gofail "$mode" etcdserver/ mvcc/backend/
elif [[ "$mode" != "disable" ]]; then
echo "FAILPOINTS set but gofail not found"
log_error "FAILPOINTS set but gofail not found"
exit 1
fi
}
@ -36,37 +38,56 @@ etcd_build() {
# Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
# shellcheck disable=SC2086
CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
-installsuffix cgo \
-ldflags "$GO_LDFLAGS" \
-o "${out}/etcd" ${REPO_PATH} || return
CGO_ENABLED=0 run go build $GO_BUILD_FLAGS \
-installsuffix=cgo \
"-ldflags='${GO_LDFLAGS}'" \
-o="${out}/etcd" . || return
# shellcheck disable=SC2086
CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
-installsuffix cgo \
-ldflags "$GO_LDFLAGS" \
-o "${out}/etcdctl" ${REPO_PATH}/etcdctl || return
CGO_ENABLED=0 run go build $GO_BUILD_FLAGS \
-installsuffix=cgo \
"-ldflags='${GO_LDFLAGS}'" \
-o="${out}/etcdctl" ./etcdctl || return
}
tools_build() {
out="bin"
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
tools_path="tools/benchmark
tools/etcd-dump-db
tools/etcd-dump-logs
tools/local-tester/bridge
functional/cmd/etcd-agent
functional/cmd/etcd-proxy
functional/cmd/etcd-runner
functional/cmd/etcd-tester"
tools/etcd-dump-db
tools/etcd-dump-logs
tools/local-tester/bridge"
for tool in ${tools_path}
do
echo "Building" "'${tool}'"...
# shellcheck disable=SC2086
CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} \
-installsuffix cgo \
-ldflags "${GO_LDFLAGS}" \
-o "${out}/${tool}" "${REPO_PATH}/${tool}" || return
CGO_ENABLED=0 run go build ${GO_BUILD_FLAGS} \
-installsuffix=cgo \
"-ldflags='${GO_LDFLAGS}'" \
-o="${out}/${tool}" "./${tool}" || return
done
tests_build "${@}"
}
tests_build() {
out="bin"
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
tools_path="
functional/cmd/etcd-agent
functional/cmd/etcd-proxy
functional/cmd/etcd-runner
functional/cmd/etcd-tester"
(
cd tests || exit 2
for tool in ${tools_path}; do
echo "Building" "'${tool}'"...
# shellcheck disable=SC2086
CGO_ENABLED=0 run go build ${GO_BUILD_FLAGS} \
-installsuffix=cgo \
"-ldflags='${GO_LDFLAGS}'" \
-o="../${out}/${tool}" "./${tool}" || return
done
)
}
toggle_failpoints_default

2
go.mod
View File

@ -10,7 +10,6 @@ require (
github.com/creack/pty v1.1.11
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4
github.com/etcd-io/gofail v0.0.0-20190801230047-ad7f989257ca
github.com/fatih/color v1.7.0 // indirect
github.com/gogo/protobuf v1.2.1
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903
@ -48,7 +47,6 @@ require (
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2
google.golang.org/grpc v1.26.0
gopkg.in/cheggaaa/pb.v1 v1.0.25
gopkg.in/yaml.v2 v2.2.2
sigs.k8s.io/yaml v1.1.0
)

2
go.sum
View File

@ -27,8 +27,6 @@ github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4 h1:qk/FSDDxo05w
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/etcd-io/gofail v0.0.0-20190801230047-ad7f989257ca h1:Y2I0lxOttdUKz+hNaIdG3FtjuQrTmwXun1opRV65IZc=
github.com/etcd-io/gofail v0.0.0-20190801230047-ad7f989257ca/go.mod h1:49H/RkXP8pKaZy4h0d+NW16rSLhyVBt4o6VLJbmOqDE=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=

22
test
View File

@ -137,11 +137,12 @@ function generic_checker {
}
function functional_pass {
./functional/build
run ./tests/functional/build
# Clean up any data and logs from previous runs
rm -rf /tmp/etcd-functional-* /tmp/etcd-functional-*.backup
# TODO: These ports should be dynamically allocated instead of hard-coded.
for a in 1 2 3; do
./bin/etcd-agent --network tcp --address 127.0.0.1:${a}9027 &
pid="$!"
@ -149,22 +150,25 @@ function functional_pass {
done
for a in 1 2 3; do
echo "Waiting for 'etcd-agent' on ${a}9027..."
log_callout "Waiting for 'etcd-agent' on ${a}9027..."
while ! nc -z localhost ${a}9027; do
sleep 1
done
done
echo "functional test START!"
run ./bin/etcd-tester --config ./functional.yaml && log_success "'etcd-tester' succeeded"
ETCD_TESTER_EXIT_CODE=$?
echo "ETCD_TESTER_EXIT_CODE:" ${ETCD_TESTER_EXIT_CODE}
log_callout "functional test START!"
run ./bin/etcd-tester --config ./tests/functional/functional.yaml && log_success "'etcd-tester' succeeded"
local etcd_tester_exit_code=$?
if [[ "${etcd_tester_exit_code}" -ne "0" ]]; then
log_error "ETCD_TESTER_EXIT_CODE:" ${etcd_tester_exit_code}
fi
# shellcheck disable=SC2206
agent_pids=($agent_pids)
kill -s TERM "${agent_pids[@]}" || true
if [[ "${ETCD_TESTER_EXIT_CODE}" -ne "0" ]]; then
if [[ "${etcd_tester_exit_code}" -ne "0" ]]; then
log_error -e "\nFAILED! 'tail -1000 /tmp/etcd-functional-1/etcd.log'"
tail -1000 /tmp/etcd-functional-1/etcd.log
@ -174,8 +178,8 @@ function functional_pass {
log_error -e "\nFAILED! 'tail -1000 /tmp/etcd-functional-3/etcd.log'"
tail -1000 /tmp/etcd-functional-3/etcd.log
log_error "--- FAIL: exit code" ${ETCD_TESTER_EXIT_CODE}
return ${ETCD_TESTER_EXIT_CODE}
log_error "--- FAIL: exit code" ${etcd_tester_exit_code}
return ${etcd_tester_exit_code}
fi
log_success "functional test PASS!"
}

View File

@ -13,7 +13,7 @@ RUN dnf check-update || true \
ENV GOROOT /usr/local/go
ENV GOPATH /go
ENV PATH ${GOPATH}/bin:${GOROOT}/bin:${PATH}
ENV GO_VERSION REPLACE_ME_GO_VERSION
ENV GO_VERSION 1.14.3
ENV GO_DOWNLOAD_URL https://storage.googleapis.com/golang
RUN rm -rf ${GOROOT} \
&& curl -s ${GO_DOWNLOAD_URL}/go${GO_VERSION}.linux-amd64.tar.gz | tar -v -C /usr/local/ -xz \
@ -22,7 +22,7 @@ RUN rm -rf ${GOROOT} \
RUN mkdir -p ${GOPATH}/src/go.etcd.io/etcd
ADD . ${GOPATH}/src/go.etcd.io/etcd
ADD ./functional.yaml /functional.yaml
ADD ./tests/functional/functional.yaml /functional.yaml
RUN go get -v go.etcd.io/gofail \
&& pushd ${GOPATH}/src/go.etcd.io/etcd \
@ -32,7 +32,7 @@ RUN go get -v go.etcd.io/gofail \
&& cp ./bin/etcdctl /bin/etcdctl \
&& GO_BUILD_FLAGS="-v" FAILPOINTS=1 ./build \
&& cp ./bin/etcd /bin/etcd-failpoints \
&& ./functional/build \
&& ./tests/functional/build \
&& cp ./bin/etcd-agent /bin/etcd-agent \
&& cp ./bin/etcd-proxy /bin/etcd-proxy \
&& cp ./bin/etcd-runner /bin/etcd-runner \

View File

@ -4,7 +4,7 @@
See [`rpcpb.Case`](https://godoc.org/github.com/coreos/etcd/functional/rpcpb#Case) for all failure cases.
See [functional.yaml](https://github.com/etcd-io/etcd/blob/master/functional.yaml) for an example configuration.
See [functional.yaml](https://github.com/etcd-io/etcd/blob/master/tests/functional/functional.yaml) for an example configuration.
### Run locally

View File

@ -1,11 +1,14 @@
#!/usr/bin/env bash
if ! [[ "$0" =~ "functional/build" ]]; then
if ! [[ "$0" =~ "tests/functional/build" ]]; then
echo "must be run from repository root"
exit 255
fi
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ./bin/etcd-agent ./functional/cmd/etcd-agent
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ./bin/etcd-proxy ./functional/cmd/etcd-proxy
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ./bin/etcd-runner ./functional/cmd/etcd-runner
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ./bin/etcd-tester ./functional/cmd/etcd-tester
(
cd ./tests
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ../bin/etcd-agent ./functional/cmd/etcd-agent
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ../bin/etcd-proxy ./functional/cmd/etcd-proxy
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ../bin/etcd-runner ./functional/cmd/etcd-runner
CGO_ENABLED=0 go build -v -installsuffix cgo -ldflags "-s" -o ../bin/etcd-tester ./functional/cmd/etcd-tester
)

View File

@ -62,6 +62,7 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=