Skip to content

Commit

Permalink
zketcd: fixed bug causing hidden multi-op error
Browse files Browse the repository at this point in the history
zkResponse was hiding multi-op error in partial response,
added new response with error function.  Also, fixed test
to expect correct errors instead of api errors

Fixes etcd-io#98
  • Loading branch information
hokie228 committed Feb 27, 2019
1 parent 8487786 commit 876e4c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ func testMultiOp(t *testing.T, c *zk.Conn) {
ops = []interface{}{
&zk.CreateRequest{Path: "/foo", Data: []byte("foo"), Acl: acl},
}
if _, err := c.Multi(ops...); err == nil || err.Error() != zetcd.ErrAPIError.Error() {
t.Fatalf("expected %v, got %v", zetcd.ErrAPIError, err)
if _, err := c.Multi(ops...); err == nil || err.Error() != zetcd.ErrNodeExists.Error() {
t.Fatalf("expected %v, got %v", zetcd.ErrNodeExists, err)
}
// test create+delete on same key == no key
ops = []interface{}{
Expand All @@ -653,8 +653,8 @@ func testMultiOp(t *testing.T, c *zk.Conn) {
&zk.CheckVersionRequest{Path: "/foo", Version: 2},
}
_, err = c.Multi(ops...)
if err == nil || err.Error() != zetcd.ErrAPIError.Error() {
t.Fatalf("expected %v, got %v", zetcd.ErrAPIError, err)
if err == nil || err.Error() != zetcd.ErrBadVersion.Error() {
t.Fatalf("expected %v, got %v", zetcd.ErrBadVersion, err)
}
if _, s1, err = c.Get("/test1"); err == nil || err.Error() != zetcd.ErrNoNode.Error() {
t.Fatalf("expected %v, got (%v,%v)", zetcd.ErrNoNode, s1, err)
Expand All @@ -681,8 +681,8 @@ func testMultiOp(t *testing.T, c *zk.Conn) {
ops = []interface{}{
&zk.CheckVersionRequest{Path: "/missing-key", Version: 0},
}
if _, err = c.Multi(ops...); err == nil || err.Error() != zetcd.ErrAPIError.Error() {
t.Fatalf("expected %v, got %v", zetcd.ErrAPIError, err)
if _, err = c.Multi(ops...); err == nil || err.Error() != zetcd.ErrNoNode.Error() {
t.Fatalf("expected %v, got %v", zetcd.ErrNoNode, err)
}
// test empty operation list
if resp, err = c.Multi(); err != nil || len(resp) != 0 {
Expand Down
6 changes: 5 additions & 1 deletion zketcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func (z *zkEtcd) Multi(xid Xid, mreq *MultiRequest) ZKResponse {
mresp.Ops[i].Stat = &r.Stat
}
}
return mkZKResp(xid, zxid, mresp)
return mkZKPartialResp(xid, zxid, mresp, mresp.DoneHeader.Err)
}

resp, _ := z.doSTM(apply, prefetch...)
Expand Down Expand Up @@ -729,6 +729,10 @@ func mkZKResp(xid Xid, zxid ZXid, resp interface{}) ZKResponse {
return ZKResponse{Hdr: &ResponseHeader{xid, zxid - 1, 0}, Resp: resp}
}

func mkZKPartialResp(xid Xid, zxid ZXid, resp interface{}, err ErrCode) ZKResponse {
return ZKResponse{Hdr: &ResponseHeader{xid, zxid - 1, err}, Resp: resp}
}

// wrapErr is to pass back error info but still get the txn response
func wrapErr(err *error, f func(s v3sync.STM) error) func(s v3sync.STM) error {
return func(s v3sync.STM) error {
Expand Down

0 comments on commit 876e4c2

Please sign in to comment.