@@ -1275,6 +1275,49 @@ func (s *S) TestCountSkipLimit(c *C) {
12751275 c .Assert (n , Equals , 4 )
12761276}
12771277
1278+ func (s * S ) TestCountMaxTimeMS (c * C ) {
1279+ if ! s .versionAtLeast (2 , 6 ) {
1280+ c .Skip ("SetMaxTime only supported in 2.6+" )
1281+ }
1282+
1283+ session , err := mgo .Dial ("localhost:40001" )
1284+ c .Assert (err , IsNil )
1285+ defer session .Close ()
1286+
1287+ coll := session .DB ("mydb" ).C ("mycoll" )
1288+
1289+ ns := make ([]int , 100000 )
1290+ for _ , n := range ns {
1291+ err := coll .Insert (M {"n" : n })
1292+ c .Assert (err , IsNil )
1293+ }
1294+ _ , err = coll .Find (M {"n" : M {"$gt" : 1 }}).SetMaxTime (1 * time .Millisecond ).Count ()
1295+ e := err .(* mgo.QueryError )
1296+ // We hope this query took longer than 1 ms, which triggers an error code 50
1297+ c .Assert (e .Code , Equals , 50 )
1298+
1299+ }
1300+
1301+ func (s * S ) TestCountHint (c * C ) {
1302+ if ! s .versionAtLeast (2 , 6 ) {
1303+ c .Skip ("Not implemented until mongo 2.5.5 https://jira.mongodb.org/browse/SERVER-2677" )
1304+ }
1305+
1306+ session , err := mgo .Dial ("localhost:40001" )
1307+ c .Assert (err , IsNil )
1308+ defer session .Close ()
1309+
1310+ coll := session .DB ("mydb" ).C ("mycoll" )
1311+ err = coll .Insert (M {"n" : 1 })
1312+ c .Assert (err , IsNil )
1313+
1314+ _ , err = coll .Find (M {"n" : M {"$gt" : 1 }}).Hint ("does_not_exists" ).Count ()
1315+ e := err .(* mgo.QueryError )
1316+ // If Hint wasn't doing anything, then Count would ignore the non existent index hint
1317+ // and return the normal ount. But we instead get an error code 2: bad hint
1318+ c .Assert (e .Code , Equals , 2 )
1319+ }
1320+
12781321func (s * S ) TestQueryExplain (c * C ) {
12791322 session , err := mgo .Dial ("localhost:40001" )
12801323 c .Assert (err , IsNil )
0 commit comments