-
-
Notifications
You must be signed in to change notification settings - Fork 189
Specify time limit operation on a mongodb cursor #227
Changes from 4 commits
5a26415
8d463f3
f6494a3
3821ae6
d40ee0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,4 +253,13 @@ public function tailable($tail = true); | |
* @return self | ||
*/ | ||
public function timeout($ms); | ||
|
||
/** | ||
* Wrapper method for MongoCursor::maxTimeMS(). | ||
* | ||
* @see http://php.net/manual/en/mongocursor.maxtimems.php | ||
* @param integer $ms | ||
* @return self | ||
*/ | ||
public function maxTimeMS($ms); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically speaking, yes. This is a BC break and thus would force us to go 2.0. I'm kicking myself now for not catching all methods that were added in the 1.5 driver. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ne0h12: Unfortunately, this needs to be removed. We cannot add new interface methods without bumping a major version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I removed it |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -381,6 +381,44 @@ public function testRecreate() | |
$cursor->recreate(); | ||
} | ||
|
||
public function testSetMaxTimeMSWhenRecreateCursor() | ||
{ | ||
if (version_compare(phpversion('mongo'), '1.5.0', '<')) { | ||
$this->markTestSkipped('This test is not applicable to driver versions < 1.5.0'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use |
||
} | ||
|
||
$self = $this; | ||
|
||
$setCursorExpectations = function($mongoCursor) use ($self) { | ||
$mongoCursor->expects($self->once()) | ||
->method('maxTimeMS') | ||
->with(30000); | ||
}; | ||
|
||
$mongoCursor = $this->getMockMongoCursor(); | ||
$recreatedMongoCursor = $this->getMockMongoCursor(); | ||
|
||
$setCursorExpectations($mongoCursor); | ||
$setCursorExpectations($recreatedMongoCursor); | ||
|
||
$mongoCollection = $this->getMockCollection(); | ||
$mongoCollection->expects($this->once()) | ||
->method('find') | ||
->with(array('x' => 9500), array()) | ||
->will($this->returnValue($recreatedMongoCursor)); | ||
|
||
$collection = $this->getMockCollection(); | ||
$collection->expects($this->once()) | ||
->method('getMongoCollection') | ||
->will($this->returnValue($mongoCollection)); | ||
|
||
$cursor = $this->getTestCursor($collection, $mongoCursor, array('x' => 9500)); | ||
|
||
$cursor->maxTimeMS(30000); | ||
|
||
$cursor->recreate(); | ||
} | ||
|
||
private function getMockCollection() | ||
{ | ||
return $this->getMockBuilder('Doctrine\MongoDB\Collection') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ne0h12: The most compatible solution would be to call
MongoCursor::addOption('$maxTimeMS', $ms)
here, as it doesn't depend on the driver's method at all.