Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cursor timeout options and native static bindings hack

  • Loading branch information...
commit b77dd94f746dfeb06366842d5a1237ad1c2695e2 1 parent 45bdb34
@marcqualie authored
Showing with 54 additions and 2 deletions.
  1. +23 −1 lib/MongoMinify/Cursor.php
  2. +31 −1 tests/MongoMinify/Tests/CursorTest.php
View
24 lib/MongoMinify/Cursor.php
@@ -5,6 +5,8 @@
class Cursor implements \Iterator
{
+ static $timeout = 20000;
+
public $collection;
public $native;
@@ -15,8 +17,10 @@ public function __construct($collection, array $query = array(), array $fields =
$this->collection = $collection;
$this->native_query = $query;
$this->native = $collection->native->find($query, $fields);
+ $native = $this->native;
}
-
+
+
/**
* Move around cursor
*/
@@ -74,6 +78,7 @@ public function limit($num)
return $this;
}
+
/**
* Native abtracts
*/
@@ -85,4 +90,21 @@ public function valid()
{
return $this->native->valid();
}
+
+
+ /**
+ * Set Timeout
+ */
+ public function timeout($ms)
+ {
+ $native = $this->native;
+ $native->timeout($ms);
+ return $this;
+ }
+
}
+
+// Bind native timeouts
+// TODO: Temporary fix, need a better place to put this code
+Cursor::$timeout = \MongoCursor::$timeout;
+\MongoCursor::$timeout =& Cursor::$timeout;
View
32 tests/MongoMinify/Tests/CursorTest.php
@@ -33,4 +33,34 @@ public function testLimit()
}
-}
+ /**
+ * Test Timeouts
+ */
+ public function testTimeout()
+ {
+
+ // Create collection
+ $collection = $this->getTestCollection();
+
+ // Create a cursor object
+ $cursor = $collection->find();
+ $native_cursor = $cursor->native;
+
+ // Assert cursor timeouts are updated
+ $this->assertEquals($cursor::$timeout, $native_cursor::$timeout);
+ $cursor->timeout(1000);
+
+ // Check that static timeouts are binded
+ $default_timeout = \MongoCursor::$timeout;
+ $cursor::$timeout = $default_timeout / 2;
+ $this->assertEquals(\MongoCursor::$timeout, $cursor::$timeout);
+ $this->assertEquals(\MongoMinify\Cursor::$timeout, $cursor::$timeout);
+ \MongoCursor::$timeout = 200;
+ $this->assertEquals(\MongoCursor::$timeout, \MongoMinify\Cursor::$timeout);
+ $this->assertEquals(\MongoMinify\Cursor::$timeout, 200);
+
+
+ }
+
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.