Skip to content

Commit

Permalink
tests: support deadlock detection in make test (#1704)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx authored and sre-bot committed Aug 30, 2019
1 parent b1eadf8 commit a1f8d9d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
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

0 comments on commit a1f8d9d

Please sign in to comment.