Skip to content

Commit

Permalink
Fix flaky test TestInboundConnection
Browse files Browse the repository at this point in the history
TestInboundConnection verifies that the InboundConnection returns the
right connection. However when the test was run with a relay, there was
a race that could cause the test to fail.

We have a server channel and a relay, and the test called the server
through the relay, so we had:
server --C1--> relay --C?--> server

The relay had a race between whether it would use the incoming
connection from the server to send the call back, or creating a new
connection. When the connection was reused, the test passed since the
relay responds with the host:port on inbound connections. However when
the relay creates a new connection, it hides the host:port on outbound
connections, and so the server would see an ephemeral host:port and this
would cause the test to fail:
https://travis-ci.org/uber/tchannel-go/jobs/204481657

Updated the test to use a separate channel for making calls instead of
a single channel calling itself. Also disable relays to avoid races.
  • Loading branch information
prashantv committed Feb 23, 2017
1 parent 9471327 commit e501935
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions inbound_test.go
Expand Up @@ -90,14 +90,18 @@ func TestInboundConnection(t *testing.T) {
ctx, cancel := NewContext(time.Second)
defer cancel()

WithVerifiedServer(t, nil, func(ch *Channel, hostPort string) {
testutils.RegisterFunc(ch, "test", func(ctx context.Context, args *raw.Args) (*raw.Res, error) {
// Disable relay since relays hide host:port on outbound calls.
opts := testutils.NewOpts().NoRelay()
testutils.WithTestServer(t, opts, func(ts *testutils.TestServer) {
s2 := ts.NewServer(nil)

ts.RegisterFunc("test", func(ctx context.Context, args *raw.Args) (*raw.Res, error) {
c, _ := InboundConnection(CurrentCall(ctx))
assert.Equal(t, hostPort, c.RemotePeerInfo().HostPort, "Unexpected host port")
assert.Equal(t, s2.PeerInfo().HostPort, c.RemotePeerInfo().HostPort, "Unexpected host port")
return &raw.Res{}, nil
})

_, _, _, err := raw.Call(ctx, ch, hostPort, ch.PeerInfo().ServiceName, "test", nil, nil)
_, _, _, err := raw.Call(ctx, s2, ts.HostPort(), ts.ServiceName(), "test", nil, nil)
require.NoError(t, err, "Call failed")
})
}
Expand Down

0 comments on commit e501935

Please sign in to comment.