From 321b6667d1ee5f2b4b51a44ab5459be1d02832f4 Mon Sep 17 00:00:00 2001 From: Daniel Cannon Date: Thu, 3 Sep 2015 20:08:24 +0100 Subject: [PATCH 1/5] Fixed pointers not to be properly decoded --- CHANGELOG.md | 4 ++++ encoding/decoder.go | 10 +++++----- encoding/decoder_test.go | 20 ++++++++++++++++++++ encoding/decoder_types.go | 4 +++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcaffdd7..5ab84347 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased +### Fixed + - Fixed pointers not to be properly decoded + ## v1.1.2 ### Fixed - Fixed issue when encoding some maps diff --git a/encoding/decoder.go b/encoding/decoder.go index f50478ab..b2302e3a 100644 --- a/encoding/decoder.go +++ b/encoding/decoder.go @@ -52,6 +52,11 @@ func Decode(dst interface{}, src interface{}) (err error) { // decode decodes the source value into the destination value func decode(dv, sv reflect.Value) { + if dv.IsValid() { + dv = indirect(dv, false) + dv.Set(reflect.Zero(dv.Type())) + } + valueDecoder(dv, sv)(dv, sv) } @@ -69,11 +74,6 @@ func valueDecoder(dv, sv reflect.Value) decoderFunc { return invalidValueDecoder } - if dv.IsValid() { - dv = indirect(dv, false) - dv.Set(reflect.Zero(dv.Type())) - } - return typeDecoder(dv.Type(), sv.Type()) } diff --git a/encoding/decoder_test.go b/encoding/decoder_test.go index 45a3e388..e441927d 100644 --- a/encoding/decoder_test.go +++ b/encoding/decoder_test.go @@ -124,6 +124,11 @@ type S13 struct { S8 } +type PointerBasic struct { + X int + Y *int +} + type Pointer struct { PPoint *Point Point Point @@ -142,6 +147,11 @@ type Ambig struct { Second int `gorethink:"Hello"` } +// Decode test helper vars +var ( + sampleInt = 2 +) + var decodeTests = []decodeTest{ // basic types {in: true, ptr: new(bool), out: true}, @@ -253,6 +263,16 @@ var decodeTests = []decodeTest{ ptr: new(Pointer), out: Pointer{PPoint: nil, Point: Point{Z: 2}}, }, + { + in: map[string]interface{}{"x": 2}, + ptr: new(PointerBasic), + out: PointerBasic{X: 2, Y: nil}, + }, + { + in: map[string]interface{}{"x": 2, "y": 2}, + ptr: new(PointerBasic), + out: PointerBasic{X: 2, Y: &sampleInt}, + }, } func TestDecode(t *testing.T) { diff --git a/encoding/decoder_types.go b/encoding/decoder_types.go index 61d268f8..c3004852 100644 --- a/encoding/decoder_types.go +++ b/encoding/decoder_types.go @@ -185,7 +185,9 @@ func interfaceDecoder(dv, sv reflect.Value) { } func interfaceAsTypeDecoder(dv, sv reflect.Value) { - decode(dv, sv.Elem()) + if !sv.IsNil() { + decode(dv, sv.Elem()) + } } type ptrDecoder struct { From 4655b9abe7bbce5b67af43f75a66c1bb7a1ac81f Mon Sep 17 00:00:00 2001 From: Daniel Cannon Date: Thu, 3 Sep 2015 20:25:11 +0100 Subject: [PATCH 2/5] Updated travis script to run tests with short flag --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 76cc2062..7737be59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,4 +16,4 @@ before_script: - rethinkdb --port-offset 2 --directory rethinkdb_data2 --join localhost:29016 > /dev/null 2>&1 & - rethinkdb --port-offset 3 --directory rethinkdb_data3 --join localhost:29016 > /dev/null 2>&1 & -script: go test -tags='cluster' -race -check.vv -v ./... +script: go test -tags='cluster' -short -race -check.vv -v ./... From ff81743035c1693ea36add50fd94204fc06b26b4 Mon Sep 17 00:00:00 2001 From: Daniel Cannon Date: Sun, 6 Sep 2015 19:12:17 +0100 Subject: [PATCH 3/5] Fixed queries always timing out when Timeout ConnectOpt is set --- CHANGELOG.md | 1 + connection.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ab84347..1f547a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased ### Fixed - Fixed pointers not to be properly decoded + - Fixed queries always timing out when Timeout ConnectOpt is set. ## v1.1.2 ### Fixed diff --git a/connection.go b/connection.go index 87a25165..1424cdfa 100644 --- a/connection.go +++ b/connection.go @@ -163,7 +163,7 @@ func (c *Connection) sendQuery(q Query) error { } // Set timeout - if c.opts.Timeout == 0 { + if c.opts.WriteTimeout == 0 { c.conn.SetWriteDeadline(time.Time{}) } else { c.conn.SetWriteDeadline(time.Now().Add(c.opts.WriteTimeout)) @@ -189,7 +189,7 @@ func (c *Connection) nextToken() int64 { // could be read then an error is returned. func (c *Connection) readResponse() (*Response, error) { // Set timeout - if c.opts.Timeout == 0 { + if c.opts.ReadTimeout == 0 { c.conn.SetReadDeadline(time.Time{}) } else { c.conn.SetReadDeadline(time.Now().Add(c.opts.ReadTimeout)) From e6a6d61e96e823d10dc68c20657778a2be5deb37 Mon Sep 17 00:00:00 2001 From: Daniel Cannon Date: Sun, 6 Sep 2015 19:22:58 +0100 Subject: [PATCH 4/5] Updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f547a3c..d53e9ea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## Unreleased +## v1.1.3 ### Fixed - Fixed pointers not to be properly decoded - Fixed queries always timing out when Timeout ConnectOpt is set. From d2ede070d3913d4f07e96400d8fc900025f294e8 Mon Sep 17 00:00:00 2001 From: Daniel Cannon Date: Sun, 6 Sep 2015 19:23:05 +0100 Subject: [PATCH 5/5] Bumped version number --- README.md | 2 +- doc.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6611a212..8e9c49b2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ![GoRethink Logo](https://raw.github.com/wiki/dancannon/gorethink/gopher-and-thinker-s.png "Golang Gopher and RethinkDB Thinker") -Current version: v1.1.1 (RethinkDB v2.1) +Current version: v1.1.3 (RethinkDB v2.1) Please note that this version of the driver only supports versions of RethinkDB using the v0.4 protocol (any versions of the driver older than RethinkDB 2.0 will not work). diff --git a/doc.go b/doc.go index b4fbe103..d79ea3f7 100644 --- a/doc.go +++ b/doc.go @@ -1,6 +1,6 @@ // Package gorethink implements a Go driver for RethinkDB // -// Current version: v1.1.1 (RethinkDB v2.1) +// Current version: v1.1.3 (RethinkDB v2.1) // For more in depth information on how to use RethinkDB check out the API docs // at http://rethinkdb.com/api package gorethink