Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Fix dial tests #439

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion wsnet/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er

err = dialer.negotiate(ctx)
if err != nil {
return nil, xerrors.Errorf("negotiate rtc connection: %w", err)
// Return the dialer since we have tests that verify things are closed
// if negotiation fails.
return dialer, xerrors.Errorf("negotiate rtc connection: %w", err)
}

return dialer, nil
Expand Down
8 changes: 8 additions & 0 deletions wsnet/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ func TestDial(t *testing.T) {
defer cancelFunc()
dialer, err := DialWebsocket(ctx, connectAddr, nil, nil)
require.True(t, errors.Is(err, context.DeadlineExceeded))
require.NotNil(t, dialer)
require.Error(t, dialer.conn.Close(), "already wrote close")

// Ensure the rtc peer connection is closed. Setting the config options
// to empty struct does nothing, but it does fail if the rtc peer conn
// is closed.
err = dialer.rtc.SetConfiguration(webrtc.Configuration{})
require.Error(t, err)
require.ErrorIs(t, err, webrtc.ErrConnectionClosed)
})

t.Run("Ping", func(t *testing.T) {
Expand Down