Skip to content

Commit 6478dcd

Browse files
authored
Merge branch 'develop' into next
2 parents c3b528b + b5240cd commit 6478dcd

File tree

12 files changed

+348
-152
lines changed

12 files changed

+348
-152
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ go:
66
- 1.9.x
77
- 1.10.x
88
- 1.11.x
9+
- 1.12.x
910
- master
1011

1112
cache: apt

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## v5.0.1 - 2018-10-18
6+
7+
- Fix noreply queries memory leak due unnecessary for responses
8+
59
## v5.0.0 - 2018-09-12
610

711
- Moved to rethinkdb organization

README.md

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Current version: v5.1.0 (RethinkDB v2.4)
1212

1313
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).
1414

15-
If you need any help you can find me on the [RethinkDB slack](http://slack.rethinkdb.com/) in the #gorethink channel.
15+
If you need any help you can find me on the [RethinkDB slack](https://rethinkdb.slack.com/) in the #gorethink channel.
1616

1717
## Installation
1818

@@ -456,6 +456,43 @@ func TestSomething(t *testing.T) {
456456
}
457457
```
458458

459+
If you want the cursor to block on some of the response values, you can pass in
460+
a value of type `chan interface{}` and the cursor will block until a value is
461+
available to read on the channel. Or you can pass in a function with signature
462+
`func() interface{}`: the cursor will call the function (which may block). Here
463+
is the example above adapted to use a channel.
464+
465+
```go
466+
func TestSomething(t *testing.T) {
467+
mock := r.NewMock()
468+
ch := make(chan []interface{})
469+
mock.On(r.Table("people")).Return(ch, nil)
470+
go func() {
471+
ch <- []interface{}{
472+
map[string]interface{}{"id": 1, "name": "John Smith"},
473+
map[string]interface{}{"id": 2, "name": "Jane Smith"},
474+
}
475+
ch <- []interface{}{map[string]interface{}{"id": 3, "name": "Jack Smith"}}
476+
close(ch)
477+
}()
478+
cursor, err := r.Table("people").Run(mock)
479+
if err != nil {
480+
t.Errorf("err is: %v", err)
481+
}
482+
483+
var rows []interface{}
484+
err = cursor.All(&rows)
485+
if err != nil {
486+
t.Errorf("err is: %v", err)
487+
}
488+
489+
// Test result of rows
490+
491+
mock.AssertExpectations(t)
492+
}
493+
494+
```
495+
459496
The mocking implementation is based on amazing https://github.com/stretchr/testify library, thanks to @stretchr for their awesome work!
460497

461498
## Benchmarks
@@ -464,17 +501,17 @@ Everyone wants their project's benchmarks to be speedy. And while we know that R
464501

465502
Thanks to @jaredfolkins for the contribution.
466503

467-
| Type | Value |
468-
| --- | --- |
469-
| **Model Name** | MacBook Pro |
470-
| **Model Identifier** | MacBookPro11,3 |
471-
| **Processor Name** | Intel Core i7 |
472-
| **Processor Speed** | 2.3 GHz |
473-
| **Number of Processors** | 1 |
474-
| **Total Number of Cores** | 4 |
475-
| **L2 Cache (per Core)** | 256 KB |
476-
| **L3 Cache** | 6 MB |
477-
| **Memory** | 16 GB |
504+
| Type | Value |
505+
| ------------------------- | -------------- |
506+
| **Model Name** | MacBook Pro |
507+
| **Model Identifier** | MacBookPro11,3 |
508+
| **Processor Name** | Intel Core i7 |
509+
| **Processor Speed** | 2.3 GHz |
510+
| **Number of Processors** | 1 |
511+
| **Total Number of Cores** | 4 |
512+
| **L2 Cache (per Core)** | 256 KB |
513+
| **L3 Cache** | 6 MB |
514+
| **Memory** | 16 GB |
478515

479516
```bash
480517
BenchmarkBatch200RandomWrites 20 557227775 ns/op

connection.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,7 @@ func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, er
209209
}
210210

211211
if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) {
212-
select {
213-
case c.readRequestsChan <- tokenAndPromise{ctx: ctx, query: &q, span: fetchingSpan}:
214-
return nil, nil, nil
215-
case <-ctx.Done():
216-
return c.stopQuery(&q)
217-
}
212+
return nil, nil, nil
218213
}
219214

