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

tests: support deadlock detection in make test #1704

Merged
merged 4 commits into from
Aug 30, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ tags
/.retools/
vendor
default*
*.bak
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ OVERALLS := overalls
FAILPOINT_ENABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|\.retools)" | xargs ./scripts/retool do failpoint-ctl enable)
FAILPOINT_DISABLE := $$(find $$PWD/ -type d | grep -vE "(\.git|\.retools)" | xargs ./scripts/retool do failpoint-ctl disable)

DEADLOCK_ENABLE := $$(find . -name "*.go" | grep -vE "(vendor|\.retools)" | xargs -n 1 sed -i.bak 's/sync.RWMutex/deadlock.RWMutex/' && \
find . -name "*.go" | grep -vE "(vendor|\.retools)" | xargs -n 1 sed -i.bak 's/sync.Mutex/deadlock.Mutex/' && \
find . -name "*.go" | grep -vE "(vendor|\.retools)" | xargs -n 1 ./scripts/retool do goimports -w)
DEADLOCK_DISABLE := $$(find . -name "*.go" | grep -vE "(vendor|\.retools)" | xargs -n 1 sed -i.bak 's/deadlock.RWMutex/sync.RWMutex/' && \
find . -name "*.go" | grep -vE "(vendor|\.retools)" | xargs -n 1 sed -i.bak 's/deadlock.Mutex/sync.Mutex/' && \
find . -name "*.go" | grep -vE "(vendor|\.retools)" | xargs -n 1 ./scripts/retool do goimports -w && \
find . -name "*.bak" | grep -vE "(vendor|\.retools)" | xargs rm)

LDFLAGS += -X "$(PD_PKG)/server.PDReleaseVersion=$(shell git describe --tags --dirty)"
LDFLAGS += -X "$(PD_PKG)/server.PDBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "$(PD_PKG)/server.PDGitHash=$(shell git rev-parse HEAD)"
Expand Down Expand Up @@ -55,10 +63,12 @@ pd-recover:
CGO_ENABLED=0 go build -o bin/pd-recover tools/pd-recover/main.go

test: retool-setup
# testing..
# testing...
@$(DEADLOCK_ENABLE)
@$(FAILPOINT_ENABLE)
CGO_ENABLED=1 GO111MODULE=on go test -race -cover $(TEST_PKGS) || { $(FAILPOINT_DISABLE); exit 1; }
CGO_ENABLED=1 GO111MODULE=on go test -race -cover $(TEST_PKGS) || { $(FAILPOINT_DISABLE); $(DEADLOCK_DISABLE); exit 1; }
@$(FAILPOINT_DISABLE)
@$(DEADLOCK_DISABLE)

basic-test:
@$(FAILPOINT_ENABLE)
Expand Down Expand Up @@ -126,6 +136,16 @@ clean-test:
rm -rf /tmp/pd-tests*
rm -rf /tmp/test_etcd*

deadlock-setup: export GO111MODULE=off
deadlock-setup:
go get github.com/sasha-s/go-deadlock

deadlock-enable: deadlock-setup
@$(DEADLOCK_ENABLE)

deadlock-disable:
@$(DEADLOCK_DISABLE)

failpoint-enable:
# Converting failpoints...
@$(FAILPOINT_ENABLE)
Expand Down
4 changes: 1 addition & 3 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

package cache

import (
"sync"
)
import "sync"

// Cache is an interface for cache system
type Cache interface {
Expand Down
2 changes: 2 additions & 0 deletions scripts/retool-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ which retool >/dev/null || go get github.com/twitchtv/retool
./scripts/retool add github.com/securego/gosec/cmd/gosec 1.0.0
# go fail
./scripts/retool add github.com/pingcap/failpoint/failpoint-ctl master
# deadlock detection
./scripts/retool add golang.org/x/tools/cmd/goimports 04b5d21e00f1f47bd824a6ade581e7189bacde87
4 changes: 4 additions & 0 deletions tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
{
"Repository": "github.com/golangci/golangci-lint/cmd/golangci-lint",
"Commit": "4ba2155996359eabd8800d1fbf3e3a9777c80490"
},
{
"Repository": "golang.org/x/tools/cmd/goimports",
"Commit": "04b5d21e00f1f47bd824a6ade581e7189bacde87"
}
],
"RetoolVersion": "1.3.7"
Expand Down