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

Commit 34d97ec

Browse files
authored
chore: fix dial test assertions (#428)
1 parent 229cfcf commit 34d97ec

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

wsnet/dial.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ func (d *Dialer) negotiate(ctx context.Context) (err error) {
290290
return <-errCh
291291
}
292292

293-
// ActiveConnections returns the amount of active connections.
294-
// DialContext opens a connection, and close will end it.
293+
// ActiveConnections returns the amount of active connections. DialContext
294+
// opens a connection, and close will end it.
295295
func (d *Dialer) activeConnections() int {
296296
stats, ok := d.rtc.GetStats().GetConnectionStats(d.rtc)
297297
if !ok {

wsnet/dial_test.go

+18-15
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
"testing"
1212
"time"
1313

14-
"cdr.dev/slog/sloggers/slogtest"
1514
"github.com/pion/ice/v2"
1615
"github.com/pion/webrtc/v3"
1716
"github.com/stretchr/testify/assert"
1817
"github.com/stretchr/testify/require"
18+
19+
"cdr.dev/slog/sloggers/slogtest"
1920
)
2021

2122
func ExampleDial_basic() {
@@ -260,33 +261,35 @@ func TestDial(t *testing.T) {
260261
log := slogtest.Make(t, nil)
261262

262263
listener, err := net.Listen("tcp", "0.0.0.0:0")
263-
if err != nil {
264-
t.Error(err)
265-
return
266-
}
264+
require.NoError(t, err)
265+
267266
go func() {
268267
_, _ = listener.Accept()
269268
}()
269+
270270
connectAddr, listenAddr := createDumbBroker(t)
271271
_, err = Listen(context.Background(), slogtest.Make(t, nil), listenAddr, "")
272-
if err != nil {
273-
t.Error(err)
274-
return
275-
}
272+
require.NoError(t, err)
276273

277274
dialer, err := DialWebsocket(context.Background(), connectAddr, &DialOptions{
278275
Log: &log,
279276
}, nil)
280-
if err != nil {
281-
t.Error(err)
282-
}
283-
conn, _ := dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
277+
require.NoError(t, err)
278+
279+
conn, err := dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
280+
require.NoError(t, err)
284281
assert.Equal(t, 1, dialer.activeConnections())
282+
285283
_ = conn.Close()
286284
assert.Equal(t, 0, dialer.activeConnections())
287-
_, _ = dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
288-
conn, _ = dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
285+
286+
_, err = dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
287+
require.NoError(t, err)
288+
289+
conn, err = dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
290+
require.NoError(t, err)
289291
assert.Equal(t, 2, dialer.activeConnections())
292+
290293
_ = conn.Close()
291294
assert.Equal(t, 1, dialer.activeConnections())
292295
})

0 commit comments

Comments
 (0)