Skip to content

Commit

Permalink
Fix CreateProtectedEphemeralSequential to return a proper error if to…
Browse files Browse the repository at this point in the history
…o many tries
  • Loading branch information
samuel committed Oct 28, 2013
1 parent 4b124e0 commit 7dcc54b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
6 changes: 4 additions & 2 deletions zk/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,15 @@ func (c *Conn) CreateProtectedEphemeralSequential(path string, data []byte, acl
rootPath := strings.Join(parts[:len(parts)-1], "/")
protectedPath := strings.Join(parts, "/")

var newPath string
var children []string
for i := 0; i < 3; i++ {
newPath, err := c.Create(protectedPath, data, FlagEphemeral|FlagSequence, acl)
newPath, err = c.Create(protectedPath, data, FlagEphemeral|FlagSequence, acl)
switch err {
case ErrSessionExpired:
// No need to search for the node since it can't exist. Just try again.
case ErrConnectionClosed:
children, _, err := c.Children(rootPath)
children, _, err = c.Children(rootPath)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions zk/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestLock(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestLock(t *testing.T) {
// This tests creating a lock with a path that's more than 1 node deep (e.g. "/test-multi-level/lock"),
// when a part of that path already exists (i.e. "/test-multi-level" node already exists).
func TestMultiLevelLock(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand Down
18 changes: 10 additions & 8 deletions zk/zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"time"
)

const testAddr = "127.0.0.1:2182"

func TestCreate(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand All @@ -32,7 +34,7 @@ func TestCreate(t *testing.T) {
}

func TestMulti(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand Down Expand Up @@ -67,7 +69,7 @@ func TestMulti(t *testing.T) {
}

func TestGetSetACL(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand Down Expand Up @@ -116,7 +118,7 @@ func TestGetSetACL(t *testing.T) {
}

func TestAuth(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand Down Expand Up @@ -161,7 +163,7 @@ func TestAuth(t *testing.T) {
}

func TestChildWatch(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand Down Expand Up @@ -200,14 +202,14 @@ func TestChildWatch(t *testing.T) {
}

func TestSetWatchers(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
defer zk.Close()
zk.reconnectDelay = time.Second

zk2, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second*15)
zk2, _, err := Connect([]string{testAddr}, time.Second*15)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand Down Expand Up @@ -250,7 +252,7 @@ func TestSetWatchers(t *testing.T) {
}

func TestExpiringWatch(t *testing.T) {
zk, _, err := Connect([]string{"127.0.0.1:2182"}, time.Second)
zk, _, err := Connect([]string{testAddr}, time.Second)
if err != nil {
t.Fatalf("Connect returned error: %+v", err)
}
Expand Down

0 comments on commit 7dcc54b

Please sign in to comment.