fix for non-deterministic test.

This commit is contained in:
Erik Brakkee 2024-08-20 09:46:04 +02:00
parent f88def71ec
commit c55c4aa365
3 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -11,7 +11,8 @@ 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,

View File

@ -0,0 +1 @@
package testsupport