Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#117 - fix data races #119

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 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
42 changes: 0 additions & 42 deletions .travis.entrypoint.sh

This file was deleted.

44 changes: 38 additions & 6 deletions .travis.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
#!/bin/sh
set -e
docker pull golang:1.10-alpine
docker run \
--rm \
-v $(pwd):/go/src/github.com/mkenney/go-chrome \
--entrypoint="/go/src/github.com/mkenney/go-chrome/.travis.entrypoint.sh" \
golang:1.10-alpine

exit_code=0

go get -v github.com/golang/lint/golint
[ "0" = "$?" ] || exit 1

go get -u github.com/golang/dep/cmd/dep
[ "0" = "$?" ] || exit 2

dep ensure
[ "0" = "$?" ] || exit 3

for dir in $(go list ./... | grep -v vendor); do
echo "golint $dir"
result=$(golint $dir)
if [ "" != "$result" ]; then
echo $result
exit_code=5
fi
if [ "0" != "$exit_code" ]; then
exit $exit_code
fi
done

rm -f coverage.txt
for dir in $(go list ./... | grep -v vendor); do
GOCACHE=off go test -race -timeout 300s -coverprofile=profile.out $dir
exit_code=$?
if [ "0" != "$exit_code" ]; then
exit $exit_code
fi
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done

exit $exit_code
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ branches:
only:
- master

services:
- docker

language: go
go_import_path: github.com/mkenney/go-chrome
go:
- 1.9.x
- 1.10.x
- 1.11.x
- tip


Expand Down
17 changes: 10 additions & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.5'
services:
chrome:
container_name: chrome
hostname: chrome
image: mkenney/chromium-headless:latest
ports:
- 9222:9222
entrypoint: sh
command:
- "-cexu"
- "/usr/bin/google-chrome --addr=localhost --port=9222 --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 --disable-extensions --disable-gpu --headless --hide-scrollbars --no-first-run --no-sandbox"
2 changes: 1 addition & 1 deletion tot/chrome.chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (chrome *Chrome) Query(
log.WithFields(log.Fields{
"path": path,
"status": resp.Status,
}).Debug("querying chrome:/%s %s", path, resp.Status)
}).Debug("querying chrome")
if 200 != resp.StatusCode {
return nil, errs.New(0, resp.Status)
}
Expand Down
2 changes: 1 addition & 1 deletion tot/mock.chromium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (chrome *MockChrome) Query(
if len(params) > 0 {
path += fmt.Sprintf("?%s", params.Encode())
}
log.Debugf("chrome:/%s %s", path)
log.Debugf("chrome:/%s", path)
return msg, nil
}

Expand Down
47 changes: 14 additions & 33 deletions tot/socket/cdtp.accessibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,27 @@ package socket

import (
"encoding/json"
"net/url"
"testing"

"github.com/mkenney/go-chrome/tot/accessibility"
"github.com/mkenney/go-chrome/tot/dom"
)

func TestAccessibilityGetPartialAXTree(t *testing.T) {
socketURL, _ := url.Parse("https://test:9222/TestAccessibilityGetPartialAXTree")
mockSocket := NewMock(socketURL)
mockSocket.Listen()
defer mockSocket.Stop()
chrome := NewMockChrome()
chrome.ListenAndServe()
defer func() { chrome.Close() }()
soc := New(chrome.URL)
defer func() { soc.Stop() }()
mkenney marked this conversation as resolved.
Show resolved Hide resolved

params := &accessibility.PartialAXTreeParams{
NodeID: dom.NodeID(1),
FetchRelatives: true,
}
resultChan := mockSocket.Accessibility().GetPartialAXTree(params)
mockResult := accessibility.PartialAXTreeResult{}
mockResultBytes, _ := json.Marshal(mockResult)
mockSocket.Conn().(*MockChromeWebSocket).AddMockData(&Response{
ID: mockSocket.CurCommandID(),
Error: &Error{},
Result: mockResultBytes,
})
result := <-resultChan
mockResult := &accessibility.PartialAXTreeResult{}

chrome.AddData(MockData{0, &Error{}, mockResult, ""})
result := <-soc.Accessibility().GetPartialAXTree(params)
if nil != result.Err {
t.Errorf("Expected success, got error: %s", result.Err)
}
Expand All @@ -36,8 +31,7 @@ func TestAccessibilityGetPartialAXTree(t *testing.T) {
t.Errorf("Expected empty set, got '%s'", tmp)
}

resultChan = mockSocket.Accessibility().GetPartialAXTree(params)
mockResult = accessibility.PartialAXTreeResult{
mockResult = &accessibility.PartialAXTreeResult{
Nodes: []*accessibility.AXNode{{
NodeID: accessibility.AXNodeID("NodeID"),
Ignored: false,
Expand Down Expand Up @@ -73,13 +67,8 @@ func TestAccessibilityGetPartialAXTree(t *testing.T) {
BackendDOMNodeID: dom.BackendNodeID(1),
}},
}
mockResultBytes, _ = json.Marshal(mockResult)
mockSocket.Conn().(*MockChromeWebSocket).AddMockData(&Response{
ID: mockSocket.CurCommandID(),
Error: &Error{},
Result: mockResultBytes,
})
result = <-resultChan
chrome.AddData(MockData{0, &Error{}, mockResult, ""})
result = <-soc.Accessibility().GetPartialAXTree(params)
if nil != result.Err {
t.Errorf("Expected success, got error: %s", result.Err)
}
Expand All @@ -88,16 +77,8 @@ func TestAccessibilityGetPartialAXTree(t *testing.T) {
t.Errorf("Expected dataset, got '%s'", tmp)
}

resultChan = mockSocket.Accessibility().GetPartialAXTree(params)
mockSocket.Conn().(*MockChromeWebSocket).AddMockData(&Response{
ID: mockSocket.CurCommandID(),
Error: &Error{
Code: 1,
Data: []byte(`"error data"`),
Message: "error message",
},
})
result = <-resultChan
chrome.AddData(MockData{0, genericError, nil, ""})
result = <-soc.Accessibility().GetPartialAXTree(params)
if nil == result.Err {
t.Errorf("Expected error, got success")
}
Expand Down
Loading