Skip to content

Commit

Permalink
functional-tester: move checker logic to cluster
Browse files Browse the repository at this point in the history
I move the checker logic from tester to cluster so that stressers and checkers can be initialized at the same time.
this is useful because some checker depends on stressers.
  • Loading branch information
fanminshi committed Oct 18, 2016
1 parent 57008f1 commit 7d86d10
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
22 changes: 13 additions & 9 deletions tools/functional-tester/etcd-tester/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ type Checker interface {
Check() error
}

type hashAndRevGetter interface {
getRevisionHash() (revs map[string]int64, hashes map[string]int64, err error)
}

type hashChecker struct {
tt *tester
hrg hashAndRevGetter
}

func newHashChecker(tt *tester) Checker { return &hashChecker{tt} }
func newHashChecker(hrg hashAndRevGetter) Checker { return &hashChecker{hrg} }

func (hc *hashChecker) Check() (err error) {
plog.Printf("%s fetching current revisions...", hc.tt.logPrefix())
plog.Printf("fetching current revisions...")
var (
revs map[string]int64
hashes map[string]int64
Expand All @@ -40,28 +44,28 @@ func (hc *hashChecker) Check() (err error) {
for i := 0; i < 7; i++ {
time.Sleep(time.Second)

revs, hashes, err = hc.tt.cluster.getRevisionHash()
revs, hashes, err = hc.hrg.getRevisionHash()
if err != nil {
plog.Printf("%s #%d failed to get current revisions (%v)", hc.tt.logPrefix(), i, err)
plog.Printf("#%d failed to get current revisions (%v)", i, err)
continue
}
if _, ok = getSameValue(revs); ok {
break
}

plog.Printf("%s #%d inconsistent current revisions %+v", hc.tt.logPrefix(), i, revs)
plog.Printf("#%d inconsistent current revisions %+v", i, revs)
}
if !ok || err != nil {
return fmt.Errorf("checking current revisions failed [err: %v, revisions: %v]", err, revs)
}
plog.Printf("%s all members are consistent with current revisions [revisions: %v]", hc.tt.logPrefix(), revs)
plog.Printf("all members are consistent with current revisions [revisions: %v]", revs)

plog.Printf("%s checking current storage hashes...", hc.tt.logPrefix())
plog.Printf("checking current storage hashes...")
if _, ok = getSameValue(hashes); !ok {
return fmt.Errorf("inconsistent hashes [%v]", hashes)
}

plog.Printf("%s all members are consistent with storage hashes", hc.tt.logPrefix())
plog.Printf("all members are consistent with storage hashes")
return nil
}

Expand Down
22 changes: 12 additions & 10 deletions tools/functional-tester/etcd-tester/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,15 @@ type agentConfig struct {
type cluster struct {
agents []agentConfig

v2Only bool // to be deprecated
v2Only bool // to be deprecated
consistencyCheck bool
Size int

stressQPS int
stressKeyLargeSize int
stressKeySize int
stressKeySuffixRange int

Size int
Stressers []Stresser
Stressers []Stresser
stressBuilder stressBuilder
Checker Checker

Members []*member

stressBuilder stressBuilder
}

type ClusterStatus struct {
Expand Down Expand Up @@ -109,6 +105,12 @@ func (c *cluster) bootstrap() error {
go c.Stressers[i].Stress()
}

if c.consistencyCheck && !c.v2Only {
c.Checker = newHashChecker(hashAndRevGetter(c))
} else {
c.Checker = newNoChecker()
}

c.Size = size
c.Members = members
return nil
Expand Down
12 changes: 4 additions & 8 deletions tools/functional-tester/etcd-tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ func main() {
}

c := &cluster{
agents: agents,
v2Only: *isV2Only,
stressBuilder: newStressBuilder(*stresserType, sConfig),
agents: agents,
v2Only: *isV2Only,
stressBuilder: newStressBuilder(*stresserType, sConfig),
consistencyCheck: *consistencyCheck,
}

if err := c.bootstrap(); err != nil {
Expand Down Expand Up @@ -116,11 +117,6 @@ func main() {
failures: schedule,
cluster: c,
limit: *limit,
checker: newNoChecker(),
}

if *consistencyCheck && !c.v2Only {
t.checker = newHashChecker(t)
}

sh := statusHandler{status: &t.status}
Expand Down
10 changes: 4 additions & 6 deletions tools/functional-tester/etcd-tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import (
)

type tester struct {
failures []failure
cluster *cluster
limit int
checker Checker

failures []failure
cluster *cluster
limit int
status Status
currentRevision int64
}
Expand Down Expand Up @@ -146,7 +144,7 @@ func (tt *tester) checkConsistency() (err error) {
}
err = tt.startStressers()
}()
if err = tt.checker.Check(); err != nil {
if err = tt.cluster.Checker.Check(); err != nil {
plog.Printf("%s %v", tt.logPrefix(), err)
}
return err
Expand Down

0 comments on commit 7d86d10

Please sign in to comment.