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

Is there any demo or userguide for failpoint? #29

Open
sh1yu opened this issue May 1, 2019 · 7 comments
Open

Is there any demo or userguide for failpoint? #29

sh1yu opened this issue May 1, 2019 · 7 comments
Labels
question Further information is requested

Comments

@sh1yu
Copy link

sh1yu commented May 1, 2019

I cannot have any idea that how to use failpoint. I tried write demo like this:

 var outerVar = "declare in outer scope"

err := failpoint.Enable("failpoint-name", "return")
if err != nil {
	fmt.Println(err)
	return
}

failpoint.Inject("failpoint-name", func(val failpoint.Value) {
	fmt.Println("unit-test", val, outerVar)
})

There isn't have any output. How could I use it in the right way?

@sh1yu sh1yu added the question Further information is requested label May 1, 2019
@yuanbiancom
Copy link

+1. I wrote something like:

        fmt.Println("Testing failpoint")
	err := failpoint.Enable("TestFailpoint", "return(1)")
	if err != nil {
		panic(err)
	}
	failpoint.Inject("TestFailpoint", func(val failpoint.Value) {
		fmt.Println("enter TestFailpoint")
		fmt.Println("Print 002")
	})
	fmt.Println("Print 001")

The closure in Inject func never run. I also tried to enable failpoint via env GO_FAILPOINT, but didn't work either.

When i run failpoint.Enable, then i run Eval, it worked. But seems it failed on replace marker func.

@lonng
Copy link
Contributor

lonng commented May 6, 2019

You should execute failpoint-ctl enable in your workspace. Reference: https://github.com/pingcap/tidb/blob/190990b352b4939c75a60722573ab3f29baa9351/Makefile#L27

@yuanbiancom
Copy link

yuanbiancom commented May 7, 2019

You should execute failpoint-ctl enable in your workspace. Reference: https://github.com/pingcap/tidb/blob/190990b352b4939c75a60722573ab3f29baa9351/Makefile#L27

I do make and get a failpoint-ctl:

GO111MODULE=on CGO_ENABLED=0 GO111MODULE=on go build  -ldflags '-X "github.com/pingcap/failpoint/failpoint-ctl/version.releaseVersion=bf45ab2" -X "github.com/pingcap/failpoint/failpoint-ctl/version.buildTS=2019-05-06 12:56:14" -X "github.com/pingcap/failpoint/failpoint-ctl/version.gitHash=bf45ab20bfc48d624b61944a4820768c16d7db99" -X "github.com/pingcap/failpoint/failpoint-ctl/version.gitBranch=master" -X "github.com/pingcap/failpoint/failpoint-ctl/version.goVersion=go version go1.11.5 darwin/amd64"' -o bin/failpoint-ctl failpoint-ctl/main.go
go: finding github.com/nicksnyder/go-i18n v1.10.0
go: finding github.com/go-playground/overalls v0.0.0-20180201144345-22ec1a223b7c
go: finding github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
go: finding github.com/pelletier/go-toml v1.3.0
go: finding github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8
go: finding github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf
go: finding github.com/yookoala/realpath v1.0.0
go: finding gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c
go: finding gopkg.in/alecthomas/gometalinter.v2 v2.0.12
go: finding github.com/davecgh/go-spew v1.1.1
go: finding github.com/BurntSushi/toml v0.3.1
go: finding gopkg.in/yaml.v2 v2.2.2
go: finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
failpoint-ctl build successfully :-) !

then when i try to use the ctl, i get this:

ru:~user$ failpoint-ctl enable
Rewrite error /Users/ru/.Trash/authExample.go:1:1: expected 'package', found 'var'

is there anything i do wrong this time? many thanks!

@lonng
Copy link
Contributor

lonng commented May 7, 2019

Your file /Users/ru/.Trash/authExample.go does not start with package **, which means that is not a valid Golang source file.

@yuanbiancom
Copy link

Your file /Users/ru/.Trash/authExample.go does not start with package **, which means that is not a valid Golang source file.

sorry, my mistake, i didn't add the path. Thanks for you help!

@sdojjy
Copy link
Member

sdojjy commented May 8, 2019

Can we add this information into the README file?

@lonng
Copy link
Contributor

lonng commented May 8, 2019

@sdojjy Sure,file a PR is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants