forked from quic-go/quic-go
Retry starting Chrome if it doesn't hit the endpoints
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||||
"github.com/lucas-clemente/quic-go/protocol"
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
@@ -16,6 +17,10 @@ import (
|
|||||||
"github.com/onsi/gomega/gexec"
|
"github.com/onsi/gomega/gexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
nChromeRetries = 8
|
||||||
|
)
|
||||||
|
|
||||||
func getChromePath() string {
|
func getChromePath() string {
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
|
return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
|
||||||
@@ -24,10 +29,20 @@ func getChromePath() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func chromeTest(version protocol.VersionNumber, url string, blockUntilDone func()) {
|
func chromeTest(version protocol.VersionNumber, url string, blockUntilDone func()) {
|
||||||
|
// Chrome sometimes starts but doesn't send any HTTP requests for no apparent reason.
|
||||||
|
// Retry starting it a couple of times.
|
||||||
|
for i := 0; i < nChromeRetries; i++ {
|
||||||
|
if chromeTestImpl(version, url, blockUntilDone) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Fail("Chrome didn't hit the testing endpoints")
|
||||||
|
}
|
||||||
|
|
||||||
|
func chromeTestImpl(version protocol.VersionNumber, url string, blockUntilDone func()) bool {
|
||||||
userDataDir, err := ioutil.TempDir("", "quic-go-test-chrome-dir")
|
userDataDir, err := ioutil.TempDir("", "quic-go-test-chrome-dir")
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
defer os.RemoveAll(userDataDir)
|
defer os.RemoveAll(userDataDir)
|
||||||
|
|
||||||
path := getChromePath()
|
path := getChromePath()
|
||||||
args := []string{
|
args := []string{
|
||||||
"--disable-gpu",
|
"--disable-gpu",
|
||||||
@@ -46,7 +61,19 @@ func chromeTest(version protocol.VersionNumber, url string, blockUntilDone func(
|
|||||||
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
|
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
defer session.Kill()
|
defer session.Kill()
|
||||||
|
const pollInterval = 100 * time.Millisecond
|
||||||
|
const pollDuration = 10 * time.Second
|
||||||
|
for i := 0; i < int(pollDuration/pollInterval); i++ {
|
||||||
|
time.Sleep(pollInterval)
|
||||||
|
if testEndpointCalled {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !testEndpointCalled {
|
||||||
|
return false
|
||||||
|
}
|
||||||
blockUntilDone()
|
blockUntilDone()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("Chrome tests", func() {
|
var _ = Describe("Chrome tests", func() {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ var (
|
|||||||
clientPath string
|
clientPath string
|
||||||
serverPath string
|
serverPath string
|
||||||
nFilesUploaded int32
|
nFilesUploaded int32
|
||||||
|
testEndpointCalled bool
|
||||||
doneCalled bool
|
doneCalled bool
|
||||||
|
|
||||||
logFileName string // the log file set in the ginkgo flags
|
logFileName string // the log file set in the ginkgo flags
|
||||||
@@ -88,6 +89,7 @@ var _ = AfterEach(func() {
|
|||||||
|
|
||||||
nFilesUploaded = 0
|
nFilesUploaded = 0
|
||||||
doneCalled = false
|
doneCalled = false
|
||||||
|
testEndpointCalled = false
|
||||||
})
|
})
|
||||||
|
|
||||||
func setupHTTPHandlers() {
|
func setupHTTPHandlers() {
|
||||||
@@ -133,6 +135,7 @@ func setupHTTPHandlers() {
|
|||||||
response = strings.Replace(response, "NUM", r.URL.Query().Get("num"), -1)
|
response = strings.Replace(response, "NUM", r.URL.Query().Get("num"), -1)
|
||||||
_, err := io.WriteString(w, response)
|
_, err := io.WriteString(w, response)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
testEndpointCalled = true
|
||||||
})
|
})
|
||||||
|
|
||||||
// Requires the len & num GET parameters, e.g. /downloadtest?len=100&num=1
|
// Requires the len & num GET parameters, e.g. /downloadtest?len=100&num=1
|
||||||
@@ -143,6 +146,7 @@ func setupHTTPHandlers() {
|
|||||||
response = strings.Replace(response, "NUM", r.URL.Query().Get("num"), -1)
|
response = strings.Replace(response, "NUM", r.URL.Query().Get("num"), -1)
|
||||||
_, err := io.WriteString(w, response)
|
_, err := io.WriteString(w, response)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
testEndpointCalled = true
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/uploadhandler", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/uploadhandler", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user