220215
promise := make(chan responseAndCursor, 1)
@@ -469,7 +464,7 @@ func (c *Connection) processResponse(ctx context.Context, q Query, response *Res
469464
case p.Response_WAIT_COMPLETE:
470465
return c.processWaitResponse(response)
471466
default:
472-
return nil, nil, RQLDriverError{rqlError("Unexpected response type: %v")}
467+
return nil, nil, RQLDriverError{rqlError(fmt.Sprintf("Unexpected response type: %v", response.Type.String()))}
473468
}
474469
}
475470

connection_test.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,6 @@ func (s *ConnectionSuite) TestConnection_Query_NoReplyOk(c *test.C) {
143143
conn.AssertExpectations(c)
144144
}
145145

146-
func (s *ConnectionSuite) TestConnection_Query_NoReplyTimeoutWrite(c *test.C) {
147-
ctx, cancel := context.WithCancel(context.Background())
148-
token := int64(1)
149-
q := testQuery(DB("db").Table("table").Get("id"))
150-
q.Opts["noreply"] = true
151-
writeData := serializeQuery(token, q)
152-
stopData := serializeQuery(token, newStopQuery(token))
153-
154-
conn := &connMock{}
155-
conn.On("Write", writeData).Return(len(writeData), nil)
156-
conn.On("Write", stopData).Return(len(stopData), nil)
157-
conn.On("SetWriteDeadline").Return(nil)
158-
159-
connection := newConnection(conn, "addr", &ConnectOpts{ReadTimeout: time.Millisecond, WriteTimeout: time.Millisecond})
160-
connection.readRequestsChan = make(chan tokenAndPromise, 0)
161-
cancel()
162-
response, cursor, err := connection.Query(ctx, q)
163-
164-
c.Assert(response, test.IsNil)
165-
c.Assert(cursor, test.IsNil)
166-
c.Assert(err, test.Equals, ErrQueryTimeout)
167-
conn.AssertExpectations(c)
168-
}
169-
170146
func (s *ConnectionSuite) TestConnection_Query_TimeoutWrite(c *test.C) {
171147
ctx, cancel := context.WithCancel(context.Background())
172148
token := int64(1)

cursor.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ func (c *Cursor) nextLocked(dest interface{}, progressCursor bool) (bool, error)
227227
if progressCursor {
228228
c.buffer = c.buffer[1:]
229229
}
230-
231230
err := encoding.Decode(dest, data)
232231
if err != nil {
233232
return false, err
@@ -494,7 +493,6 @@ func (c *Cursor) Listen(channel interface{}) {
494493
if !c.Next(elemp.Interface()) {
495494
break
496495
}
497-
498496
channelv.Send(elemp.Elem())
499497
}
500498

cursor_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package rethinkdb
2+
3+
import (
4+
test "gopkg.in/check.v1"
5+
"gopkg.in/rethinkdb/rethinkdb-go.v5/internal/integration/tests"
6+
)
7+
8+
type CursorSuite struct{}
9+
10+
var _ = test.Suite(&CursorSuite{})
11+
12+
func (s *CursorSuite) TestCursor_One_Ok(c *test.C) {
13+
data := map[string]interface{}{
14+
"A": 1,
15+
"B": true,
16+
}
17+
18+
mock := NewMock()
19+
ch := make(chan []interface{})
20+
mock.On(DB("test").Table("test")).Return(ch, nil)
21+
go func() {
22+
ch <- []interface{}{data}
23+
close(ch)
24+
}()
25+
res, err := DB("test").Table("test").Run(mock)
26+
c.Assert(err, test.IsNil)
27+
28+
var response interface{}
29+
err = res.One(&response)
30+
31+
c.Assert(err, test.IsNil)
32+
c.Assert(response, tests.JsonEquals, data)
33+
mock.AssertExpectations(c)
34+
}

encoding/decoder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func TestDecodeUnmarshalerPointer(t *testing.T) {
433433
t.Errorf("got error %v, expected nil", err)
434434
}
435435
if !jsonEqual(out, want) {
436-
t.Errorf("got %q, want %q", out, want)
436+
t.Errorf("got %+v, want %+v", out, want)
437437
}
438438
}
439439

@@ -587,7 +587,7 @@ func TestDecodeCustomTypeEncodingPointer(t *testing.T) {
587587
t.Errorf("got error %v, expected nil", err)
588588
}
589589
if !jsonEqual(out, want) {
590-
t.Errorf("got %q, want %q", out, want)
590+
t.Errorf("got %+v, want %+v", out, want)
591591
}
592592
}
593593

0 commit comments

Comments
 (0)