forked from quic-go/quic-go
use atomics in the Chrome test HTTP handlers
This fixes a race condition in these tests.
This commit is contained in:
@@ -35,9 +35,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nFilesUploaded int32
|
nFilesUploaded int32 // should be used atomically
|
||||||
testEndpointCalled bool
|
testEndpointCalled utils.AtomicBool
|
||||||
doneCalled bool
|
doneCalled utils.AtomicBool
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChrome(t *testing.T) {
|
func TestChrome(t *testing.T) {
|
||||||
@@ -54,7 +54,7 @@ func init() {
|
|||||||
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
|
testEndpointCalled.Set(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
|
||||||
@@ -65,7 +65,7 @@ func init() {
|
|||||||
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
|
testEndpointCalled.Set(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/uploadhandler", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/uploadhandler", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -84,7 +84,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/done", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/done", func(w http.ResponseWriter, r *http.Request) {
|
||||||
doneCalled = true
|
doneCalled.Set(true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,9 +93,9 @@ var _ = JustBeforeEach(testserver.StartQuicServer)
|
|||||||
var _ = AfterEach(func() {
|
var _ = AfterEach(func() {
|
||||||
testserver.StopQuicServer()
|
testserver.StopQuicServer()
|
||||||
|
|
||||||
nFilesUploaded = 0
|
atomic.StoreInt32(&nFilesUploaded, 0)
|
||||||
doneCalled = false
|
doneCalled.Set(false)
|
||||||
testEndpointCalled = false
|
testEndpointCalled.Set(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
func getChromePath() string {
|
func getChromePath() string {
|
||||||
@@ -149,11 +149,11 @@ func chromeTestImpl(version protocol.VersionNumber, url string, blockUntilDone f
|
|||||||
const pollDuration = 10 * time.Second
|
const pollDuration = 10 * time.Second
|
||||||
for i := 0; i < int(pollDuration/pollInterval); i++ {
|
for i := 0; i < int(pollDuration/pollInterval); i++ {
|
||||||
time.Sleep(pollInterval)
|
time.Sleep(pollInterval)
|
||||||
if testEndpointCalled {
|
if testEndpointCalled.Get() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !testEndpointCalled {
|
if !testEndpointCalled.Get() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
blockUntilDone()
|
blockUntilDone()
|
||||||
@@ -161,7 +161,7 @@ func chromeTestImpl(version protocol.VersionNumber, url string, blockUntilDone f
|
|||||||
}
|
}
|
||||||
|
|
||||||
func waitForDone() {
|
func waitForDone() {
|
||||||
Eventually(func() bool { return doneCalled }, 60).Should(BeTrue())
|
Eventually(func() bool { return doneCalled.Get() }, 60).Should(BeTrue())
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForNUploaded(expected int) func() {
|
func waitForNUploaded(expected int) func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user