Skip to content

Commit

Permalink
fix websocket workaround error assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Apr 11, 2023
1 parent 6719610 commit 7bb03ef
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions p2p/test/transport/gating_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ func TestInterceptSecuredOutgoing(t *testing.T) {
require.Equal(t, stripCertHash(h2.Addrs()[0]).String(), addrs.RemoteMultiaddr().String())
}),
)
require.Error(t, h1.Connect(ctx, peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}))
cerr := h1.Connect(ctx, peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
require.Error(t, cerr)
// There's a bug in the WebSocket library, making Close block for up to 5s.
// See https://github.com/nhooyr/websocket/issues/355 for details.
if _, err := h2.Addrs()[0].ValueForProtocol(ma.P_WS); err == nil {
require.NotErrorIs(t, err, context.DeadlineExceeded)
require.NotErrorIs(t, cerr, context.DeadlineExceeded)
}
})
}
Expand Down Expand Up @@ -126,11 +127,12 @@ func TestInterceptUpgradedOutgoing(t *testing.T) {
require.Equal(t, h1.ID(), c.LocalPeer())
require.Equal(t, h2.ID(), c.RemotePeer())
}))
require.Error(t, h1.Connect(ctx, peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}))
cerr := h1.Connect(ctx, peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
require.Error(t, cerr)
// There's a bug in the WebSocket library, making Close block for up to 5s.
// See https://github.com/nhooyr/websocket/issues/355 for details.
if _, err := h2.Addrs()[0].ValueForProtocol(ma.P_WS); err == nil {
require.NotErrorIs(t, err, context.DeadlineExceeded)
require.NotErrorIs(t, cerr, context.DeadlineExceeded)
}
})
}
Expand All @@ -155,12 +157,12 @@ func TestInterceptAccept(t *testing.T) {
require.Equal(t, stripCertHash(h2.Addrs()[0]), addrs.LocalMultiaddr())
})
h1.Peerstore().AddAddrs(h2.ID(), h2.Addrs(), time.Hour)
_, err := h1.NewStream(ctx, h2.ID(), protocol.TestingID)
require.Error(t, err)
_, cerr := h1.NewStream(ctx, h2.ID(), protocol.TestingID)
require.Error(t, cerr)
// There's a bug in the WebSocket library, making Close block for up to 5s.
// See https://github.com/nhooyr/websocket/issues/355 for details.
if _, err := h2.Addrs()[0].ValueForProtocol(ma.P_WS); err == nil {
require.NotErrorIs(t, err, context.DeadlineExceeded)
require.NotErrorIs(t, cerr, context.DeadlineExceeded)
}
})
}
Expand All @@ -187,12 +189,12 @@ func TestInterceptSecuredIncoming(t *testing.T) {
}),
)
h1.Peerstore().AddAddrs(h2.ID(), h2.Addrs(), time.Hour)
_, err := h1.NewStream(ctx, h2.ID(), protocol.TestingID)
require.Error(t, err)
_, cerr := h1.NewStream(ctx, h2.ID(), protocol.TestingID)
require.Error(t, cerr)
// There's a bug in the WebSocket library, making Close block for up to 5s.
// See https://github.com/nhooyr/websocket/issues/355 for details.
if _, err := h2.Addrs()[0].ValueForProtocol(ma.P_WS); err == nil {
require.NotErrorIs(t, err, context.DeadlineExceeded)
require.NotErrorIs(t, cerr, context.DeadlineExceeded)
}
})
}
Expand Down Expand Up @@ -222,12 +224,12 @@ func TestInterceptUpgradedIncoming(t *testing.T) {
}),
)
h1.Peerstore().AddAddrs(h2.ID(), h2.Addrs(), time.Hour)
_, err := h1.NewStream(ctx, h2.ID(), protocol.TestingID)
require.Error(t, err)
_, cerr := h1.NewStream(ctx, h2.ID(), protocol.TestingID)
require.Error(t, cerr)
// There's a bug in the WebSocket library, making Close block for up to 5s.
// See https://github.com/nhooyr/websocket/issues/355 for details.
if _, err := h2.Addrs()[0].ValueForProtocol(ma.P_WS); err == nil {
require.NotErrorIs(t, err, context.DeadlineExceeded)
require.NotErrorIs(t, cerr, context.DeadlineExceeded)
}
})
}
Expand Down

0 comments on commit 7bb03ef

Please sign in to comment.