mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Integration tests: Use zaptest.Logger based testing.TB
Thanks to this the logs: - are automatically printed if the test fails. - are in pretty consistent format. - are annotated by 'member' information of the cluster emitting them. Side changes: - Set propert default got DefaultWarningApplyDuration (used to be '0') - Name the members based on their 'place' on the list (as opposed to 'random')
This commit is contained in:
@@ -48,6 +48,16 @@ func SetLogger(l Logger) {
|
||||
raftLoggerMu.Unlock()
|
||||
}
|
||||
|
||||
func ResetDefaultLogger() {
|
||||
SetLogger(defaultLogger)
|
||||
}
|
||||
|
||||
func getLogger() Logger {
|
||||
raftLoggerMu.Lock()
|
||||
defer raftLoggerMu.Unlock()
|
||||
return raftLogger
|
||||
}
|
||||
|
||||
var (
|
||||
defaultLogger = &DefaultLogger{Logger: log.New(os.Stderr, "raft", log.LstdFlags)}
|
||||
discardLogger = &DefaultLogger{Logger: log.New(ioutil.Discard, "", 0)}
|
||||
|
||||
@@ -230,7 +230,7 @@ func (c *Config) validate() error {
|
||||
}
|
||||
|
||||
if c.Logger == nil {
|
||||
c.Logger = raftLogger
|
||||
c.Logger = getLogger()
|
||||
}
|
||||
|
||||
if c.ReadOnlyOption == ReadOnlyLeaseBased && !c.CheckQuorum {
|
||||
|
||||
@@ -100,7 +100,7 @@ func (s Status) MarshalJSON() ([]byte, error) {
|
||||
func (s Status) String() string {
|
||||
b, err := s.MarshalJSON()
|
||||
if err != nil {
|
||||
raftLogger.Panicf("unexpected error: %v", err)
|
||||
getLogger().Panicf("unexpected error: %v", err)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (ms *MemoryStorage) Entries(lo, hi, maxSize uint64) ([]pb.Entry, error) {
|
||||
return nil, ErrCompacted
|
||||
}
|
||||
if hi > ms.lastIndex()+1 {
|
||||
raftLogger.Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex())
|
||||
getLogger().Panicf("entries' hi(%d) is out of bound lastindex(%d)", hi, ms.lastIndex())
|
||||
}
|
||||
// only contains dummy entries.
|
||||
if len(ms.ents) == 1 {
|
||||
@@ -200,7 +200,7 @@ func (ms *MemoryStorage) CreateSnapshot(i uint64, cs *pb.ConfState, data []byte)
|
||||
|
||||
offset := ms.ents[0].Index
|
||||
if i > ms.lastIndex() {
|
||||
raftLogger.Panicf("snapshot %d is out of bound lastindex(%d)", i, ms.lastIndex())
|
||||
getLogger().Panicf("snapshot %d is out of bound lastindex(%d)", i, ms.lastIndex())
|
||||
}
|
||||
|
||||
ms.snapshot.Metadata.Index = i
|
||||
@@ -223,7 +223,7 @@ func (ms *MemoryStorage) Compact(compactIndex uint64) error {
|
||||
return ErrCompacted
|
||||
}
|
||||
if compactIndex > ms.lastIndex() {
|
||||
raftLogger.Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex())
|
||||
getLogger().Panicf("compact %d is out of bound lastindex(%d)", compactIndex, ms.lastIndex())
|
||||
}
|
||||
|
||||
i := compactIndex - offset
|
||||
@@ -266,7 +266,7 @@ func (ms *MemoryStorage) Append(entries []pb.Entry) error {
|
||||
case uint64(len(ms.ents)) == offset:
|
||||
ms.ents = append(ms.ents, entries...)
|
||||
default:
|
||||
raftLogger.Panicf("missing log entry [last: %d, append at: %d]",
|
||||
getLogger().Panicf("missing log entry [last: %d, append at: %d]",
|
||||
ms.lastIndex(), entries[0].Index)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user