go test failed
nkbai opened this issue · 8 comments
Bug Report
go get github.com/pingcap/failpoint/
cd failpoint
go test .
/V/d/g/s/g/p/failpoint (master|✔) [2] $ go test .
failed to parse "invalid" past "invalid"
failed to enable "failpoint-name=invalid" (failpoint: could not parse terms)
----------------------------------------------------------------------
FAIL: http_test.go:47: httpSuite.TestServeHTTP
http_test.go:124:
c.Assert(err, IsNil)
... value *url.Error = &url.Error{Op:"Get", URL:"http://127.0.0.1:23389/failpoint-env1", Err:(*net.OpError)(0xc000172050)} ("Get http://127.0.0.1:23389/failpoint-env1: dial tcp 127.0.0.1:23389: connect: connection refused")
failed to parse "invalid" past "invalid"
failed to enable "runtime-test-2=invalid" (failpoint: could not parse terms)
----------------------------------------------------------------------
FAIL: runtime_test.go:21: runtimeSuite.TestRuntime
runtime_test.go:133:
c.Assert(ok, IsTrue)
... obtained bool = false
OOPS: 1 passed, 2 FAILED
--- FAIL: TestFailpoint (1.00s)
failed to parse "invalid" past "invalid"
failed to enable "failpoint-name=invalid" (failpoint: could not parse terms)
----------------------------------------------------------------------
FAIL: http_test.go:47: httpSuite.TestServeHTTP
http_test.go:124:
c.Assert(err, IsNil)
... value *url.Error = &url.Error{Op:"Get", URL:"http://127.0.0.1:23389/failpoint-env1", Err:(*net.OpError)(0xc000172d70)} ("Get http://127.0.0.1:23389/failpoint-env1: dial tcp 127.0.0.1:23389: connect: connection refused")
failed to parse "invalid" past "invalid"
failed to enable "runtime-test-2=invalid" (failpoint: could not parse terms)
----------------------------------------------------------------------
FAIL: runtime_test.go:21: runtimeSuite.TestRuntime
runtime_test.go:133:
c.Assert(ok, IsTrue)
... obtained bool = false
OOPS: 1 passed, 2 FAILED
--- FAIL: TestHttp (1.00s)
failed to parse "invalid" past "invalid"
failed to enable "failpoint-name=invalid" (failpoint: could not parse terms)
----------------------------------------------------------------------
FAIL: http_test.go:47: httpSuite.TestServeHTTP
http_test.go:124:
c.Assert(err, IsNil)
... value *url.Error = &url.Error{Op:"Get", URL:"http://127.0.0.1:23389/failpoint-env1", Err:(*net.OpError)(0xc000146500)} ("Get http://127.0.0.1:23389/failpoint-env1: dial tcp 127.0.0.1:23389: connect: connection refused")
failed to parse "invalid" past "invalid"
failed to enable "runtime-test-2=invalid" (failpoint: could not parse terms)
----------------------------------------------------------------------
FAIL: runtime_test.go:21: runtimeSuite.TestRuntime
runtime_test.go:133:
c.Assert(ok, IsTrue)
... obtained bool = false
OOPS: 1 passed, 2 FAILED
--- FAIL: TestNewRestorer (1.01s)
FAIL
FAIL github.com/pingcap/failpoint 3.030s
/V/d/g/s/g/p/failpoint (master|✔) [1] $
Some environment variables are required in unit/integration test, we recommend to use make test
or make gotest
. You can find more information in the Makefile
.
package testfail
import (
"errors"
"github.com/pingcap/failpoint"
"testing"
)
type ttt struct {
}
func (t ttt) Call() error{
failpoint.Inject("failpoint-test", func() {
failpoint.Return(nil)
})
return errors.New("must fail")
}
func TestCall(t*testing.T){
tt:=ttt{}
failpoint.Enable("failpoint-test","return(nil)")
err:=tt.Call()
if err!=nil{
t.Error(err)
}
}
how to make this test success?
I cannot find any example ,tell me how to use this library.
@nkbai failpoint.Enable("failpoint-test","return(nil)")
means the failpoint failpoint-test
has been activited and the Call
will return nil
. I cannot understand your intentions.
but this test is failed, and tt.Call return error ("must fail")
You must use failpoint-ctl enable
to rewrite the source file.
@nkbai for the first question, you can take a look at the target make test
and it actually expands to
GO111MODULE=on GO_FAILPOINTS="failpoint-env1=return(10);failpoint-env2=return(true)" GO_FAILPOINTS_HTTP=":23389" CGO_ENABLED=1 GO111MODULE=on go test -p 4 -v ./...
... for using failpoint
in your own project, yes you can take a look at how pingcap/tidb and tikv/client-go use it. The former uses a code generation way while the latter doesn't require code generation.
We should provide more document on its usage, though.
I'll close this issue as the document part is tracked by #29