mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #3992 from xiang90/fix_rafthttp_test
rafhttp: make TestStreamWriterAttachOutgoingConn more robust
This commit is contained in:
commit
6f59a15e55
@ -42,25 +42,39 @@ func TestStreamWriterAttachOutgoingConn(t *testing.T) {
|
|||||||
t.Errorf("initial working status = %v, want false", ok)
|
t.Errorf("initial working status = %v, want false", ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
// repeatitive tests to ensure it can use latest connection
|
// repeat tests to ensure streamWriter can use last attached connection
|
||||||
var wfc *fakeWriteFlushCloser
|
var wfc *fakeWriteFlushCloser
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
prevwfc := wfc
|
prevwfc := wfc
|
||||||
wfc = &fakeWriteFlushCloser{}
|
wfc = &fakeWriteFlushCloser{}
|
||||||
sw.attach(&outgoingConn{t: streamTypeMessage, Writer: wfc, Flusher: wfc, Closer: wfc})
|
sw.attach(&outgoingConn{t: streamTypeMessage, Writer: wfc, Flusher: wfc, Closer: wfc})
|
||||||
|
|
||||||
|
// sw.attach happens asynchronously. Waits for its result in a for loop to make the
|
||||||
|
// test more robust on slow CI.
|
||||||
|
for j := 0; j < 3; j++ {
|
||||||
testutil.WaitSchedule()
|
testutil.WaitSchedule()
|
||||||
|
// previous attached connection should be closed
|
||||||
|
if prevwfc != nil && prevwfc.Closed() != true {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// write chan is available
|
||||||
|
if _, ok := sw.writec(); ok != true {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// previous attached connection should be closed
|
// previous attached connection should be closed
|
||||||
if prevwfc != nil && prevwfc.Closed() != true {
|
if prevwfc != nil && prevwfc.Closed() != true {
|
||||||
t.Errorf("#%d: close of previous connection = %v, want true", i, prevwfc.Closed())
|
t.Errorf("#%d: close of previous connection = %v, want true", i, prevwfc.Closed())
|
||||||
}
|
}
|
||||||
// starts working
|
// write chan is available
|
||||||
if _, ok := sw.writec(); ok != true {
|
if _, ok := sw.writec(); ok != true {
|
||||||
t.Errorf("#%d: working status = %v, want true", i, ok)
|
t.Errorf("#%d: working status = %v, want true", i, ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.msgc <- raftpb.Message{}
|
sw.msgc <- raftpb.Message{}
|
||||||
testutil.WaitSchedule()
|
testutil.WaitSchedule()
|
||||||
// still working
|
// write chan is available
|
||||||
if _, ok := sw.writec(); ok != true {
|
if _, ok := sw.writec(); ok != true {
|
||||||
t.Errorf("#%d: working status = %v, want true", i, ok)
|
t.Errorf("#%d: working status = %v, want true", i, ok)
|
||||||
}
|
}
|
||||||
@ -70,7 +84,7 @@ func TestStreamWriterAttachOutgoingConn(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sw.stop()
|
sw.stop()
|
||||||
// no longer in working status now
|
// write chan is unavailable since the writer is stopped.
|
||||||
if _, ok := sw.writec(); ok != false {
|
if _, ok := sw.writec(); ok != false {
|
||||||
t.Errorf("working status after stop = %v, want false", ok)
|
t.Errorf("working status after stop = %v, want false", ok)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user