mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcd-tester: split out consistency checking code from tester
This commit is contained in:
parent
b586060812
commit
d4eff5381c
71
tools/functional-tester/etcd-tester/checks.go
Normal file
71
tools/functional-tester/etcd-tester/checks.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// Copyright 2016 The etcd Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Checker interface {
|
||||||
|
// Check returns an error if the system fails a consistency check.
|
||||||
|
Check() error
|
||||||
|
}
|
||||||
|
|
||||||
|
type hashChecker struct {
|
||||||
|
tt *tester
|
||||||
|
}
|
||||||
|
|
||||||
|
func newHashChecker(tt *tester) Checker { return &hashChecker{tt} }
|
||||||
|
|
||||||
|
func (hc *hashChecker) Check() (err error) {
|
||||||
|
plog.Printf("%s fetching current revisions...", hc.tt.logPrefix())
|
||||||
|
var (
|
||||||
|
revs map[string]int64
|
||||||
|
hashes map[string]int64
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
for i := 0; i < 7; i++ {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
|
revs, hashes, err = hc.tt.cluster.getRevisionHash()
|
||||||
|
if err != nil {
|
||||||
|
plog.Printf("%s #%d failed to get current revisions (%v)", hc.tt.logPrefix(), i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok = getSameValue(revs); ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
plog.Printf("%s #%d inconsistent current revisions %+v", hc.tt.logPrefix(), 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("%s checking current storage hashes...", hc.tt.logPrefix())
|
||||||
|
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())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type noChecker struct{}
|
||||||
|
|
||||||
|
func newNoChecker() Checker { return &noChecker{} }
|
||||||
|
func (nc *noChecker) Check() error { return nil }
|
@ -117,7 +117,11 @@ func main() {
|
|||||||
failures: schedule,
|
failures: schedule,
|
||||||
cluster: c,
|
cluster: c,
|
||||||
limit: *limit,
|
limit: *limit,
|
||||||
consistencyCheck: *consistencyCheck,
|
checker: newNoChecker(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if *consistencyCheck && !c.v2Only {
|
||||||
|
t.checker = newHashChecker(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
sh := statusHandler{status: &t.status}
|
sh := statusHandler{status: &t.status}
|
||||||
|
@ -23,7 +23,7 @@ type tester struct {
|
|||||||
failures []failure
|
failures []failure
|
||||||
cluster *cluster
|
cluster *cluster
|
||||||
limit int
|
limit int
|
||||||
consistencyCheck bool
|
checker Checker
|
||||||
|
|
||||||
status Status
|
status Status
|
||||||
currentRevision int64
|
currentRevision int64
|
||||||
@ -109,82 +109,47 @@ func (tt *tester) doRound(round int) (bool, error) {
|
|||||||
}
|
}
|
||||||
plog.Printf("%s recovered failure", tt.logPrefix())
|
plog.Printf("%s recovered failure", tt.logPrefix())
|
||||||
|
|
||||||
if tt.cluster.v2Only {
|
|
||||||
plog.Printf("%s succeed!", tt.logPrefix())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !tt.consistencyCheck {
|
|
||||||
if err := tt.updateRevision(); err != nil {
|
|
||||||
plog.Warningf("%s functional-tester returning with tt.updateRevision error (%v)", tt.logPrefix(), err)
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := tt.checkConsistency(); err != nil {
|
if err := tt.checkConsistency(); err != nil {
|
||||||
plog.Warningf("%s functional-tester returning with tt.checkConsistency error (%v)", tt.logPrefix(), err)
|
plog.Warningf("%s functional-tester returning with tt.checkConsistency error (%v)", tt.logPrefix(), err)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
plog.Printf("%s succeed!", tt.logPrefix())
|
plog.Printf("%s succeed!", tt.logPrefix())
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tt *tester) updateRevision() error {
|
func (tt *tester) updateRevision() error {
|
||||||
|
if tt.cluster.v2Only {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
revs, _, err := tt.cluster.getRevisionHash()
|
revs, _, err := tt.cluster.getRevisionHash()
|
||||||
for _, rev := range revs {
|
for _, rev := range revs {
|
||||||
tt.currentRevision = rev
|
tt.currentRevision = rev
|
||||||
break // just need get one of the current revisions
|
break // just need get one of the current revisions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plog.Printf("%s updated current revision to %d", tt.logPrefix(), tt.currentRevision)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tt *tester) checkConsistency() (err error) {
|
func (tt *tester) checkConsistency() (err error) {
|
||||||
tt.cancelStressers()
|
tt.cancelStressers()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
|
||||||
err = tt.startStressers()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
plog.Printf("%s updating current revisions...", tt.logPrefix())
|
|
||||||
var (
|
|
||||||
revs map[string]int64
|
|
||||||
hashes map[string]int64
|
|
||||||
ok bool
|
|
||||||
)
|
|
||||||
for i := 0; i < 7; i++ {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
|
|
||||||
revs, hashes, err = tt.cluster.getRevisionHash()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
plog.Printf("%s #%d failed to get current revisions (%v)", tt.logPrefix(), i, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if tt.currentRevision, ok = getSameValue(revs); ok {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
plog.Printf("%s #%d inconsistent current revisions %+v", tt.logPrefix(), i, revs)
|
|
||||||
}
|
|
||||||
if !ok || err != nil {
|
|
||||||
err = fmt.Errorf("checking current revisions failed [err: %v, revisions: %v]", err, revs)
|
|
||||||
plog.Printf("%s %v", tt.logPrefix(), err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
plog.Printf("%s all members are consistent with current revisions [revisions: %v]", tt.logPrefix(), revs)
|
if err = tt.updateRevision(); err != nil {
|
||||||
|
plog.Warningf("%s functional-tester returning with tt.updateRevision error (%v)", tt.logPrefix(), err)
|
||||||
plog.Printf("%s checking current storage hashes...", tt.logPrefix())
|
|
||||||
if _, ok = getSameValue(hashes); !ok {
|
|
||||||
err = fmt.Errorf("inconsistent hashes [%v]", hashes)
|
|
||||||
plog.Printf("%s %v", tt.logPrefix(), err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
plog.Printf("%s all members are consistent with storage hashes", tt.logPrefix())
|
err = tt.startStressers()
|
||||||
|
}()
|
||||||
plog.Printf("%s updated current revision to %d", tt.logPrefix(), tt.currentRevision)
|
if err = tt.checker.Check(); err != nil {
|
||||||
return nil
|
plog.Printf("%s %v", tt.logPrefix(), err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tt *tester) compact(rev int64, timeout time.Duration) (err error) {
|
func (tt *tester) compact(rev int64, timeout time.Duration) (err error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user