Skip to content

Commit

Permalink
e2e: add TestCtlV3Corrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuho committed Sep 19, 2017
1 parent dd7db5b commit c68824c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions e2e/cluster_test.go
Expand Up @@ -20,6 +20,7 @@ import (
"net/url"
"os"
"strings"
"time"

"github.com/coreos/etcd/etcdserver"
)
Expand Down Expand Up @@ -115,6 +116,7 @@ type etcdProcessClusterConfig struct {
forceNewCluster bool
initialToken string
quotaBackendBytes int64
corruptCheckTime time.Duration
noStrictReconfig bool
}

Expand Down Expand Up @@ -221,6 +223,11 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro
"--quota-backend-bytes", fmt.Sprintf("%d", cfg.quotaBackendBytes),
)
}
if cfg.corruptCheckTime > 0 {
args = append(args,
"--experimental-corrupt-check-time", cfg.corruptCheckTime.String(),
)
}
if cfg.noStrictReconfig {
args = append(args, "--strict-reconfig-check=false")
}
Expand Down
58 changes: 58 additions & 0 deletions e2e/ctl_v3_alarm_test.go
Expand Up @@ -16,12 +16,16 @@ package e2e

import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/mvcc"
"github.com/coreos/etcd/mvcc/backend"
)

func TestCtlV3Alarm(t *testing.T) {
Expand Down Expand Up @@ -99,6 +103,60 @@ func alarmTest(cx ctlCtx) {
}
}

func TestCtlV3Corrupt(t *testing.T) {
testCtl(t, corruptTest, withCfg(configNoTLS), withQuorum(), withCorruptCheckTime(2*time.Second))
}

type fakeConsistentIndex struct{ rev uint64 }

func (f *fakeConsistentIndex) ConsistentIndex() uint64 { return f.rev }

func corruptTest(cx ctlCtx) {
for i := 0; i < 10; i++ {
if err := ctlV3Put(cx, "k", "v", ""); err != nil {
if cx.dialTimeout > 0 && !isGRPCTimedout(err) {
cx.t.Fatalf("putTest ctlV3Put error (%v)", err)
}
}
}

eps := cx.epc.EndpointsV3()
cli1, err := clientv3.New(clientv3.Config{Endpoints: []string{eps[1]}, DialTimeout: 3 * time.Second})
if err != nil {
cx.t.Fatal(err)
}
defer cli1.Close()

sresp, err := cli1.Status(context.TODO(), eps[0])
if err != nil {
cx.t.Fatal(err)
}
id0 := sresp.Header.GetMemberId()

cx.epc.procs[0].Stop()

// Corrupt member 0 by modifying backend offline.
fp := filepath.Join(cx.epc.procs[0].Config().dataDirPath, "member", "snap", "db")
be := backend.NewDefaultBackend(fp)
s := mvcc.NewStore(be, nil, &fakeConsistentIndex{13})
s.Put([]byte("abc"), []byte("def"), 0)
s.Put([]byte("xyz"), []byte("123"), 0)
s.Compact(5)
s.Commit()
s.Close()
be.Close()

ep := cx.epc.procs[0]
proc, err := spawnCmd(append([]string{ep.Config().execPath}, ep.Config().args...))
if err != nil {
cx.t.Fatal(err)
}
defer proc.Stop()

// restarting corrupted member should fail
waitReadyExpectProc(proc, []string{fmt.Sprintf("etcdserver: %016x is corrupted", id0)})
}

func ctlV3Alarm(cx ctlCtx, cmd string, as ...string) error {
cmdArgs := append(cx.PrefixArgs(), "alarm", cmd)
return spawnWithExpects(cmdArgs, as...)
Expand Down
8 changes: 8 additions & 0 deletions e2e/ctl_v3_test.go
Expand Up @@ -55,6 +55,7 @@ type ctlCtx struct {
t *testing.T
cfg etcdProcessClusterConfig
quotaBackendBytes int64
corruptCheckTime time.Duration
noStrictReconfig bool

epc *etcdProcessCluster
Expand Down Expand Up @@ -101,6 +102,10 @@ func withQuota(b int64) ctlOption {
return func(cx *ctlCtx) { cx.quotaBackendBytes = b }
}

func withCorruptCheckTime(d time.Duration) ctlOption {
return func(cx *ctlCtx) { cx.corruptCheckTime = d }
}

func withCompactPhysical() ctlOption {
return func(cx *ctlCtx) { cx.compactPhysical = true }
}
Expand Down Expand Up @@ -130,6 +135,9 @@ func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
if ret.quotaBackendBytes > 0 {
ret.cfg.quotaBackendBytes = ret.quotaBackendBytes
}
if ret.corruptCheckTime > 0 {
ret.cfg.corruptCheckTime = ret.corruptCheckTime
}
ret.cfg.noStrictReconfig = ret.noStrictReconfig

epc, err := newEtcdProcessCluster(&ret.cfg)
Expand Down

0 comments on commit c68824c

Please sign in to comment.