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"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
@@ -16,6 +17,10 @@ import (
|
||||
"github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
const (
|
||||
nChromeRetries = 8
|
||||
)
|
||||
|
||||
func getChromePath() string {
|
||||
if runtime.GOOS == "darwin" {
|
||||
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()) {
|
||||
// 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")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
defer os.RemoveAll(userDataDir)
|
||||
|
||||
path := getChromePath()
|
||||
args := []string{
|
||||
"--disable-gpu",
|
||||
@@ -46,7 +61,19 @@ func chromeTest(version protocol.VersionNumber, url string, blockUntilDone func(
|
||||
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
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()
|
||||
return true
|
||||
}
|
||||
|
||||
var _ = Describe("Chrome tests", func() {
|
||||
|
||||
@@ -33,13 +33,14 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
server *h2quic.Server
|
||||
dataMan dataManager
|
||||
port string
|
||||
clientPath string
|
||||
serverPath string
|
||||
nFilesUploaded int32
|
||||
doneCalled bool
|
||||
server *h2quic.Server
|
||||
dataMan dataManager
|
||||
port string
|
||||
clientPath string
|
||||
serverPath string
|
||||
nFilesUploaded int32
|
||||
testEndpointCalled bool
|
||||
doneCalled bool
|
||||
|
||||
logFileName string // the log file set in the ginkgo flags
|
||||
logFile *os.File
|
||||
@@ -88,6 +89,7 @@ var _ = AfterEach(func() {
|
||||
|
||||
nFilesUploaded = 0
|
||||
doneCalled = false
|
||||
testEndpointCalled = false
|
||||
})
|
||||
|
||||
func setupHTTPHandlers() {
|
||||
@@ -133,6 +135,7 @@ func setupHTTPHandlers() {
|
||||
response = strings.Replace(response, "NUM", r.URL.Query().Get("num"), -1)
|
||||
_, err := io.WriteString(w, response)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
testEndpointCalled = true
|
||||
})
|
||||
|
||||
// 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)
|
||||
_, err := io.WriteString(w, response)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
testEndpointCalled = true
|
||||
})
|
||||
|
||||
http.HandleFunc("/uploadhandler", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user