Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix master_test flake #19195

Merged
merged 1 commit into from Dec 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions pkg/storage/etcd/etcd_helper.go
Expand Up @@ -130,10 +130,7 @@ func (h *etcdHelper) Backends(ctx context.Context) []string {
glog.Errorf("Error obtaining etcd members list: %q", err)
return nil
}
if 0 == len(members) {
return nil
}
mlist := []string{""}
mlist := []string{}
for _, member := range members {
mlist = append(mlist, member.ClientURLs...)
}
Expand Down
27 changes: 25 additions & 2 deletions pkg/storage/etcd/testing/utils.go
Expand Up @@ -32,6 +32,8 @@ import (
"github.com/coreos/etcd/pkg/transport"
"github.com/coreos/etcd/pkg/types"
"github.com/coreos/etcd/rafthttp"
"github.com/golang/glog"
"golang.org/x/net/context"
)

// EtcdTestServer encapsulates the datastructures needed to start local instance for testing
Expand Down Expand Up @@ -124,6 +126,22 @@ func (m *EtcdTestServer) launch(t *testing.T) error {
return nil
}

// waitForEtcd wait until etcd is propagated correctly
func (m *EtcdTestServer) waitUntilUp() error {
membersAPI := etcd.NewMembersAPI(m.Client)
for start := time.Now(); time.Since(start) < 5*time.Second; time.Sleep(10 * time.Millisecond) {
members, err := membersAPI.List(context.TODO())
if err != nil {
glog.Errorf("Error when getting etcd cluster members")
continue
}
if len(members) == 1 && len(members[0].ClientURLs) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to return error different than timeout if there is one member but ClientURLs is empty.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it consciously - I think that if ClientURLs and there is one members (which is exactly what is happening at the beginning), I want to return a timeout.

return nil
}
}
return fmt.Errorf("timeout on waiting for etcd cluster")
}

// Terminate will shutdown the running etcd server
func (m *EtcdTestServer) Terminate(t *testing.T) {
m.Client = nil
Expand All @@ -150,8 +168,13 @@ func NewEtcdTestClientServer(t *testing.T) *EtcdTestServer {
}
server.Client, err = etcd.New(cfg)
if err != nil {
t.Errorf("Unexpected Error in NewEtcdTestClientServer (%v)", err)
defer server.Terminate(t)
t.Errorf("Unexpected error in NewEtcdTestClientServer (%v)", err)
server.Terminate(t)
return nil
}
if err := server.waitUntilUp(); err != nil {
t.Errorf("Unexpected error in waitUntilUp (%v)", err)
server.Terminate(t)
return nil
}
return server
Expand Down