Merge pull request #1862 from weaveworks/1651-pause-differently
Fix race condition in ipam TestHTTPCancel
This commit is contained in:
commit
c0cd9dffc2
1 file changed
+10
-14
+10
-14
@@ -149,29 +149,25 @@ func TestHTTPCancel(t *testing.T) {
|
|||||||
testCIDR1 = "10.0.3.0/29"
|
testCIDR1 = "10.0.3.0/29"
|
||||||
)
|
)
|
||||||
|
|
||||||
alloc, _ := makeAllocatorWithMockGossip(t, "08:00:27:01:c3:9a", testCIDR1, 1)
|
// Say quorum=2, so the allocate won't go ahead
|
||||||
|
alloc, _ := makeAllocatorWithMockGossip(t, "08:00:27:01:c3:9a", testCIDR1, 2)
|
||||||
defer alloc.Stop()
|
defer alloc.Stop()
|
||||||
alloc.claimRingForTesting()
|
ExpectBroadcastMessage(alloc, nil) // trying to form consensus
|
||||||
_, cidr, _ := address.ParseCIDR(testCIDR1)
|
_, cidr, _ := address.ParseCIDR(testCIDR1)
|
||||||
port := listenHTTP(alloc, cidr)
|
port := listenHTTP(alloc, cidr)
|
||||||
|
|
||||||
// Stop the alloc so nothing actually works
|
|
||||||
unpause := alloc.pause()
|
|
||||||
|
|
||||||
// Ask the http server for a new address
|
// Ask the http server for a new address
|
||||||
done := make(chan *http.Response)
|
|
||||||
req, _ := http.NewRequest("POST", allocURL(port, testCIDR1, containerID), nil)
|
req, _ := http.NewRequest("POST", allocURL(port, testCIDR1, containerID), nil)
|
||||||
|
// On another goroutine, wait for a bit then cancel the request
|
||||||
go func() {
|
go func() {
|
||||||
res, _ := http.DefaultClient.Do(req)
|
time.Sleep(100 * time.Millisecond)
|
||||||
done <- res
|
common.Log.Debug("Cancelling allocate")
|
||||||
|
http.DefaultTransport.(*http.Transport).CancelRequest(req)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
res, _ := http.DefaultClient.Do(req)
|
||||||
fmt.Println("Cancelling allocate")
|
|
||||||
http.DefaultTransport.(*http.Transport).CancelRequest(req)
|
|
||||||
unpause()
|
|
||||||
res := <-done
|
|
||||||
if res != nil {
|
if res != nil {
|
||||||
require.FailNow(t, "Error: Allocate returned non-nil")
|
body, _ := ioutil.ReadAll(res.Body)
|
||||||
|
require.FailNow(t, "Error: Allocate returned non-nil", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user