diff --git a/Makefile b/Makefile index e6c6fc4b44dbf..3777187ab2e06 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,9 @@ explaintest: server @cd cmd/explaintest && ./run-tests.sh -s ../../bin/tidb-server gotest: - $(GO) get github.com/etcd-io/gofail + @rm -rf $GOPATH/bin/gofail + $(GO) get github.com/pingcap/gofail + @which gofail @$(GOFAIL_ENABLE) ifeq ("$(TRAVIS_COVERAGE)", "1") @echo "Running in TRAVIS_COVERAGE mode." @@ -126,21 +128,21 @@ endif @$(GOFAIL_DISABLE) race: - $(GO) get github.com/etcd-io/gofail + $(GO) get github.com/pingcap/gofail @$(GOFAIL_ENABLE) @export log_level=debug; \ $(GOTEST) -timeout 20m -race $(PACKAGES) || { $(GOFAIL_DISABLE); exit 1; } @$(GOFAIL_DISABLE) leak: - $(GO) get github.com/etcd-io/gofail + $(GO) get github.com/pingcap/gofail @$(GOFAIL_ENABLE) @export log_level=debug; \ $(GOTEST) -tags leak $(PACKAGES) || { $(GOFAIL_DISABLE); exit 1; } @$(GOFAIL_DISABLE) tikv_integration_test: - $(GO) get github.com/etcd-io/gofail + $(GO) get github.com/pingcap/gofail @$(GOFAIL_ENABLE) $(GOTEST) ./store/tikv/. -with-tikv=true || { $(GOFAIL_DISABLE); exit 1; } @$(GOFAIL_DISABLE) diff --git a/ddl/fail_db_test.go b/ddl/fail_db_test.go index a4cca08a91e82..ec7316baa6847 100644 --- a/ddl/fail_db_test.go +++ b/ddl/fail_db_test.go @@ -17,8 +17,8 @@ import ( "fmt" "time" - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" + gofail "github.com/pingcap/gofail/runtime" "github.com/pingcap/parser" "github.com/pingcap/parser/model" "github.com/pingcap/tidb/ddl" diff --git a/ddl/fail_test.go b/ddl/fail_test.go index 9b8771672793b..8b8ad576fa3c6 100644 --- a/ddl/fail_test.go +++ b/ddl/fail_test.go @@ -14,8 +14,8 @@ package ddl import ( - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" + gofail "github.com/pingcap/gofail/runtime" "github.com/pingcap/parser/ast" "github.com/pingcap/parser/model" "github.com/pingcap/tidb/types" diff --git a/executor/executor_test.go b/executor/executor_test.go index 3690c9d4f377c..e8a7963905b7f 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -25,10 +25,10 @@ import ( "testing" "time" - gofail "github.com/etcd-io/gofail/runtime" "github.com/golang/protobuf/proto" . "github.com/pingcap/check" "github.com/pingcap/errors" + gofail "github.com/pingcap/gofail/runtime" pb "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/parser" "github.com/pingcap/parser/model" diff --git a/go.mod b/go.mod index a035c5bef97a9..3ef3bc35184a6 100644 --- a/go.mod +++ b/go.mod @@ -45,6 +45,7 @@ require ( github.com/opentracing/opentracing-go v1.0.2 github.com/pingcap/check v0.0.0-20171206051426-1c287c953996 github.com/pingcap/errors v0.11.0 + github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3 github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030 github.com/pingcap/kvproto v0.0.0-20181109035735-8e3f33ac4929 github.com/pingcap/parser v0.0.0-20181207085916-6c21d4344dfa diff --git a/go.sum b/go.sum index 25afbf2f824b3..670cdc7221747 100644 --- a/go.sum +++ b/go.sum @@ -86,6 +86,8 @@ github.com/pingcap/check v0.0.0-20171206051426-1c287c953996 h1:ZBdiJCMan6GSo/aPA github.com/pingcap/check v0.0.0-20171206051426-1c287c953996/go.mod h1:B1+S9LNcuMyLH/4HMTViQOJevkGiik3wW2AN9zb2fNQ= github.com/pingcap/errors v0.11.0 h1:DCJQB8jrHbQ1VVlMFIrbj2ApScNNotVmkSNplu2yUt4= github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= +github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3 h1:04yuCf5NMvLU8rB2m4Qs3rynH7EYpMno3lHkewIOdMo= +github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3/go.mod h1:DazNTg0PTldtpsQiT9I5tVJwV1onHMKBBgXzmJUlMns= github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030 h1:XJLuW0lsP7vAtQ2iPjZwvXZ14m5urp9No+Qr06ZZcTo= github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw= github.com/pingcap/kvproto v0.0.0-20181109035735-8e3f33ac4929 h1:NAq95+VGsS2G7SjzZ5LP9iUlCMNAs13QUzbNY3G90v8= diff --git a/owner/fail_test.go b/owner/fail_test.go index 5145eeadafa8e..db1bdb6eace2b 100644 --- a/owner/fail_test.go +++ b/owner/fail_test.go @@ -21,8 +21,8 @@ import ( "time" "github.com/coreos/etcd/clientv3" - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" + gofail "github.com/pingcap/gofail/runtime" "github.com/pingcap/parser/terror" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/testleak" diff --git a/session/session_fail_test.go b/session/session_fail_test.go index 9cbf408eeb500..26b97070be4b6 100644 --- a/session/session_fail_test.go +++ b/session/session_fail_test.go @@ -14,8 +14,8 @@ package session_test import ( - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" + gofail "github.com/pingcap/gofail/runtime" "github.com/pingcap/tidb/util/testkit" ) diff --git a/store/tikv/2pc_fail_test.go b/store/tikv/2pc_fail_test.go index d3b6edeaa7be3..32b1b6831d577 100644 --- a/store/tikv/2pc_fail_test.go +++ b/store/tikv/2pc_fail_test.go @@ -14,9 +14,9 @@ package tikv import ( - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" "github.com/pingcap/errors" + gofail "github.com/pingcap/gofail/runtime" "github.com/pingcap/parser/terror" "github.com/pingcap/tidb/kv" "golang.org/x/net/context" diff --git a/store/tikv/gcworker/gc_worker_test.go b/store/tikv/gcworker/gc_worker_test.go index 490c148291a57..501942bab2b1d 100644 --- a/store/tikv/gcworker/gc_worker_test.go +++ b/store/tikv/gcworker/gc_worker_test.go @@ -19,8 +19,8 @@ import ( "testing" "time" - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" + gofail "github.com/pingcap/gofail/runtime" "github.com/pingcap/kvproto/pkg/errorpb" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/session" diff --git a/store/tikv/sql_fail_test.go b/store/tikv/sql_fail_test.go index 30bbc95c25ff7..fbbfc70c8ade7 100644 --- a/store/tikv/sql_fail_test.go +++ b/store/tikv/sql_fail_test.go @@ -18,8 +18,8 @@ import ( "sync" "time" - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" + gofail "github.com/pingcap/gofail/runtime" "github.com/pingcap/parser/terror" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/session" diff --git a/store/tikv/store_fail_test.go b/store/tikv/store_fail_test.go index 6fc8ce09c9f9a..01bc02ba61245 100644 --- a/store/tikv/store_fail_test.go +++ b/store/tikv/store_fail_test.go @@ -17,8 +17,8 @@ import ( "sync" "time" - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" + gofail "github.com/pingcap/gofail/runtime" "golang.org/x/net/context" ) diff --git a/tablecodec/tablecodec_test.go b/tablecodec/tablecodec_test.go index 9467d926128d9..60448b94376c5 100644 --- a/tablecodec/tablecodec_test.go +++ b/tablecodec/tablecodec_test.go @@ -19,8 +19,8 @@ import ( "testing" "time" - gofail "github.com/etcd-io/gofail/runtime" . "github.com/pingcap/check" + gofail "github.com/pingcap/gofail/runtime" "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx/stmtctx" diff --git a/vendor/github.com/etcd-io/gofail/LICENSE b/vendor/github.com/pingcap/gofail/LICENSE similarity index 100% rename from vendor/github.com/etcd-io/gofail/LICENSE rename to vendor/github.com/pingcap/gofail/LICENSE diff --git a/vendor/github.com/etcd-io/gofail/NOTICE b/vendor/github.com/pingcap/gofail/NOTICE similarity index 100% rename from vendor/github.com/etcd-io/gofail/NOTICE rename to vendor/github.com/pingcap/gofail/NOTICE diff --git a/vendor/github.com/etcd-io/gofail/runtime/failpoint.go b/vendor/github.com/pingcap/gofail/runtime/failpoint.go similarity index 87% rename from vendor/github.com/etcd-io/gofail/runtime/failpoint.go rename to vendor/github.com/pingcap/gofail/runtime/failpoint.go index 0eee542e83fa4..e4b4cbc57eb4c 100644 --- a/vendor/github.com/etcd-io/gofail/runtime/failpoint.go +++ b/vendor/github.com/pingcap/gofail/runtime/failpoint.go @@ -20,12 +20,13 @@ import ( ) type Failpoint struct { - mu sync.RWMutex - t *terms + mu sync.RWMutex + t *terms + waitChan chan struct{} } func NewFailpoint(pkg, name string) *Failpoint { - fp := &Failpoint{} + fp := &Failpoint{waitChan: make(chan struct{})} register(pkg+"/"+name, fp) return fp } @@ -51,6 +52,11 @@ func (fp *Failpoint) Acquire() (interface{}, error) { // Release is called when the failpoint exists. func (fp *Failpoint) Release() { fp.mu.RUnlock() } +// Pause will pause until the failpoint is disabled. +func (fp *Failpoint) Pause() { + <-fp.waitChan +} + // BadType is called when the failpoint evaluates to the wrong type. func (fp *Failpoint) BadType(v interface{}, t string) { fmt.Printf("failpoint: %q got value %v of type \"%T\" but expected type %q\n", fp.t.fpath, v, v, t) diff --git a/vendor/github.com/etcd-io/gofail/runtime/http.go b/vendor/github.com/pingcap/gofail/runtime/http.go similarity index 100% rename from vendor/github.com/etcd-io/gofail/runtime/http.go rename to vendor/github.com/pingcap/gofail/runtime/http.go diff --git a/vendor/github.com/etcd-io/gofail/runtime/runtime.go b/vendor/github.com/pingcap/gofail/runtime/runtime.go similarity index 96% rename from vendor/github.com/etcd-io/gofail/runtime/runtime.go rename to vendor/github.com/pingcap/gofail/runtime/runtime.go index 446524330c66c..0a14038787d56 100644 --- a/vendor/github.com/etcd-io/gofail/runtime/runtime.go +++ b/vendor/github.com/pingcap/gofail/runtime/runtime.go @@ -63,19 +63,20 @@ func Enable(failpath, inTerms string) error { // enableAndLock enables a failpoint and returns a function to unlock it func enableAndLock(failpath, inTerms string) (func(), error) { - t, err := newTerms(failpath, inTerms) - if err != nil { - fmt.Printf("failed to enable \"%s=%s\" (%v)\n", failpath, inTerms, err) - return nil, err - } failpointsMu.RLock() fp := failpoints[failpath] failpointsMu.RUnlock() if fp == nil { return nil, ErrNoExist } + t, err := newTerms(failpath, inTerms, fp) + if err != nil { + fmt.Printf("failed to enable \"%s=%s\" (%v)\n", failpath, inTerms, err) + return nil, err + } fp.mu.Lock() fp.t = t + fp.waitChan = make(chan struct{}) return func() { fp.mu.Unlock() }, nil } @@ -87,6 +88,7 @@ func Disable(failpath string) error { if fp == nil { return ErrNoExist } + close(fp.waitChan) fp.mu.Lock() defer fp.mu.Unlock() if fp.t == nil { diff --git a/vendor/github.com/etcd-io/gofail/runtime/terms.go b/vendor/github.com/pingcap/gofail/runtime/terms.go similarity index 94% rename from vendor/github.com/etcd-io/gofail/runtime/terms.go rename to vendor/github.com/pingcap/gofail/runtime/terms.go index d81477d5e1c63..aab3015d4d78e 100644 --- a/vendor/github.com/etcd-io/gofail/runtime/terms.go +++ b/vendor/github.com/pingcap/gofail/runtime/terms.go @@ -52,6 +52,7 @@ type term struct { val interface{} parent *terms + fp *Failpoint } type mod interface { @@ -83,8 +84,8 @@ func (ml *modList) allow() bool { return true } -func newTerms(fpath, desc string) (*terms, error) { - chain := parse(desc) +func newTerms(fpath, desc string, fp *Failpoint) (*terms, error) { + chain := parse(desc, fp) if len(chain) == 0 { return nil, ErrBadParse } @@ -109,10 +110,10 @@ func (t *terms) eval() (interface{}, error) { } // split terms from a -> b -> ... into [a, b, ...] -func parse(desc string) (chain []*term) { +func parse(desc string, fp *Failpoint) (chain []*term) { origDesc := desc for len(desc) != 0 { - t := parseTerm(desc) + t := parseTerm(desc, fp) if t == nil { fmt.Printf("failed to parse %q past %q\n", origDesc, desc) return nil @@ -131,7 +132,7 @@ func parse(desc string) (chain []*term) { } // :: [ "(" ")" ] -func parseTerm(desc string) *term { +func parseTerm(desc string, fp *Failpoint) *term { t := &term{} modStr, mods := parseMod(desc) t.mods = &modList{mods} @@ -140,6 +141,7 @@ func parseTerm(desc string) *term { valStr, val := parseVal(desc[len(modStr)+len(actStr):]) t.val = val t.desc = desc[:len(modStr)+len(actStr)+len(valStr)] + t.fp = fp if len(t.desc) == 0 { return nil } @@ -230,7 +232,7 @@ func parseIntFloat(desc string) (string, interface{}) { } // parseAct parses an action -// :: "off" | "return" | "sleep" | "panic" | "break" | "print" +// :: "off" | "return" | "sleep" | "panic" | "break" | "print" | "pause" func parseAct(desc string) (string, actFunc) { for k, v := range actMap { if strings.HasPrefix(desc, k) { @@ -285,6 +287,7 @@ var actMap = map[string]actFunc{ "panic": actPanic, "break": actBreak, "print": actPrint, + "pause": actPause, } func (t *term) do() interface{} { return t.act(t) } @@ -313,6 +316,13 @@ func actSleep(t *term) interface{} { return nil } +func actPause(t *term) interface{} { + if t.fp != nil { + t.fp.Pause() + } + return nil +} + func actPanic(t *term) interface{} { if t.val != nil { panic(fmt.Sprintf("failpoint panic: %v", t.val)) diff --git a/vendor/modules.txt b/vendor/modules.txt index 383c8d377ce92..97dd12acede42 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -20,8 +20,6 @@ github.com/coreos/etcd/pkg/types github.com/cznic/mathutil # github.com/cznic/sortutil v0.0.0-20150617083342-4c7342852e65 github.com/cznic/sortutil -# github.com/etcd-io/gofail v0.0.0-20180808172546-51ce9a71510a -github.com/etcd-io/gofail/runtime # github.com/go-sql-driver/mysql v0.0.0-20170715192408-3955978caca4 github.com/go-sql-driver/mysql # github.com/gogo/protobuf v1.1.1 @@ -65,6 +63,8 @@ github.com/opentracing/opentracing-go/log github.com/pingcap/check # github.com/pingcap/errors v0.11.0 github.com/pingcap/errors +# github.com/pingcap/gofail v0.0.0-20181217135706-6a951c1e42c3 +github.com/pingcap/gofail/runtime # github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030 github.com/pingcap/goleveldb/leveldb github.com/pingcap/goleveldb/leveldb/comparer