Commit 6afb08f4 authored by Jeremy Mikola's avatar Jeremy Mikola

Create collection before change stream tests

parent a032bb3f
...@@ -930,6 +930,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -930,6 +930,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$db = new Database($this->manager, $this->getDatabaseName()); $db = new Database($this->manager, $this->getDatabaseName());
$db->dropCollection('inventory'); $db->dropCollection('inventory');
$db->createCollection('inventory');
// Start Changestream Example 1 // Start Changestream Example 1
$changeStream = $db->inventory->watch(); $changeStream = $db->inventory->watch();
......
...@@ -29,19 +29,18 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -29,19 +29,18 @@ class WatchFunctionalTest extends FunctionalTestCase
parent::setUp(); parent::setUp();
$this->skipIfChangeStreamIsNotSupported(); $this->skipIfChangeStreamIsNotSupported();
$this->createCollection();
} }
public function testNextResumesAfterCursorNotFound() public function testNextResumesAfterCursorNotFound()
{ {
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
$changeStream->rewind(); $changeStream->rewind();
$this->assertFalse($changeStream->valid()); $this->assertFalse($changeStream->valid());
$this->insertDocument(['_id' => 2, 'x' => 'bar']); $this->insertDocument(['_id' => 1, 'x' => 'foo']);
$changeStream->next(); $changeStream->next();
$this->assertTrue($changeStream->valid()); $this->assertTrue($changeStream->valid());
...@@ -49,16 +48,16 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -49,16 +48,16 @@ class WatchFunctionalTest extends FunctionalTestCase
$expectedResult = [ $expectedResult = [
'_id' => $changeStream->current()->_id, '_id' => $changeStream->current()->_id,
'operationType' => 'insert', 'operationType' => 'insert',
'fullDocument' => ['_id' => 2, 'x' => 'bar'], 'fullDocument' => ['_id' => 1, 'x' => 'foo'],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()], 'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
'documentKey' => ['_id' => 2], 'documentKey' => ['_id' => 1],
]; ];
$this->assertMatchesDocument($expectedResult, $changeStream->current()); $this->assertMatchesDocument($expectedResult, $changeStream->current());
$this->killChangeStreamCursor($changeStream); $this->killChangeStreamCursor($changeStream);
$this->insertDocument(['_id' => 3, 'x' => 'baz']); $this->insertDocument(['_id' => 2, 'x' => 'bar']);
$changeStream->next(); $changeStream->next();
$this->assertTrue($changeStream->valid()); $this->assertTrue($changeStream->valid());
...@@ -66,9 +65,9 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -66,9 +65,9 @@ class WatchFunctionalTest extends FunctionalTestCase
$expectedResult = [ $expectedResult = [
'_id' => $changeStream->current()->_id, '_id' => $changeStream->current()->_id,
'operationType' => 'insert', 'operationType' => 'insert',
'fullDocument' => ['_id' => 3, 'x' => 'baz'], 'fullDocument' => ['_id' => 2, 'x' => 'bar'],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()], 'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
'documentKey' => ['_id' => 3] 'documentKey' => ['_id' => 2]
]; ];
$this->assertMatchesDocument($expectedResult, $changeStream->current()); $this->assertMatchesDocument($expectedResult, $changeStream->current());
...@@ -335,15 +334,13 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -335,15 +334,13 @@ class WatchFunctionalTest extends FunctionalTestCase
public function testNoChangeAfterResumeBeforeInsert() public function testNoChangeAfterResumeBeforeInsert()
{ {
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
$this->assertNoCommandExecuted(function() use ($changeStream) { $changeStream->rewind(); }); $this->assertNoCommandExecuted(function() use ($changeStream) { $changeStream->rewind(); });
$this->assertFalse($changeStream->valid()); $this->assertFalse($changeStream->valid());
$this->insertDocument(['_id' => 2, 'x' => 'bar']); $this->insertDocument(['_id' => 1, 'x' => 'foo']);
$changeStream->next(); $changeStream->next();
$this->assertTrue($changeStream->valid()); $this->assertTrue($changeStream->valid());
...@@ -351,9 +348,9 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -351,9 +348,9 @@ class WatchFunctionalTest extends FunctionalTestCase
$expectedResult = [ $expectedResult = [
'_id' => $changeStream->current()->_id, '_id' => $changeStream->current()->_id,
'operationType' => 'insert', 'operationType' => 'insert',
'fullDocument' => ['_id' => 2, 'x' => 'bar'], 'fullDocument' => ['_id' => 1, 'x' => 'foo'],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()], 'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
'documentKey' => ['_id' => 2], 'documentKey' => ['_id' => 1],
]; ];
$this->assertMatchesDocument($expectedResult, $changeStream->current()); $this->assertMatchesDocument($expectedResult, $changeStream->current());
...@@ -363,7 +360,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -363,7 +360,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$changeStream->next(); $changeStream->next();
$this->assertFalse($changeStream->valid()); $this->assertFalse($changeStream->valid());
$this->insertDocument(['_id' => 3, 'x' => 'baz']); $this->insertDocument(['_id' => 2, 'x' => 'bar']);
$changeStream->next(); $changeStream->next();
$this->assertTrue($changeStream->valid()); $this->assertTrue($changeStream->valid());
...@@ -371,9 +368,9 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -371,9 +368,9 @@ class WatchFunctionalTest extends FunctionalTestCase
$expectedResult = [ $expectedResult = [
'_id' => $changeStream->current()->_id, '_id' => $changeStream->current()->_id,
'operationType' => 'insert', 'operationType' => 'insert',
'fullDocument' => ['_id' => 3, 'x' => 'baz'], 'fullDocument' => ['_id' => 2, 'x' => 'bar'],
'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()], 'ns' => ['db' => $this->getDatabaseName(), 'coll' => $this->getCollectionName()],
'documentKey' => ['_id' => 3], 'documentKey' => ['_id' => 2],
]; ];
$this->assertMatchesDocument($expectedResult, $changeStream->current()); $this->assertMatchesDocument($expectedResult, $changeStream->current());
...@@ -381,9 +378,6 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -381,9 +378,6 @@ class WatchFunctionalTest extends FunctionalTestCase
public function testResumeMultipleTimesInSuccession() public function testResumeMultipleTimesInSuccession()
{ {
$operation = new CreateCollection($this->getDatabaseName(), $this->getCollectionName());
$operation->execute($this->getPrimaryServer());
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $operation->execute($this->getPrimaryServer());
...@@ -966,9 +960,6 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -966,9 +960,6 @@ class WatchFunctionalTest extends FunctionalTestCase
public function testSessionFreed() public function testSessionFreed()
{ {
// Create collection so we can drop it later
$this->createCollection();
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions); $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
$changeStream = $operation->execute($this->getPrimaryServer()); $changeStream = $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