From 876e4c28d441cb1fc389b806a679d89ab5479acd Mon Sep 17 00:00:00 2001 From: Keith Schaffer Date: Wed, 27 Feb 2019 12:41:15 -0500 Subject: [PATCH] zketcd: fixed bug causing hidden multi-op error 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 #98 --- integration/integration_test.go | 12 ++++++------ zketcd.go | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index 3f0b341..4d46f9c 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -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{}{ @@ -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) @@ -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 { diff --git a/zketcd.go b/zketcd.go index e4d1b20..a237b87 100644 --- a/zketcd.go +++ b/zketcd.go @@ -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...) @@ -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 {