fix for non-deterministic test.
This commit is contained in:
parent
f88def71ec
commit
c55c4aa365
@ -51,7 +51,17 @@ func (rw *ChannelReadWriter) Write(p []byte) (n int, err error) {
|
|||||||
if rw.closed {
|
if rw.closed {
|
||||||
return 0, errors.New("Write on closed channel")
|
return 0, errors.New("Write on closed channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if context is canceled it should never write
|
||||||
select {
|
select {
|
||||||
|
case <-rw.ctx.Done():
|
||||||
|
rw.Close()
|
||||||
|
return 0, io.ErrClosedPipe
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
// deal with closing duirng the write
|
||||||
case <-rw.ctx.Done():
|
case <-rw.ctx.Done():
|
||||||
rw.Close()
|
rw.Close()
|
||||||
return 0, io.ErrClosedPipe
|
return 0, io.ErrClosedPipe
|
||||||
|
@ -12,6 +12,7 @@ type InmemoryConnection struct {
|
|||||||
func NewInmemoryConnection(ctx context.Context, addr string) *InmemoryConnection {
|
func NewInmemoryConnection(ctx context.Context, addr string) *InmemoryConnection {
|
||||||
pipe := InmemoryConnection{
|
pipe := InmemoryConnection{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
|
// arbitrary unbuffered channel, unbuffered is more similar to TCP connections.
|
||||||
frontToBack: make(chan []byte),
|
frontToBack: make(chan []byte),
|
||||||
backToFront: make(chan []byte),
|
backToFront: make(chan []byte),
|
||||||
addr: addr,
|
addr: addr,
|
||||||
|
1
pkg/testsupport/inmemoryconnection_test.go
Normal file
1
pkg/testsupport/inmemoryconnection_test.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package testsupport
|
Loading…
Reference in New Issue
Block a user