diff --git a/etcd/etcd_functional_test.go b/etcd/etcd_functional_test.go index f6b6e5d34..634af9f58 100644 --- a/etcd/etcd_functional_test.go +++ b/etcd/etcd_functional_test.go @@ -20,6 +20,7 @@ import ( "fmt" "math/rand" "net/http/httptest" + "net/url" "reflect" "testing" "time" @@ -339,37 +340,22 @@ func TestModeSwitch(t *testing.T) { // Sending set commands func keepSetting(urlStr string, stop chan bool) { - stopSet := false + tc := NewTestClient() i := 0 - c := etcd.NewClient([]string{urlStr}) + value := url.Values(map[string][]string{"value": {"bar"}}) for { - key := fmt.Sprintf("%s_%v", "foo", i) - - result, err := c.Set(key, "bar", 0) - - if err != nil || result.Node.Key != "/"+key || result.Node.Value != "bar" { - select { - case <-stop: - stopSet = true - - default: - } + resp, err := tc.PutForm(fmt.Sprintf("%s/v2/keys/foo_%v", urlStr, i), value) + if err == nil { + tc.ReadBody(resp) } - select { case <-stop: - stopSet = true - + stop <- true + return default: } - - if stopSet { - break - } - i++ } - stop <- true } type leadterm struct { diff --git a/etcd/v2_http_kv_test.go b/etcd/v2_http_kv_test.go index 1c27a91aa..a33740bb1 100644 --- a/etcd/v2_http_kv_test.go +++ b/etcd/v2_http_kv_test.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "io/ioutil" + "net" "net/http" "net/url" "reflect" @@ -981,7 +982,11 @@ type testHttpClient struct { // Creates a new HTTP client with KeepAlive disabled. func NewTestClient() *testHttpClient { - return &testHttpClient{&http.Client{Transport: &http.Transport{DisableKeepAlives: true}}} + tr := &http.Transport{ + Dial: (&net.Dialer{Timeout: time.Second}).Dial, + DisableKeepAlives: true, + } + return &testHttpClient{&http.Client{Transport: tr}} } // Reads the body from the response and closes it.