Commit 2c87d398 authored by Jeremy Mikola's avatar Jeremy Mikola

Refactor killing of change stream cursor to private method

parent 41892d26
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\ChangeStream;
use MongoDB\Client; use MongoDB\Client;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
...@@ -52,8 +53,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -52,8 +53,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->assertSameDocument($expectedResult, $changeStream->current()); $this->assertSameDocument($expectedResult, $changeStream->current());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]); $this->killChangeStreamCursor($changeStream);
$operation->execute($this->getPrimaryServer());
$this->insertDocument(['_id' => 3, 'x' => 'baz']); $this->insertDocument(['_id' => 3, 'x' => 'baz']);
...@@ -150,8 +150,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -150,8 +150,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$this->assertSameDocument($expectedResult, $changeStream->current()); $this->assertSameDocument($expectedResult, $changeStream->current());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]); $this->killChangeStreamCursor($changeStream);
$operation->execute($this->getPrimaryServer());
$changeStream->next(); $changeStream->next();
$this->assertNull($changeStream->current()); $this->assertNull($changeStream->current());
...@@ -176,8 +175,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -176,8 +175,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), []); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), []);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]); $this->killChangeStreamCursor($changeStream);
$operation->execute($this->getPrimaryServer());
$changeStream->next(); $changeStream->next();
$this->assertNull($changeStream->current()); $this->assertNull($changeStream->current());
...@@ -188,8 +186,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -188,8 +186,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), []); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), []);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]); $this->killChangeStreamCursor($changeStream);
$operation->execute($this->getPrimaryServer());
$this->insertDocument(['_id' => 1, 'x' => 'foo']); $this->insertDocument(['_id' => 1, 'x' => 'foo']);
...@@ -214,8 +211,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -214,8 +211,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$changeStream->next(); $changeStream->next();
$this->assertNull($changeStream->key()); $this->assertNull($changeStream->key());
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]); $this->killChangeStreamCursor($changeStream);
$operation->execute($this->getPrimaryServer());
$changeStream->next(); $changeStream->next();
$this->assertNull($changeStream->key()); $this->assertNull($changeStream->key());
...@@ -318,4 +314,15 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -318,4 +314,15 @@ class WatchFunctionalTest extends FunctionalTestCase
$writeResult = $insertOne->execute($this->getPrimaryServer()); $writeResult = $insertOne->execute($this->getPrimaryServer());
$this->assertEquals(1, $writeResult->getInsertedCount()); $this->assertEquals(1, $writeResult->getInsertedCount());
} }
private function killChangeStreamCursor(ChangeStream $changeStream)
{
$command = [
'killCursors' => $this->getCollectionName(),
'cursors' => [ $changeStream->getCursorId() ],
];
$operation = new DatabaseCommand($this->getDatabaseName(), $command);
$operation->execute($this->getPrimaryServer());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment