Skip to content

Update to latest ext-mongodb and MongoDB server versions #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ cache:

env:
global:
- DRIVER_VERSION=1.6.0alpha2
- DRIVER_VERSION=1.6.0alpha3
- SERVER_DISTRO=ubuntu1604
- SERVER_VERSION=4.0.10
- SERVER_VERSION=4.2.0
- DEPLOYMENT=STANDALONE
- COMPOSER_OPTIONS=

Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
env:
- COMPOSER_OPTIONS=--prefer-lowest

# Test older standalone server versions (3.0-3.6)
# Test older standalone server versions (3.0-4.0)
- stage: Test
php: "7.0"
dist: trusty
Expand All @@ -66,6 +66,10 @@ jobs:
php: "7.0"
env:
- SERVER_VERSION=3.6.13
- stage: Test
php: "7.3"
env:
- SERVER_VERSION=4.0.12

# Test other server configurations
- stage: Test
Expand Down Expand Up @@ -94,13 +98,6 @@ jobs:
env:
- DEPLOYMENT=SHARDED_CLUSTER_RS

# Test upcoming server versions
- stage: Test
php: "7.3"
env:
- SERVER_VERSION=4.2.0-rc1
- DEPLOYMENT=REPLICASET

before_install:
- pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami`
- export SERVER_FILENAME=mongodb-linux-x86_64-${SERVER_DISTRO}-${SERVER_VERSION}
Expand Down
2 changes: 1 addition & 1 deletion .travis/setup_mo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi
case $DEPLOYMENT in
SHARDED_CLUSTER)
${TRAVIS_BUILD_DIR}/.travis/mo.sh ${TRAVIS_BUILD_DIR}/mongo-orchestration/sharded_clusters/cluster.json start > /tmp/mo-result.json
cat /tmp/mo-result.json | tail -n 1 | php -r 'echo json_decode(file_get_contents("php://stdin"))->mongodb_uri;' > /tmp/uri.txt
cat /tmp/mo-result.json | tail -n 1 | php -r 'echo json_decode(file_get_contents("php://stdin"))->mongodb_uri, "/?retryWrites=false";' > /tmp/uri.txt
;;
SHARDED_CLUSTER_RS)
${TRAVIS_BUILD_DIR}/.travis/mo.sh ${TRAVIS_BUILD_DIR}/mongo-orchestration/sharded_clusters/cluster_replset.json start > /tmp/mo-result.json
Expand Down
11 changes: 7 additions & 4 deletions tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnsupportedException;
use MongoDB\Operation\Count;
use MongoDB\Operation\MapReduce;
use MongoDB\Tests\CommandObserver;
Expand Down Expand Up @@ -619,8 +620,6 @@ function(array $event) {

/**
* @dataProvider collectionWriteMethodClosures
* @expectedException MongoDB\Exception\UnsupportedException
* @expectedExceptionMessage "writeConcern" option cannot be specified within a transaction
*/
public function testMethodInTransactionWithWriteConcernOption($method)
{
Expand All @@ -631,6 +630,9 @@ public function testMethodInTransactionWithWriteConcernOption($method)
$session = $this->manager->startSession();
$session->startTransaction();

$this->expectException(UnsupportedException::class);
$this->expectExceptionMessage('"writeConcern" option cannot be specified within a transaction');

try {
call_user_func($method, $this->collection, $session, ['writeConcern' => new WriteConcern(1)]);
} finally {
Expand All @@ -640,8 +642,6 @@ public function testMethodInTransactionWithWriteConcernOption($method)

/**
* @dataProvider collectionReadMethodClosures
* @expectedException MongoDB\Exception\UnsupportedException
* @expectedExceptionMessage "readConcern" option cannot be specified within a transaction
*/
public function testMethodInTransactionWithReadConcernOption($method)
{
Expand All @@ -652,6 +652,9 @@ public function testMethodInTransactionWithReadConcernOption($method)
$session = $this->manager->startSession();
$session->startTransaction();

$this->expectException(UnsupportedException::class);
$this->expectExceptionMessage('"readConcern" option cannot be specified within a transaction');

try {
call_user_func($method, $this->collection, $session, ['readConcern' => new ReadConcern(ReadConcern::LOCAL)]);
} finally {
Expand Down
6 changes: 3 additions & 3 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public static function getUri($allowMultipleMongoses = false)
$parts[] = $urlParts['path'];
}
if (isset($urlParts['query'])) {
$parts += [
$parts = array_merge($parts, [
'?',
$urlParts['path']
];
$urlParts['query']
]);
}

return implode('', $parts);
Expand Down
12 changes: 11 additions & 1 deletion tests/Operation/AggregateFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,17 @@ function() use ($pipeline, $options) {
$results = iterator_to_array($operation->execute($this->getPrimaryServer()));

$this->assertCount(1, $results);
$this->assertObjectHasAttribute('stages', current($results));
$result = current($results);

if ($this->isShardedCluster()) {
$this->assertObjectHasAttribute('shards', $result);

foreach ($result->shards as $shard) {
$this->assertObjectHasAttribute('stages', $shard);
}
} else {
$this->assertObjectHasAttribute('stages', $result);
}
},
function(array $event) {
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
Expand Down
3 changes: 2 additions & 1 deletion tests/Operation/WatchFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WatchFunctionalTest extends FunctionalTestCase
{
use SetUpTearDownTrait;

const INTERRUPTED = 11601;
const NOT_MASTER = 10107;

private static $wireVersionForStartAtOperationTime = 7;
Expand Down Expand Up @@ -1295,7 +1296,7 @@ public function testErrorDuringAggregateCommandDoesNotCauseResume()
$this->configureFailPoint([
'configureFailPoint' => 'failCommand',
'mode' => ['times' => 1],
'data' => ['failCommands' => ['aggregate'], 'errorCode' => self::NOT_MASTER],
'data' => ['failCommands' => ['aggregate'], 'errorCode' => self::INTERRUPTED],
]);

$this->expectException(CommandException::class);
Expand Down
8 changes: 8 additions & 0 deletions tests/SpecTests/ChangeStreamsSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
*/
class ChangeStreamsSpecTest extends FunctionalTestCase
{
private static $incompleteTests = [
'change-streams-errors: Change Stream should error when _id is projected out' => 'PHPC-1419',
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this test previously passing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test fails on sharded clusters, but for different reasons.

On a sharded cluster backed by standalone servers, $changeStream obviously isn't supported. This causes an exception when trying to run the watch operation from the spec test, but that exception does not contain the NonResumableChangeStreamError (because it's not a change stream error) label, causing the test to fail.
This is caused because the spec requires this test to run on both replicaset and sharded topologies. Unfortunately, the spec does not differentiate between the two types of sharded clusters (backed entirely by replicasets or not), so this is something we may want to address in the specification in the future. However, since the spec test also require testing change streams on a standalone server to ensure an exception is thrown, we can't just skip these tests on unsupported platforms. I may have to hardcode an exception for this one particular test.

On a sharded cluster backed by replica sets, we're seeing the behaviour described in #659 (comment). In a nutshell, the first getMore call does not return any results as mongos hasn't received returnable results from all shards yet. A subsequent getMore would return a document, causing the getMore call to fail with the expected error. Even then, the test still fails because of PHPC-1419: the NonResumableChangeStreamError is not present in the exception.

With that in mind, I'd skip the test for now and properly fix it in #659 where we take care of other change stream tests as well.

FWIW, debugging this issue made me realise that PHPC-1419 only appears on sharded clusters. I'll investigate that further separately to figure out the cause of the bug.


/**
* Assert that the expected and actual command documents match.
*
Expand Down Expand Up @@ -66,6 +70,10 @@ public static function assertResult(array $expectedDocuments, array $actualDocum
*/
public function testChangeStreams(stdClass $test, $databaseName = null, $collectionName = null, $database2Name = null, $collection2Name = null)
{
if (isset(self::$incompleteTests[$this->dataDescription()])) {
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
}

$this->checkServerRequirements($this->createRunOn($test));

if (!isset($databaseName, $collectionName, $database2Name, $collection2Name)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/SpecTests/ErrorExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function assert(TestCase $test, Exception $actual = null)
$test->assertNotNull($actual);

if (isset($this->messageContains)) {
$test->assertContains($this->messageContains, $actual->getMessage(), '', true /* case-insensitive */);
$test->assertStringContainsStringIgnoringCase($this->messageContains, $actual->getMessage());
}

if (isset($this->codeName)) {
Expand Down Expand Up @@ -178,7 +178,7 @@ private function assertCodeName(TestCase $test, Exception $actual = null)
$test->assertInstanceOf(CommandException::class, $actual);
$result = $actual->getResultDocument();
$test->assertObjectHasAttribute('codeName', $result);
$test->assertAttributeSame($this->codeName, 'codeName', $result);
$test->assertSame($this->codeName, $result->codeName);
}

private static function isArrayOfStrings($array)
Expand Down