mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #7939 from gyuho/test
etcd-tester: add '-failpoints' to configure gofail
This commit is contained in:
commit
0afc51c762
@ -32,7 +32,7 @@ type failpointStats struct {
|
|||||||
|
|
||||||
var fpStats failpointStats
|
var fpStats failpointStats
|
||||||
|
|
||||||
func failpointFailures(c *cluster) (ret []failure, err error) {
|
func failpointFailures(c *cluster, failpoints []string) (ret []failure, err error) {
|
||||||
var fps []string
|
var fps []string
|
||||||
fps, err = failpointPaths(c.Members[0].FailpointURL)
|
fps, err = failpointPaths(c.Members[0].FailpointURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -43,7 +43,7 @@ func failpointFailures(c *cluster) (ret []failure, err error) {
|
|||||||
if len(fp) == 0 {
|
if len(fp) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fpFails := failuresFromFailpoint(fp)
|
fpFails := failuresFromFailpoint(fp, failpoints)
|
||||||
// wrap in delays so failpoint has time to trigger
|
// wrap in delays so failpoint has time to trigger
|
||||||
for i, fpf := range fpFails {
|
for i, fpf := range fpFails {
|
||||||
if strings.Contains(fp, "Snap") {
|
if strings.Contains(fp, "Snap") {
|
||||||
@ -77,34 +77,39 @@ func failpointPaths(endpoint string) ([]string, error) {
|
|||||||
return fps, nil
|
return fps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func failuresFromFailpoint(fp string) []failure {
|
// failpoints follows FreeBSD KFAIL_POINT syntax.
|
||||||
inject := makeInjectFailpoint(fp, `panic("etcd-tester")`)
|
// e.g. panic("etcd-tester"),1*sleep(1000)->panic("etcd-tester")
|
||||||
|
func failuresFromFailpoint(fp string, failpoints []string) (fs []failure) {
|
||||||
recov := makeRecoverFailpoint(fp)
|
recov := makeRecoverFailpoint(fp)
|
||||||
return []failure{
|
for _, failpoint := range failpoints {
|
||||||
&failureOne{
|
inject := makeInjectFailpoint(fp, failpoint)
|
||||||
description: description("failpoint " + fp + " panic one"),
|
fs = append(fs, []failure{
|
||||||
injectMember: inject,
|
&failureOne{
|
||||||
recoverMember: recov,
|
description: description(fmt.Sprintf("failpoint %s (one: %s)", fp, failpoint)),
|
||||||
},
|
|
||||||
&failureAll{
|
|
||||||
description: description("failpoint " + fp + " panic all"),
|
|
||||||
injectMember: inject,
|
|
||||||
recoverMember: recov,
|
|
||||||
},
|
|
||||||
&failureMajority{
|
|
||||||
description: description("failpoint " + fp + " panic majority"),
|
|
||||||
injectMember: inject,
|
|
||||||
recoverMember: recov,
|
|
||||||
},
|
|
||||||
&failureLeader{
|
|
||||||
failureByFunc{
|
|
||||||
description: description("failpoint " + fp + " panic leader"),
|
|
||||||
injectMember: inject,
|
injectMember: inject,
|
||||||
recoverMember: recov,
|
recoverMember: recov,
|
||||||
},
|
},
|
||||||
0,
|
&failureAll{
|
||||||
},
|
description: description(fmt.Sprintf("failpoint %s (all: %s)", fp, failpoint)),
|
||||||
|
injectMember: inject,
|
||||||
|
recoverMember: recov,
|
||||||
|
},
|
||||||
|
&failureMajority{
|
||||||
|
description: description(fmt.Sprintf("failpoint %s (majority: %s)", fp, failpoint)),
|
||||||
|
injectMember: inject,
|
||||||
|
recoverMember: recov,
|
||||||
|
},
|
||||||
|
&failureLeader{
|
||||||
|
failureByFunc{
|
||||||
|
description: description(fmt.Sprintf("failpoint %s (leader: %s)", fp, failpoint)),
|
||||||
|
injectMember: inject,
|
||||||
|
recoverMember: recov,
|
||||||
|
},
|
||||||
|
0,
|
||||||
|
},
|
||||||
|
}...)
|
||||||
}
|
}
|
||||||
|
return fs
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeInjectFailpoint(fp, val string) injectMemberFunc {
|
func makeInjectFailpoint(fp, val string) injectMemberFunc {
|
||||||
|
@ -52,6 +52,7 @@ func main() {
|
|||||||
stresserType := flag.String("stresser", "keys,lease", "comma separated list of stressers (keys, lease, v2keys, nop, election-runner, watch-runner, lock-racer-runner, lease-runner).")
|
stresserType := flag.String("stresser", "keys,lease", "comma separated list of stressers (keys, lease, v2keys, nop, election-runner, watch-runner, lock-racer-runner, lease-runner).")
|
||||||
etcdRunnerPath := flag.String("etcd-runner", "", "specify a path of etcd runner binary")
|
etcdRunnerPath := flag.String("etcd-runner", "", "specify a path of etcd runner binary")
|
||||||
failureTypes := flag.String("failures", "default,failpoints", "specify failures (concat of \"default\" and \"failpoints\").")
|
failureTypes := flag.String("failures", "default,failpoints", "specify failures (concat of \"default\" and \"failpoints\").")
|
||||||
|
failpoints := flag.String("failpoints", `panic("etcd-tester")`, `comma separated list of failpoint terms to inject (e.g. 'panic("etcd-tester"),1*sleep(1000)')`)
|
||||||
externalFailures := flag.String("external-failures", "", "specify a path of script for enabling/disabling an external fault injector")
|
externalFailures := flag.String("external-failures", "", "specify a path of script for enabling/disabling an external fault injector")
|
||||||
enablePprof := flag.Bool("enable-pprof", false, "true to enable pprof")
|
enablePprof := flag.Bool("enable-pprof", false, "true to enable pprof")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -81,7 +82,8 @@ func main() {
|
|||||||
var failures []failure
|
var failures []failure
|
||||||
|
|
||||||
if failureTypes != nil && *failureTypes != "" {
|
if failureTypes != nil && *failureTypes != "" {
|
||||||
failures = makeFailures(*failureTypes, c)
|
types, failpoints := strings.Split(*failureTypes, ","), strings.Split(*failpoints, ",")
|
||||||
|
failures = makeFailures(types, failpoints, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
if externalFailures != nil && *externalFailures != "" {
|
if externalFailures != nil && *externalFailures != "" {
|
||||||
@ -170,12 +172,10 @@ func portsFromArg(arg string, n, defaultPort int) []int {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeFailures(types string, c *cluster) []failure {
|
func makeFailures(types, failpoints []string, c *cluster) []failure {
|
||||||
var failures []failure
|
var failures []failure
|
||||||
|
for i := range types {
|
||||||
fails := strings.Split(types, ",")
|
switch types[i] {
|
||||||
for i := range fails {
|
|
||||||
switch fails[i] {
|
|
||||||
case "default":
|
case "default":
|
||||||
defaultFailures := []failure{
|
defaultFailures := []failure{
|
||||||
newFailureKillAll(),
|
newFailureKillAll(),
|
||||||
@ -193,14 +193,14 @@ func makeFailures(types string, c *cluster) []failure {
|
|||||||
failures = append(failures, defaultFailures...)
|
failures = append(failures, defaultFailures...)
|
||||||
|
|
||||||
case "failpoints":
|
case "failpoints":
|
||||||
fpFailures, fperr := failpointFailures(c)
|
fpFailures, fperr := failpointFailures(c, failpoints)
|
||||||
if len(fpFailures) == 0 {
|
if len(fpFailures) == 0 {
|
||||||
plog.Infof("no failpoints found (%v)", fperr)
|
plog.Infof("no failpoints found (%v)", fperr)
|
||||||
}
|
}
|
||||||
failures = append(failures, fpFailures...)
|
failures = append(failures, fpFailures...)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
plog.Errorf("unknown failure: %s\n", fails[i])
|
plog.Errorf("unknown failure: %s\n", types[i])
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user