Error log output is not clear enough in TestRawNodeRestart2AC
RagingSpud opened this issue · 3 comments
RagingSpud commented
When i failed this test, i get error log:
g = {SoftState:<nil> HardState:{Term:0 Vote:0 Commit:0 XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0} Entries:[] Snapshot:{Data:[] Metadata:<nil> XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0} CommittedEntries:[{EntryType:EntryNormal Term:1 Index:1 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}] Messages:[]},
w {SoftState:<nil> HardState:{Term:0 Vote:0 Commit:0 XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0} Entries:[] Snapshot:{Data:[] Metadata:<nil> XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0} CommittedEntries:[{EntryType:EntryNormal Term:1 Index:1 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}] Messages:[]}
which is very confused cause the log suggest that w(the test wanted result) and g(my result) are same.
The actual case is that my result contained a nil slice and the test require an empty slice.The test log used %+v
to print an object so it failed to show the difference between a nil slice and an empty slice.
if !reflect.DeepEqual(rd, want) {
t.Errorf("g = %+v,\n w %+v", rd, want)
}
I thought maybe we could use %#v
to replace %+v
.Is that a good idea?
Connor1996 commented
How is the output of %#v
?
RagingSpud commented
How is the output of
%#v
?
g = raft.Ready{SoftState:(*raft.SoftState)(nil), HardState:eraftpb.HardState{Term:0x0, Vote:0x0, Commit:0x0, XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}, Entries:[]eraftpb.Entry(nil), Snapshot:eraftpb.Snapshot{Data:[]uint8(nil), Metadata:(*eraftpb.SnapshotMetadata)(nil), XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}, CommittedEntries:[]eraftpb.Entry{eraftpb.Entry{EntryType:0, Term:0x1, Index:0x1, Data:[]uint8(nil), XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}}, Messages:[]eraftpb.Message(nil)},
w raft.Ready{SoftState:(*raft.SoftState)(nil), HardState:eraftpb.HardState{Term:0x0, Vote:0x0, Commit:0x0, XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}, Entries:[]eraftpb.Entry{}, Snapshot:eraftpb.Snapshot{Data:[]uint8(nil), Metadata:(*eraftpb.SnapshotMetadata)(nil), XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}, CommittedEntries:[]eraftpb.Entry{eraftpb.Entry{EntryType:0, Term:0x1, Index:0x1, Data:[]uint8(nil), XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}}, Messages:[]eraftpb.Message(nil)}
Entries:[]eraftpb.Entry(nil) and Entries:[]eraftpb.Entry{}
Connor1996 commented
Reasonable