Skip to content

Commit

Permalink
Small test cleanups (#551)
Browse files Browse the repository at this point in the history
* Listen on 127.0.0.1:0 instead of :0

* Add missing waitgroup Wait to relay test
  • Loading branch information
akshayjshah authored and prashantv committed Dec 21, 2016
1 parent eda0488 commit 7b39616
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hyperbahn/advertise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func withSetup(t *testing.T, f func(ch *tchannel.Channel, hostPort string)) {
serverCh, err := tchannel.NewChannel(hyperbahnServiceName, nil)
require.NoError(t, err)
defer serverCh.Close()
listener, err := net.Listen("tcp", ":0")
listener, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
serverCh.Serve(listener)

Expand Down
6 changes: 3 additions & 3 deletions init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestUnexpectedInitReq(t *testing.T) {
ch, err := NewChannel("test", nil)
require.NoError(t, err)
defer ch.Close()
require.NoError(t, ch.ListenAndServe(":0"))
require.NoError(t, ch.ListenAndServe("127.0.0.1:0"))
hostPort := ch.PeerInfo().HostPort

conn, err := net.Dial("tcp", hostPort)
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestHandleInitReqNewVersion(t *testing.T) {
ch, err := NewChannel("test", nil)
require.NoError(t, err)
defer ch.Close()
require.NoError(t, ch.ListenAndServe(":0"))
require.NoError(t, ch.ListenAndServe("127.0.0.1:0"))
hostPort := ch.PeerInfo().HostPort

conn, err := net.Dial("tcp", hostPort)
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestInitReqGetsError(t *testing.T) {
}

func newListener(t *testing.T) net.Listener {
l, err := net.Listen("tcp", ":0")
l, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err, "Listen failed")
return l
}
2 changes: 1 addition & 1 deletion json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestHeadersForwarded(t *testing.T) {
"forward": handler.forward,
"leaf": handler.leaf,
}, handler.onError))
assert.NoError(t, ch.ListenAndServe(":0"))
assert.NoError(t, ch.ListenAndServe("127.0.0.1:0"))

rootArg := &ForwardArgs{
Service: "svc",
Expand Down
1 change: 1 addition & 0 deletions relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ func TestRelayRejectsDuringClose(t *testing.T) {
require.Error(t, err, "Expect call to fail after relay is shutdown")
assert.Contains(t, err.Error(), "incoming connection is not active")
close(block)
wg.Wait()

// We have a successful call that ran in the goroutine
// and a failed call that we just checked the error on.
Expand Down
2 changes: 1 addition & 1 deletion retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestRetryNetConnect(t *testing.T) {
defer cancel()

closedAddr := testutils.GetClosedHostPort(t)
listenC, err := net.Listen("tcp", ":0")
listenC, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err, "Listen failed")
defer listenC.Close()

Expand Down
2 changes: 1 addition & 1 deletion testutils/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type frameRelay struct {
}

func (r *frameRelay) listen() (listenHostPort string, cancel func()) {
conn, err := net.Listen("tcp", ":0")
conn, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(r.t, err, "net.Listen failed")

go func() {
Expand Down

0 comments on commit 7b39616

Please sign in to comment.