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

Commit e2456e8

Browse files
committed
Add disconnect err test
1 parent 1d7d14c commit e2456e8

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

wsnet/dial_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package wsnet
33
import (
44
"context"
55
"errors"
6-
"fmt"
6+
"io"
77
"testing"
88

99
"github.com/pion/webrtc/v3"
@@ -57,32 +57,30 @@ func TestDial(t *testing.T) {
5757
if err != nil {
5858
t.Error(err)
5959
}
60-
6160
})
6261

63-
t.Run("Pipe", func(t *testing.T) {
62+
t.Run("Disconnect", func(t *testing.T) {
6463
connectAddr, listenAddr := createDumbBroker(t)
6564
listener, err := Listen(context.Background(), listenAddr)
6665
if err != nil {
6766
t.Error(err)
6867
}
68+
go func() {
69+
c, _ := listener.Accept()
70+
c.Close()
71+
}()
6972
dialer, err := Dial(context.Background(), connectAddr, nil)
7073
if err != nil {
7174
t.Error(err)
7275
}
73-
go func() {
74-
conn, err := dialer.DialContext(context.Background(), "tcp", "localhost:40000")
75-
if err != nil {
76-
t.Error(err)
77-
}
78-
conn.Write([]byte("hello"))
79-
}()
80-
conn, err := listener.Accept()
76+
conn, err := dialer.DialContext(context.Background(), "tcp", "example")
8177
if err != nil {
8278
t.Error(err)
8379
}
84-
b := make([]byte, 5)
85-
_, _ = conn.Read(b)
86-
fmt.Printf("WE LEGIT GOT IT! %s\n", b)
80+
b := make([]byte, 16)
81+
_, err = conn.Read(b)
82+
if err != io.EOF {
83+
t.Error(err)
84+
}
8785
})
8886
}

0 commit comments

Comments
 (0)