Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions pkg/fftls/fftls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"strings"
"testing"
"time"
"io"

"github.com/hyperledger/firefly-common/pkg/config"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -100,28 +101,42 @@ func buildTLSListener(t *testing.T, conf config.Section, tlsType TLSType) (strin
server, err := tls.Listen("tcp4", "127.0.0.1:0", tlsConfig)
assert.NoError(t, err)

done := make(chan struct{})

go func() {
for {
tlsConn, err := server.Accept()
if err != nil {
t.Logf("Server ending: %s", err)
select {
case <-done:
return // cleanup in progress, don't log
default:
t.Logf("Server ending: %s", err)
}
return
}
// Just read until EOF, echoing back
for {
oneByte := make([]byte, 1)
_, err = tlsConn.Read(oneByte)
if err != nil {
t.Logf("read failed: %s", err)
select {
case <-done:
// cleanup in progress, don't log
default:
if err != io.EOF {
t.Logf("read failed: %s", err)
}
Comment on lines +127 to +129
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should actually log EOF's here - as they are not expected if we are not <-done now that I think about it.

The bug was that we do a t.Logf after the test completed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't make sense, t should still be captured in the context of this go thread..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or does it get set to nil by the framework?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it never gets nil'ed, its just that if you call Logf on a t who's test has completed, it will panic.

That could occur bc this was in a separate Goroutine that might not shut down quick enough as the test concludes. So the <-done helps prevent all that primarily.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see so it's the test framework that panics gotcha

}
break
}
_, err = tlsConn.Write(oneByte)
assert.NoError(t, err)
_, _ = tlsConn.Write(oneByte) // ignore write errors during shutdown
}
tlsConn.Close()
}
}()
return server.Addr().String(), func() {
close(done)
err := server.Close()
assert.NoError(t, err)
}
Expand Down