@@ -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 )
@@ -1673,7 +1716,7 @@ func (s *S) TestResumeIter(c *C) {
16731716	c .Assert (len (batch ), Equals , 0 )
16741717}
16751718
1676- var  cursorTimeout  =  flag .Bool ("cursor-timeout" , false , "Enable cursor timeout test " )
1719+ var  cursorTimeout  =  flag .Bool ("cursor-timeout" , false , "Enable cursor timeout tests " )
16771720
16781721func  (s  * S ) TestFindIterCursorTimeout (c  * C ) {
16791722	if  ! * cursorTimeout  {
@@ -1717,6 +1760,56 @@ func (s *S) TestFindIterCursorTimeout(c *C) {
17171760	c .Assert (iter .Err (), Equals , mgo .ErrCursor )
17181761}
17191762
1763+ func  (s  * S ) TestFindIterCursorNoTimeout (c  * C ) {
1764+ 	if  ! * cursorTimeout  {
1765+ 		c .Skip ("-cursor-timeout" )
1766+ 	}
1767+ 	session , err  :=  mgo .Dial ("localhost:40001" )
1768+ 	c .Assert (err , IsNil )
1769+ 	defer  session .Close ()
1770+ 
1771+ 	session .SetCursorTimeout (0 )
1772+ 
1773+ 	type  Doc  struct  {
1774+ 		Id  int  "_id" 
1775+ 	}
1776+ 
1777+ 	coll  :=  session .DB ("test" ).C ("test" )
1778+ 	coll .Remove (nil )
1779+ 	for  i  :=  0 ; i  <  100 ; i ++  {
1780+ 		err  =  coll .Insert (Doc {i })
1781+ 		c .Assert (err , IsNil )
1782+ 	}
1783+ 
1784+ 	session .SetBatch (1 )
1785+ 	iter  :=  coll .Find (nil ).Iter ()
1786+ 	var  doc  Doc 
1787+ 	if  ! iter .Next (& doc ) {
1788+ 		c .Fatalf ("iterator failed to return any documents" )
1789+ 	}
1790+ 
1791+ 	for  i  :=  10 ; i  >  0 ; i --  {
1792+ 		c .Logf ("Sleeping... %d minutes to go..." , i )
1793+ 		time .Sleep (1 * time .Minute  +  2 * time .Second )
1794+ 	}
1795+ 
1796+ 	// Drain any existing documents that were fetched. 
1797+ 	if  ! iter .Next (& doc ) {
1798+ 		c .Fatalf ("iterator failed to return previously cached document" )
1799+ 	}
1800+ 	for  i  :=  1 ; i  <  100 ; i ++  {
1801+ 		if  ! iter .Next (& doc ) {
1802+ 			c .Errorf ("iterator failed on iteration %d" , i )
1803+ 			break 
1804+ 		}
1805+ 	}
1806+ 	if  iter .Next (& doc ) {
1807+ 		c .Error ("iterator returned more than 100 documents" )
1808+ 	}
1809+ 
1810+ 	c .Assert (iter .Err (), IsNil )
1811+ }
1812+ 
17201813func  (s  * S ) TestTooManyItemsLimitBug (c  * C ) {
17211814	if  * fast  {
17221815		c .Skip ("-fast" )
0 commit comments