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

tests/linearizability: added sleep fail point injection #14796

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/etcdserver/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (r *raftNode) tick() {
// to modify the fields after it has been started.
func (r *raftNode) start(rh *raftReadyHandler) {
internalTimeout := time.Second

// gofail: var raftBeforeStart struct{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that this is not a useful gofail point so let's not add it. If you want to test sleep failpoint you can just use other ones like backend/defragBeforeCopy.

go func() {
defer r.onStop()
islead := false
Expand Down
54 changes: 54 additions & 0 deletions tests/linearizability/failpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/url"
Expand All @@ -31,6 +32,7 @@ import (
)

var (
SleepFailPoint Failpoint = sleepFailpoint{"etcdserver/sleepFailPoint", "sleep(200)"}
KillFailpoint Failpoint = killFailpoint{}
DefragBeforeCopyPanic Failpoint = goFailpoint{"backend/defragBeforeCopy", "panic", triggerDefrag}
DefragBeforeRenamePanic Failpoint = goFailpoint{"backend/defragBeforeRename", "panic", triggerDefrag}
Expand Down Expand Up @@ -75,6 +77,58 @@ type Failpoint interface {
Name() string
}

type sleepFailpoint struct {
failpoint string
payload string
}

func (sf sleepFailpoint) Name() string {
return sf.failpoint
}

func (sf sleepFailpoint) Trigger(ctx context.Context, clus *e2e.EtcdProcessCluster) error {
member := clus.Procs[rand.Int()%len(clus.Procs)]
address := fmt.Sprintf("127.0.0.1:%d", member.Config().GoFailPort)
err := setupSleepFailpoint(address, sf.failpoint, sf.payload)
if err != nil {
return fmt.Errorf("sleep gofailpoint setup failed: %w", err)
}
return nil
}

func setupSleepFailpoint(host, failpoint, payload string) error {
//payload should be in the form of: 'sleep(600)'
err := setupGoFailpoint(host, failpoint, payload)
if err != nil {
return err
}
failpointsUrl := url.URL{
Scheme: "http",
Host: host,
Path: failpoint,
}
//check whether sleep was enabled
r, err := http.NewRequest("GET", failpointsUrl.String(), nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is needed. If setupGoFailpoint succeeded then we can assume that sleep was enabled.

if err != nil {
return err
}
resp, err := httpClient.Do(r)
if err != nil {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
respStr := strings.TrimSpace(string(body))

if !strings.Contains(payload, respStr) {
return fmt.Errorf("sleep gofailpoint is not enabled: %s: ", failpoint)
}
return nil
}

type killFailpoint struct{}

func (f killFailpoint) Trigger(ctx context.Context, clus *e2e.EtcdProcessCluster) error {
Expand Down