diff --git a/go/master/service_test.go b/go/master/service_test.go index 87ce9c90439e9c1794e806e706cb68dc11e2ab3f..2d00c22d6feb7177da5c19c557fd16d7925ef6d1 100644 --- a/go/master/service_test.go +++ b/go/master/service_test.go @@ -2,7 +2,9 @@ package master_test import ( "io/ioutil" + "net/url" "os" + "strings" "testing" "time" @@ -19,6 +21,10 @@ func TestNewServiceWithEtcd(t *testing.T) { t.Fatal(err) } cfg := embed.NewConfig() + lpurl, _ := url.Parse("http://localhost:0") + lcurl, _ := url.Parse("http://localhost:0") + cfg.LPUrls = []url.URL{*lpurl} + cfg.LCUrls = []url.URL{*lcurl} cfg.Dir = etcdDir e, err := embed.StartEtcd(cfg) if err != nil { @@ -30,15 +36,13 @@ func TestNewServiceWithEtcd(t *testing.T) { t.Fatal(err) } }() - select { - case <-e.Server.ReadyNotify(): - t.Log("Server is ready!") - case <-time.After(60 * time.Second): - e.Server.Stop() // trigger a shutdown - t.Fatal("Server took too long to start!") - } - ep := []string{"127.0.0.1:2379"} + <-e.Server.ReadyNotify() + + port := strings.Split(e.Clients[0].Addr().String(), ":")[1] + endpoint := "127.0.0.1:" + port + + ep := []string{endpoint} masterAddr := "127.0.0.1:3306" store, err := master.NewEtcdClient(ep, masterAddr, master.DefaultLockPath, master.DefaultAddrPath, master.DefaultStatePath, 30) if err != nil { diff --git a/go/pserver/client/etcd_client_test.go b/go/pserver/client/etcd_client_test.go index 9daeb97d4ce9daaec8826d77a9fa4f6d4a9c79a0..08742433e7a266fbd39e34f4b92ac4cc4caeb0fb 100644 --- a/go/pserver/client/etcd_client_test.go +++ b/go/pserver/client/etcd_client_test.go @@ -2,7 +2,9 @@ package client_test import ( "io/ioutil" + "net/url" "os" + "strings" "sync" "testing" @@ -16,6 +18,10 @@ func TestSelector(t *testing.T) { t.Fatal(err) } cfg := embed.NewConfig() + lpurl, _ := url.Parse("http://localhost:0") + lcurl, _ := url.Parse("http://localhost:0") + cfg.LPUrls = []url.URL{*lpurl} + cfg.LCUrls = []url.URL{*lcurl} cfg.Dir = etcdDir e, err := embed.StartEtcd(cfg) if err != nil { @@ -31,6 +37,9 @@ func TestSelector(t *testing.T) { <-e.Server.ReadyNotify() + port := strings.Split(e.Clients[0].Addr().String(), ":")[1] + endpoint := "127.0.0.1:" + port + var mu sync.Mutex selectedCount := 0 var wg sync.WaitGroup @@ -53,10 +62,10 @@ func TestSelector(t *testing.T) { } } - c0 := client.NewEtcd("127.0.0.1:2379") - c1 := client.NewEtcd("127.0.0.1:2379") - c2 := client.NewEtcd("127.0.0.1:2379") - c3 := client.NewEtcd("127.0.0.1:2379") + c0 := client.NewEtcd(endpoint) + c1 := client.NewEtcd(endpoint) + c2 := client.NewEtcd(endpoint) + c3 := client.NewEtcd(endpoint) wg.Add(3) go selectAndDone(c0) go selectAndDone(c1)