mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #574 from unihorn/6
Fix the bug that TestSimpleMultiNodeTls may error sometimes
This commit is contained in:
commit
7599a285c3
@ -26,7 +26,7 @@ func templateTestSimpleMultiNode(t *testing.T, tls bool) {
|
||||
_, etcds, err := CreateCluster(clusterSize, procAttr, tls)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("cannot create cluster")
|
||||
t.Fatalf("cannot create cluster: %v", err)
|
||||
}
|
||||
|
||||
defer DestroyCluster(etcds)
|
||||
@ -35,29 +35,30 @@ func templateTestSimpleMultiNode(t *testing.T, tls bool) {
|
||||
|
||||
c := etcd.NewClient(nil)
|
||||
|
||||
c.SyncCluster()
|
||||
if c.SyncCluster() == false {
|
||||
t.Fatal("Cannot sync cluster!")
|
||||
}
|
||||
|
||||
// Test Set
|
||||
result, err := c.Set("foo", "bar", 100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
node := result.Node
|
||||
|
||||
if err != nil || node.Key != "/foo" || node.Value != "bar" || node.TTL < 95 {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if node.Key != "/foo" || node.Value != "bar" || node.TTL < 95 {
|
||||
t.Fatalf("Set 1 failed with %s %s %v", node.Key, node.Value, node.TTL)
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
result, err = c.Set("foo", "bar", 100)
|
||||
node = result.Node
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err != nil || node.Key != "/foo" || node.Value != "bar" || node.TTL < 95 {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
node = result.Node
|
||||
if node.Key != "/foo" || node.Value != "bar" || node.TTL < 95 {
|
||||
t.Fatalf("Set 2 failed with %s %s %v", node.Key, node.Value, node.TTL)
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
|
||||
"io/ioutil"
|
||||
@ -69,6 +70,23 @@ func Set(stop chan bool) {
|
||||
stop <- true
|
||||
}
|
||||
|
||||
func WaitForServer(host string, client http.Client, scheme string) error {
|
||||
path := fmt.Sprintf("%s://%s/v2/keys/", scheme, host)
|
||||
|
||||
var resp *http.Response
|
||||
var err error
|
||||
for i := 0; i < 10; i++ {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
resp, err = client.Get(path)
|
||||
if err == nil && resp.StatusCode == 200 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return errors.New(fmt.Sprintf("etcd server was not reachable in a long time, last-time response and error: %v; %v", resp, err))
|
||||
}
|
||||
|
||||
// Create a cluster of etcd nodes
|
||||
func CreateCluster(size int, procAttr *os.ProcAttr, ssl bool) ([][]string, []*os.Process, error) {
|
||||
argGroup := make([][]string, size)
|
||||
@ -107,12 +125,15 @@ func CreateCluster(size int, procAttr *os.ProcAttr, ssl bool) ([][]string, []*os
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// TODOBP: Change this sleep to wait until the master is up.
|
||||
// The problem is that if the master isn't up then the children
|
||||
// have to retry. This retry can take upwards of 15 seconds
|
||||
// which slows tests way down and some of them fail.
|
||||
if i == 0 {
|
||||
time.Sleep(time.Second * 2)
|
||||
client := buildClient()
|
||||
err = WaitServerUp("127.0.0.1:4001", client, "http")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user