Skip to content

Commit

Permalink
Optimize forgotten tests to parallel
Browse files Browse the repository at this point in the history
Co-authored-by: ka3de <danijs12@hotmail.com>
  • Loading branch information
inancgumus and ka3de committed Aug 31, 2023
1 parent cdccc4d commit 9cd296e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
16 changes: 16 additions & 0 deletions common/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ import (
)

func TestConnection(t *testing.T) {
t.Parallel()

server := ws.NewServer(t, ws.WithEchoHandler("/echo"))

t.Run("connect", func(t *testing.T) {
t.Parallel()

ctx := context.Background()
url, _ := url.Parse(server.ServerHTTP.URL)
wsURL := fmt.Sprintf("ws://%s/echo", url.Host)
Expand All @@ -33,9 +37,13 @@ func TestConnection(t *testing.T) {
}

func TestConnectionClosureAbnormal(t *testing.T) {
t.Parallel()

server := ws.NewServer(t, ws.WithClosureAbnormalHandler("/closure-abnormal"))

t.Run("closure abnormal", func(t *testing.T) {
t.Parallel()

ctx := context.Background()
url, _ := url.Parse(server.ServerHTTP.URL)
wsURL := fmt.Sprintf("ws://%s/closure-abnormal", url.Host)
Expand All @@ -50,9 +58,13 @@ func TestConnectionClosureAbnormal(t *testing.T) {
}

func TestConnectionSendRecv(t *testing.T) {
t.Parallel()

server := ws.NewServer(t, ws.WithCDPHandler("/cdp", ws.CDPDefaultHandler, nil))

t.Run("send command with empty reply", func(t *testing.T) {
t.Parallel()

ctx := context.Background()
url, _ := url.Parse(server.ServerHTTP.URL)
wsURL := fmt.Sprintf("ws://%s/cdp", url.Host)
Expand All @@ -67,6 +79,8 @@ func TestConnectionSendRecv(t *testing.T) {
}

func TestConnectionCreateSession(t *testing.T) {
t.Parallel()

cmdsReceived := make([]cdproto.MethodType, 0)
handler := func(conn *websocket.Conn, msg *cdproto.Message, writeCh chan cdproto.Message, done chan struct{}) {
if msg.SessionID == "" && msg.Method != "" {
Expand Down Expand Up @@ -116,6 +130,8 @@ func TestConnectionCreateSession(t *testing.T) {
server := ws.NewServer(t, ws.WithCDPHandler("/cdp", handler, &cmdsReceived))

t.Run("create session for target", func(t *testing.T) {
t.Parallel()

ctx := context.Background()
url, _ := url.Parse(server.ServerHTTP.URL)
wsURL := fmt.Sprintf("ws://%s/cdp", url.Host)
Expand Down
2 changes: 2 additions & 0 deletions common/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestContextWithDoneChan(t *testing.T) {
t.Parallel()

done := make(chan struct{})
ctx := contextWithDoneChan(context.Background(), done)
close(done)
Expand Down
2 changes: 2 additions & 0 deletions common/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
// tests. Since we don't yet have any of them, it makes sense to keep
// this test.
func TestPageLocator(t *testing.T) {
t.Parallel()

const (
wantMainFrameID = "1"
wantSelector = "span"
Expand Down
9 changes: 7 additions & 2 deletions tests/element_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ func TestElementHandleIsChecked(t *testing.T) {
}

func TestElementHandleQueryAll(t *testing.T) {
// tests are faster than parallel execution.
// do not make this test parallel.
t.Parallel()

const (
wantLiLen = 2
Expand All @@ -316,6 +315,8 @@ func TestElementHandleQueryAll(t *testing.T) {
`, nil)

t.Run("element_handle", func(t *testing.T) {
t.Parallel()

el, err := p.Query("#aul")
require.NoError(t, err)

Expand All @@ -325,12 +326,16 @@ func TestElementHandleQueryAll(t *testing.T) {
assert.Equal(t, wantLiLen, len(els))
})
t.Run("page", func(t *testing.T) {
t.Parallel()

els, err := p.QueryAll(query)
require.NoError(t, err)

assert.Equal(t, wantLiLen, len(els))
})
t.Run("frame", func(t *testing.T) {
t.Parallel()

els, err := p.MainFrame().QueryAll(query)
require.NoError(t, err)
assert.Equal(t, wantLiLen, len(els))
Expand Down
2 changes: 2 additions & 0 deletions tests/locator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ func TestLocatorElementState(t *testing.T) {
}

func TestLocatorPress(t *testing.T) {
t.Parallel()

tb := newTestBrowser(t)

p := tb.NewPage(nil)
Expand Down

0 comments on commit 9cd296e

Please sign in to comment.