Skip to content

Commit ad5fa11

Browse files
authored
Merge branch 'development' into bugfix/jameinel-max-txn-queue-length
2 parents 3f6e5c5 + db81f4c commit ad5fa11

File tree

5 files changed

+88
-17
lines changed

5 files changed

+88
-17
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ Further PR's (with tests) are welcome, but please maintain backwards compatibili
1515
* Support majority read concerns ([details](https://github.com/globalsign/mgo/pull/2))
1616
* Improved connection handling ([details](https://github.com/globalsign/mgo/pull/5))
1717
* Hides SASL warnings ([details](https://github.com/globalsign/mgo/pull/7))
18+
* Fixes timezone handling ([details](https://github.com/go-mgo/mgo/pull/464))
1819
* Improved multi-document transaction performance ([details](https://github.com/globalsign/mgo/pull/10), [more](https://github.com/globalsign/mgo/pull/11), [more](https://github.com/globalsign/mgo/pull/16))
20+
* Fixes cursor timeouts ([detials](https://jira.mongodb.org/browse/SERVER-24899))
1921

2022
---
2123

2224
### Thanks to
25+
* @BenLubar
2326
* @carter2000
2427
* @cezarsa
2528
* @eaglerayp
2629
* @drichelson
2730
* @jameinel
31+
* @Reenjii
2832
* @smoya
2933
* @wgallagher

bson/json.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"fmt"
77
"strconv"
8+
"strings"
89
"time"
910

1011
"github.com/globalsign/mgo/internal/json"
@@ -156,7 +157,7 @@ func jencBinaryType(v interface{}) ([]byte, error) {
156157
return fbytes(`{"$binary":"%s","$type":"0x%x"}`, out, in.Kind), nil
157158
}
158159

159-
const jdateFormat = "2006-01-02T15:04:05.999Z"
160+
const jdateFormat = "2006-01-02T15:04:05.999Z07:00"
160161

161162
func jdecDate(data []byte) (interface{}, error) {
162163
var v struct {
@@ -170,13 +171,15 @@ func jdecDate(data []byte) (interface{}, error) {
170171
v.S = v.Func.S
171172
}
172173
if v.S != "" {
174+
var errs []string
173175
for _, format := range []string{jdateFormat, "2006-01-02"} {
174176
t, err := time.Parse(format, v.S)
175177
if err == nil {
176178
return t, nil
177179
}
180+
errs = append(errs, err.Error())
178181
}
179-
return nil, fmt.Errorf("cannot parse date: %q", v.S)
182+
return nil, fmt.Errorf("cannot parse date: %q [%s]", v.S, strings.Join(errs, ", "))
180183
}
181184

182185
var vn struct {

bson/json_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ var jsonTests = []jsonTest{
3434
{
3535
a: time.Date(2016, 5, 15, 1, 2, 3, 4000000, time.UTC),
3636
b: `{"$date":"2016-05-15T01:02:03.004Z"}`,
37+
}, {
38+
a: time.Date(2016, 5, 15, 1, 2, 3, 4000000, time.FixedZone("CET", 60*60)),
39+
b: `{"$date":"2016-05-15T01:02:03.004+01:00"}`,
3740
}, {
3841
b: `{"$date": {"$numberLong": "1002"}}`,
3942
c: time.Date(1970, 1, 1, 0, 0, 1, 2e6, time.UTC),
4043
}, {
4144
b: `ISODate("2016-05-15T01:02:03.004Z")`,
4245
c: time.Date(2016, 5, 15, 1, 2, 3, 4000000, time.UTC),
46+
}, {
47+
b: `ISODate("2016-05-15T01:02:03.004-07:00")`,
48+
c: time.Date(2016, 5, 15, 1, 2, 3, 4000000, time.FixedZone("PDT", -7*60*60)),
4349
}, {
4450
b: `new Date(1000)`,
4551
c: time.Date(1970, 1, 1, 0, 0, 1, 0, time.UTC),
@@ -180,6 +186,11 @@ func (s *S) TestJSON(c *C) {
180186
value = zerov.Elem().Interface()
181187
}
182188
c.Logf("Loaded: %#v", value)
189+
if ctime, ok := item.c.(time.Time); ok {
190+
// time.Time must be compared with time.Time.Equal and not reflect.DeepEquals
191+
c.Assert(ctime.Equal(value.(time.Time)), Equals, true)
192+
continue
193+
}
183194
c.Assert(value, DeepEquals, item.c)
184195
}
185196
}

session.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,20 +3281,23 @@ func prepareFindOp(socket *mongoSocket, op *queryOp, limit int32) bool {
32813281
}
32823282

32833283
find := findCmd{
3284-
Collection: op.collection[nameDot+1:],
3285-
Filter: op.query,
3286-
Projection: op.selector,
3287-
Sort: op.options.OrderBy,
3288-
Skip: op.skip,
3289-
Limit: limit,
3290-
MaxTimeMS: op.options.MaxTimeMS,
3291-
MaxScan: op.options.MaxScan,
3292-
Hint: op.options.Hint,
3293-
Comment: op.options.Comment,
3294-
Snapshot: op.options.Snapshot,
3295-
OplogReplay: op.flags&flagLogReplay != 0,
3296-
Collation: op.options.Collation,
3297-
ReadConcern: readLevel{level: op.readConcern},
3284+
Collection: op.collection[nameDot+1:],
3285+
Filter: op.query,
3286+
Projection: op.selector,
3287+
Sort: op.options.OrderBy,
3288+
Skip: op.skip,
3289+
Limit: limit,
3290+
MaxTimeMS: op.options.MaxTimeMS,
3291+
MaxScan: op.options.MaxScan,
3292+
Hint: op.options.Hint,
3293+
Comment: op.options.Comment,
3294+
Snapshot: op.options.Snapshot,
3295+
Collation: op.options.Collation,
3296+
Tailable: op.flags&flagTailable != 0,
3297+
AwaitData: op.flags&flagAwaitData != 0,
3298+
OplogReplay: op.flags&flagLogReplay != 0,
3299+
NoCursorTimeout: op.flags&flagNoCursorTimeout != 0,
3300+
ReadConcern: readLevel{level: op.readConcern},
32983301
}
32993302

33003303
if op.limit < 0 {

session_test.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ func (s *S) TestResumeIter(c *C) {
16731673
c.Assert(len(batch), Equals, 0)
16741674
}
16751675

1676-
var cursorTimeout = flag.Bool("cursor-timeout", false, "Enable cursor timeout test")
1676+
var cursorTimeout = flag.Bool("cursor-timeout", false, "Enable cursor timeout tests")
16771677

16781678
func (s *S) TestFindIterCursorTimeout(c *C) {
16791679
if !*cursorTimeout {
@@ -1717,6 +1717,56 @@ func (s *S) TestFindIterCursorTimeout(c *C) {
17171717
c.Assert(iter.Err(), Equals, mgo.ErrCursor)
17181718
}
17191719

1720+
func (s *S) TestFindIterCursorNoTimeout(c *C) {
1721+
if !*cursorTimeout {
1722+
c.Skip("-cursor-timeout")
1723+
}
1724+
session, err := mgo.Dial("localhost:40001")
1725+
c.Assert(err, IsNil)
1726+
defer session.Close()
1727+
1728+
session.SetCursorTimeout(0)
1729+
1730+
type Doc struct {
1731+
Id int "_id"
1732+
}
1733+
1734+
coll := session.DB("test").C("test")
1735+
coll.Remove(nil)
1736+
for i := 0; i < 100; i++ {
1737+
err = coll.Insert(Doc{i})
1738+
c.Assert(err, IsNil)
1739+
}
1740+
1741+
session.SetBatch(1)
1742+
iter := coll.Find(nil).Iter()
1743+
var doc Doc
1744+
if !iter.Next(&doc) {
1745+
c.Fatalf("iterator failed to return any documents")
1746+
}
1747+
1748+
for i := 10; i > 0; i-- {
1749+
c.Logf("Sleeping... %d minutes to go...", i)
1750+
time.Sleep(1*time.Minute + 2*time.Second)
1751+
}
1752+
1753+
// Drain any existing documents that were fetched.
1754+
if !iter.Next(&doc) {
1755+
c.Fatalf("iterator failed to return previously cached document")
1756+
}
1757+
for i := 1; i < 100; i++ {
1758+
if !iter.Next(&doc) {
1759+
c.Errorf("iterator failed on iteration %d", i)
1760+
break
1761+
}
1762+
}
1763+
if iter.Next(&doc) {
1764+
c.Error("iterator returned more than 100 documents")
1765+
}
1766+
1767+
c.Assert(iter.Err(), IsNil)
1768+
}
1769+
17201770
func (s *S) TestTooManyItemsLimitBug(c *C) {
17211771
if *fast {
17221772
c.Skip("-fast")

0 commit comments

Comments
 (0)