Skip to content

Commit

Permalink
cherry pick pingcap#838 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
kennytm committed Mar 10, 2021
1 parent cdfda3e commit a4b4e7e
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ build_for_integration_test:
) || (make failpoint-disable && exit 1)
@make failpoint-disable

test: export ARGS=$$($(PACKAGES))
test:
$(PREPARE_MOD)
@make failpoint-enable
$(GOTEST) $(RACEFLAG) -tags leak $$($(PACKAGES)) || ( make failpoint-disable && exit 1 )
$(GOTEST) $(RACEFLAG) -tags br_test,leak $(ARGS) || ( make failpoint-disable && exit 1 )
@make failpoint-disable

testcover: tools
Expand Down Expand Up @@ -188,7 +189,7 @@ static: prepare tools
@# exhaustivestruct - Protobuf structs have hidden fields, like "XXX_NoUnkeyedLiteral"
@# exhaustive - no need to check exhaustiveness of enum switch statements
@# gosec - too many false positive
CGO_ENABLED=0 tools/bin/golangci-lint run --enable-all --deadline 120s \
CGO_ENABLED=0 tools/bin/golangci-lint run --enable-all --build-tags br_test --deadline 120s \
--disable gochecknoglobals \
--disable goimports \
--disable gofmt \
Expand Down
2 changes: 2 additions & 0 deletions pkg/mock/backend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/mock/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2021 PingCAP, Inc. Licensed under Apache-2.0.

// This file avoids mock being an empty package when `-tags br_test` is not provided.

package mock
6 changes: 4 additions & 2 deletions pkg/mock/glue.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/mock/glue_checkpoint.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/mock/importer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/mock/mock_cluster.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.

//+build br_test

package mock

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/mock/mock_cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.

//+build br_test

package mock_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/mock/s3iface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/mock/storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
This folder contains all tests which relies on external processes such as TiDB.
# Unit tests

Unit tests (the `*_test.go` files inside the source directory) should *never* rely on external
programs.

Run `make test` to execute all unit tests.

To run a specific test, pass `ARGS` into `make test` like

```sh
make test ARGS='github.com/pingcap/br/pkg/cdclog --test.v --check.v --check.f TestColumn'
# ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# which package to test more extra test flags
```

You can also run unit tests directly via `go test` like:

```sh
make failpoint-enable

go test -tags br_test github.com/pingcap/br/pkg/cdclog --test.v --check.v --check.f TestColumn
# ^~~~~~~~~~~~~

make failpoint-disable
```

but note that:

* the build-tag `br_test` must be enabled (this workarounds the lack of test-dependencies in go.mod)
* failpoints must be toggled manually

# Integration tests

This folder contains all tests which relies on external processes such as TiDB.

## Preparations

1. The following 9 executables must be copied or linked into these locations:
Expand Down Expand Up @@ -39,7 +69,6 @@ If you have docker installed, you can skip step 1 and step 2 by running

## Running

Run `make test` to execute the unit tests.
Run `make integration_test` to execute the integration tests. This command will

1. Build `br`
Expand Down

0 comments on commit a4b4e7e

Please sign in to comment.