Skip to content

Commit 75f0fb8

Browse files
committed
Merge pull request #622
2 parents 401496a + d13ab85 commit 75f0fb8

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/ChangeStream.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,15 @@ private function onIteration($isNext)
212212
return;
213213
}
214214

215+
$this->resumeToken = $this->extractResumeToken($this->csIt->current());
216+
215217
/* Increment the key if the iteration event was a call to next() and we
216218
* have already advanced past the first result. */
217219
if ($isNext && $this->hasAdvanced) {
218220
$this->key++;
219221
}
220222

221223
$this->hasAdvanced = true;
222-
$this->resumeToken = $this->extractResumeToken($this->csIt->current());
223224
}
224225

225226
/**

tests/Operation/WatchFunctionalTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ public function testNextAdvancesKey()
706706
$this->assertSame(1, $changeStream->key());
707707
}
708708

709-
public function testResumeTokenNotFoundAdvancesKey()
709+
public function testResumeTokenNotFoundDoesNotAdvanceKey()
710710
{
711711
if (version_compare($this->getServerVersion(), '4.1.8', '>=')) {
712712
$this->markTestSkipped('Server rejects change streams that modify resume token (SERVER-37786)');
@@ -717,8 +717,6 @@ public function testResumeTokenNotFoundAdvancesKey()
717717
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, $this->defaultOptions);
718718
$changeStream = $operation->execute($this->getPrimaryServer());
719719

720-
/* Note: we intentionally do not start iteration with rewind() to ensure
721-
* that we test extraction functionality within next(). */
722720
$this->insertDocument(['x' => 1]);
723721
$this->insertDocument(['x' => 2]);
724722
$this->insertDocument(['x' => 3]);
@@ -735,14 +733,14 @@ public function testResumeTokenNotFoundAdvancesKey()
735733
$this->fail('ResumeTokenException was not thrown');
736734
} catch (ResumeTokenException $e) {}
737735

738-
$this->assertSame(1, $changeStream->key());
736+
$this->assertSame(0, $changeStream->key());
739737

740738
try {
741739
$changeStream->next();
742740
$this->fail('ResumeTokenException was not thrown');
743741
} catch (ResumeTokenException $e) {}
744742

745-
$this->assertSame(2, $changeStream->key());
743+
$this->assertSame(0, $changeStream->key());
746744
}
747745

748746
public function testSessionPersistsAfterResume()

0 commit comments

Comments
 (0)