diff --git a/integrationtests/chrome_test.go b/integrationtests/chrome_test.go index e1ac87021..c24493841 100644 --- a/integrationtests/chrome_test.go +++ b/integrationtests/chrome_test.go @@ -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() { diff --git a/integrationtests/integrationtests_suite_test.go b/integrationtests/integrationtests_suite_test.go index 705be2ee0..726b5c7bc 100644 --- a/integrationtests/integrationtests_suite_test.go +++ b/integrationtests/integrationtests_suite_test.go @@ -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) {