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

Commit 426b18c

Browse files
authored
Fix dial tests (#439)
1 parent a778c5f commit 426b18c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

wsnet/dial.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er
178178

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

184186
return dialer, nil

wsnet/dial_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@ func TestDial(t *testing.T) {
6262
defer cancelFunc()
6363
dialer, err := DialWebsocket(ctx, connectAddr, nil, nil)
6464
require.True(t, errors.Is(err, context.DeadlineExceeded))
65+
require.NotNil(t, dialer)
6566
require.Error(t, dialer.conn.Close(), "already wrote close")
67+
68+
// Ensure the rtc peer connection is closed. Setting the config options
69+
// to empty struct does nothing, but it does fail if the rtc peer conn
70+
// is closed.
71+
err = dialer.rtc.SetConfiguration(webrtc.Configuration{})
72+
require.Error(t, err)
73+
require.ErrorIs(t, err, webrtc.ErrConnectionClosed)
6674
})
6775

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

0 commit comments

Comments
 (0)