From 7d86d1050ee3a73dd8b81970f5b290e76e9178f5 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Tue, 18 Oct 2016 10:57:32 -0700 Subject: [PATCH] functional-tester: move checker logic to cluster 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. --- tools/functional-tester/etcd-tester/checks.go | 22 +++++++++++-------- .../functional-tester/etcd-tester/cluster.go | 22 ++++++++++--------- tools/functional-tester/etcd-tester/main.go | 12 ++++------ tools/functional-tester/etcd-tester/tester.go | 10 ++++----- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tools/functional-tester/etcd-tester/checks.go b/tools/functional-tester/etcd-tester/checks.go index 9b4381ef6f4..153f54b8807 100644 --- a/tools/functional-tester/etcd-tester/checks.go +++ b/tools/functional-tester/etcd-tester/checks.go @@ -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 @@ -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 } diff --git a/tools/functional-tester/etcd-tester/cluster.go b/tools/functional-tester/etcd-tester/cluster.go index c3771bbddf3..92421e6030a 100644 --- a/tools/functional-tester/etcd-tester/cluster.go +++ b/tools/functional-tester/etcd-tester/cluster.go @@ -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 { @@ -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 diff --git a/tools/functional-tester/etcd-tester/main.go b/tools/functional-tester/etcd-tester/main.go index 3574ee30bdf..10856e1d95d 100644 --- a/tools/functional-tester/etcd-tester/main.go +++ b/tools/functional-tester/etcd-tester/main.go @@ -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 { @@ -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} diff --git a/tools/functional-tester/etcd-tester/tester.go b/tools/functional-tester/etcd-tester/tester.go index 61e60449017..e7f0aa8f3ff 100644 --- a/tools/functional-tester/etcd-tester/tester.go +++ b/tools/functional-tester/etcd-tester/tester.go @@ -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 } @@ -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