Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

chore: fix dial test assertions#428

Merged
coadler merged 1 commit intomainfromcolin/fix-dial-tests
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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: 2 additions & 2 deletionswsnet/dial.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -290,8 +290,8 @@ func (d *Dialer) negotiate(ctx context.Context) (err error) {
return <-errCh
}

// ActiveConnections returns the amount of active connections.
//DialContextopens a connection, and close will end it.
// ActiveConnections returns the amount of active connections. DialContext
// opens a connection, and close will end it.
func (d *Dialer) activeConnections() int {
stats, ok := d.rtc.GetStats().GetConnectionStats(d.rtc)
if !ok {
Expand Down
33 changes: 18 additions & 15 deletionswsnet/dial_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,11 +11,12 @@ import (
"testing"
"time"

"cdr.dev/slog/sloggers/slogtest"
"github.com/pion/ice/v2"
"github.com/pion/webrtc/v3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"cdr.dev/slog/sloggers/slogtest"
)

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

listener, err := net.Listen("tcp", "0.0.0.0:0")
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)

go func() {
_, _ = listener.Accept()
}()

connectAddr, listenAddr := createDumbBroker(t)
_, err = Listen(context.Background(), slogtest.Make(t, nil), listenAddr, "")
if err != nil {
t.Error(err)
return
}
require.NoError(t, err)

dialer, err := DialWebsocket(context.Background(), connectAddr, &DialOptions{
Log: &log,
}, nil)
if err != nil {
t.Error(err)
}
conn, _ := dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
require.NoError(t, err)

conn, err := dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
require.NoError(t, err)
assert.Equal(t, 1, dialer.activeConnections())

_ = conn.Close()
assert.Equal(t, 0, dialer.activeConnections())
_, _ = dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
conn, _ = dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())

_, err = dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
require.NoError(t, err)

conn, err = dialer.DialContext(context.Background(), listener.Addr().Network(), listener.Addr().String())
require.NoError(t, err)
assert.Equal(t, 2, dialer.activeConnections())

_ = conn.Close()
assert.Equal(t, 1, dialer.activeConnections())
})
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp