Skip to content

Commit

Permalink
panic on duplicated connection
Browse files Browse the repository at this point in the history
resolve #360
  • Loading branch information
ysmood committed Feb 28, 2021
1 parent 3ff3f0b commit deea7a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/cdp/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type WebSocket struct {

// Connect to browser
func (ws *WebSocket) Connect(ctx context.Context, wsURL string, header http.Header) error {
if ws.conn != nil {
panic("duplicated connection: " + wsURL)
}

ctx, cancel := context.WithCancel(ctx)
ws.close = cancel

Expand Down
14 changes: 14 additions & 0 deletions lib/cdp/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,17 @@ func (t T) newPage(ctx context.Context) (*cdp.Client, string) {

return client, sessionID
}

func (t T) DuplicatedConnectErr() {
l := launcher.New()
t.Cleanup(l.Kill)

u := l.MustLaunch()

ws := &cdp.WebSocket{}
t.E(ws.Connect(t.Context(), u, nil))

t.Panic(func() {
_ = ws.Connect(t.Context(), u, nil)
})
}

0 comments on commit deea7a7

Please sign in to comment.