Skip to content

PHPLIB-617 Continuous Matrix Testing for 4.0 era drivers #810

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 11 commits into from
Feb 19, 2021
1 change: 1 addition & 0 deletions .evergreen/config/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension=mongodb.so
132 changes: 132 additions & 0 deletions .evergreen/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/bin/sh
set -o errexit # Exit the script with error if any of the commands fail

set_php_version ()
{
PHP_VERSION=$1

if [ ! -d "/opt/php" ]; then
echo "PHP is not available"
exit 1
fi

if [ -d "/opt/php/${PHP_VERSION}-64bit/bin" ]; then
export PHP_PATH="/opt/php/${PHP_VERSION}-64bit/bin"
else
# Try to find the newest version matching our constant
export PHP_PATH=`find /opt/php/ -maxdepth 1 -type d -name "${PHP_VERSION}.*-64bit" -print | sort -V -r | head -1`
fi

if [ ! -d "$PHP_PATH" ]; then
echo "Could not find PHP binaries for version ${PHP_VERSION}. Listing available versions..."
ls -1 /opt/php
exit 1
fi

export PATH=$PHP_PATH/bin:$PATH
}

install_extension ()
{
# Workaround to get PECL running on PHP 7.0
# export PHP_PEAR_PHP_BIN=${PHP_PATH}/bin/php
# export PHP_PEAR_INSTALL_DIR=${PHP_PATH}/bin/php

rm -f ${PHP_PATH}/lib/php.ini

if [ "x${EXTENSION_BRANCH}" != "x" ] || [ "x${EXTENSION_REPO}" != "x" ]; then
CLONE_REPO=${EXTENSION_REPO:-https://github.com/mongodb/mongo-php-driver}
CHECKOUT_BRANCH=${EXTENSION_BRANCH:-master}

echo "Compiling driver branch ${CHECKOUT_BRANCH} from repository ${CLONE_REPO}"

mkdir -p /tmp/compile
rm -rf /tmp/compile/mongo-php-driver
git clone ${CLONE_REPO} /tmp/compile/mongo-php-driver
cd /tmp/compile/mongo-php-driver

git checkout ${CHECKOUT_BRANCH}
git submodule update --init
phpize
./configure --enable-mongodb-developer-flags
make all -j20 > /dev/null
make install

cd ${PROJECT_DIRECTORY}
elif [ "x${EXTENSION_VERSION}" != "x" ]; then
echo "Installing driver version ${EXTENSION_VERSION} from PECL"
pecl install -f mongodb-${EXTENSION_VERSION}
else
echo "Installing latest driver version from PECL"
pecl install -f mongodb
fi

sudo cp ${PROJECT_DIRECTORY}/.evergreen/config/php.ini ${PHP_PATH}/lib/php.ini

php --ri mongodb
}

install_composer ()
{
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi

php composer-setup.php --quiet
rm composer-setup.php
}

# Functions to fetch MongoDB binaries
. ${DRIVERS_TOOLS}/.evergreen/download-mongodb.sh
OS=$(uname -s | tr '[:upper:]' '[:lower:]')

get_distro

case "$DISTRO" in
cygwin*)
echo "Install Windows dependencies"
;;

darwin*)
echo "Install macOS dependencies"
;;

linux-rhel*)
echo "Install RHEL dependencies"
;;

linux-ubuntu*)
echo "Install Ubuntu dependencies"
sudo apt-get install -y awscli || true
;;

sunos*)
echo "Install Solaris dependencies"
sudo /opt/csw/bin/pkgutil -y -i sasl_dev || true
;;

*)
echo "All other platforms..."
;;
esac

case "$DEPENDENCIES" in
lowest*)
COMPOSER_FLAGS="${COMPOSER_FLAGS} --prefer-lowest"
;;

*)
;;
esac

set_php_version $PHP_VERSION
install_extension
install_composer

php composer.phar update $COMPOSER_FLAGS
59 changes: 59 additions & 0 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh
set -o errexit # Exit the script with error if any of the commands fail

# Supported/used environment variables:
# AUTH Set to enable authentication. Defaults to "noauth"
# SSL Set to enable SSL. Defaults to "nossl"
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
# MARCH Machine Architecture. Defaults to lowercase uname -m


AUTH=${AUTH:-noauth}
SSL=${SSL:-nossl}
MONGODB_URI=${MONGODB_URI:-}
TESTS=${TESTS:-}
IS_MATRIX_TESTING=${IS_MATRIX_TESTING:-false}

# For matrix testing, we have to determine the correct driver version
if [ "$IS_MATRIX_TESTING" == "true" ]; then
case "${DRIVER_MONGODB_VERSION}" in
'4.4')
export EXTENSION_VERSION='1.8.2'
;;
'4.2')
export EXTENSION_VERSION='1.6.1'
;;
'4.0')
export EXTENSION_VERSION='1.5.5'
;;
esac

case "${MONGODB_VERSION}" in
latest)
MONGODB_VERSION_NUMBER='5.0'
;;
*)
MONGODB_VERSION_NUMBER=$MONGODB_VERSION
;;
esac

PHPUNIT_OPTS="--dont-report-useless-tests --exclude-group matrix-testing-server-${MONGODB_VERSION_NUMBER}-driver-${DRIVER_MONGODB_VERSION},matrix-testing-server-${MONGODB_VERSION_NUMBER}-driver-${DRIVER_MONGODB_VERSION}-topology-${TOPOLOGY}"
Copy link
Member

Choose a reason for hiding this comment

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

Very nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, not happy about the formatting, but your suggestion to use groups to skip tests was great.


DIR=$(dirname $0)
. $DIR/install-dependencies.sh
fi

OS=$(uname -s | tr '[:upper:]' '[:lower:]')
[ -z "$MARCH" ] && MARCH=$(uname -m | tr '[:upper:]' '[:lower:]')

echo "Running tests with $AUTH and $SSL, connecting to: $MONGODB_URI"

# Disable failing PHPUnit due to deprecations
export SYMFONY_DEPRECATIONS_HELPER=999999

# Run the tests, and store the results in a Evergreen compatible JSON results file
case "$TESTS" in
*)
php vendor/bin/phpunit --configuration phpunit.evergreen.xml $PHPUNIT_OPTS
;;
esac
32 changes: 32 additions & 0 deletions phpunit.evergreen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>

<php>
<ini name="error_reporting" value="-1"/>
<env name="MONGODB_URI" value="mongodb://127.0.0.1:27017/?serverSelectionTimeoutMS=100"/>
<env name="MONGODB_DATABASE" value="phplib_test"/>
</php>

<testsuites>
<testsuite name="Default Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<logging>
<log type="junit" target="test-results.xml" />
</logging>
</phpunit>
4 changes: 4 additions & 0 deletions tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ public function testWithOptionsPassesOptions()
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
}

/**
* @group matrix-testing-server-4.4-driver-4.0
* @group matrix-testing-server-5.0-driver-4.0
*/
public function testMapReduce()
{
$this->createFixtures(3);
Expand Down
2 changes: 2 additions & 0 deletions tests/Collection/CrudSpecFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* CRUD spec functional tests.
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*
* @group matrix-testing-server-5.0-driver-4.0
*/
class CrudSpecFunctionalTest extends FunctionalTestCase
{
Expand Down
5 changes: 5 additions & 0 deletions tests/Database/DatabaseFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ public function testGetSelectsCollectionAndInheritsOptions()
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
}

/**
* @group matrix-testing-server-4.2-driver-4.0-topology-sharded_cluster
* @group matrix-testing-server-4.4-driver-4.0-topology-sharded_cluster
* @group matrix-testing-server-5.0-driver-4.0-topology-sharded_cluster
*/
public function testModifyCollection()
{
$this->database->createCollection($this->getCollectionName());
Expand Down
1 change: 1 addition & 0 deletions tests/DocumentationExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ public function testExample_55_58()
$this->assertInventoryCount(0);
}

/** @group matrix-testing-server-5.0-driver-4.0-topology-sharded_cluster */
public function testChangeStreamExample_1_4()
{
if ($this->getPrimaryServer()->getType() === Server::TYPE_STANDALONE) {
Expand Down
9 changes: 9 additions & 0 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ protected function assertSameObjectId($expectedObjectId, $actualObjectId)

protected function getFeatureCompatibilityVersion(ReadPreference $readPreference = null)
{
if ($this->isShardedCluster()) {
return $this->getServerVersion($readPreference);
}

Copy link
Member

Choose a reason for hiding this comment

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

Backport? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Fixed a number of tests 😉

if (version_compare($this->getServerVersion(), '3.4.0', '<')) {
return $this->getServerVersion($readPreference);
}
Expand Down Expand Up @@ -133,4 +137,9 @@ protected function skipIfTransactionsAreNotSupported()
$this->markTestSkipped('Transactions require WiredTiger storage engine');
}
}

protected function isShardedCluster()
{
return $this->getPrimaryServer()->getType() == Server::TYPE_MONGOS;
}
}
1 change: 1 addition & 0 deletions tests/Model/IndexInfoFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function testIs2dSphere()
$this->assertEquals($expectedVersion, $index['2dsphereIndexVersion']);
}

/** @group matrix-testing-server-5.0-driver-4.0 */
public function testIsGeoHaystack()
{
$indexName = $this->collection->createIndex(['pos' => 'geoHaystack', 'x' => 1], ['bucketSize' => 5]);
Expand Down
20 changes: 18 additions & 2 deletions tests/Operation/AggregateFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ public function testExplainOption()
$results = iterator_to_array($operation->execute($this->getPrimaryServer()));

$this->assertCount(1, $results);
$this->assertArrayHasKey('stages', $results[0]);

/* MongoDB 4.2 may optimize aggregate pipelines into queries, which can
* result in different explain output (see: SERVER-24860) */
$this->assertThat($results[0], $this->logicalOr(
$this->arrayHasKey('stages'),
$this->arrayHasKey('queryPlanner')
));
}

public function testExplainOptionWithWriteConcern()
Expand All @@ -183,7 +189,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);

/* MongoDB 4.2 may optimize aggregate pipelines into queries, which can
* result in different explain output (see: SERVER-24860) */
if (isset($result->shards)) {
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
4 changes: 4 additions & 0 deletions tests/Operation/ListCollectionsFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function testListCollectionsForNewlyCreatedDatabase()
}
}

/**
* @group matrix-testing-server-4.4-driver-4.0
* @group matrix-testing-server-5.0-driver-4.0
*/
public function testIdIndexAndInfo()
{
if (version_compare($this->getServerVersion(), '3.4.0', '<')) {
Expand Down
4 changes: 4 additions & 0 deletions tests/Operation/MapReduceFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use MongoDB\Tests\CommandObserver;
use stdClass;

/**
* @group matrix-testing-server-4.4-driver-4.0
* @group matrix-testing-server-5.0-driver-4.0
*/
class MapReduceFunctionalTest extends FunctionalTestCase
{
public function testDefaultReadConcernIsOmitted()
Expand Down
5 changes: 5 additions & 0 deletions tests/Operation/ModifyCollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

class ModifyCollectionFunctionalTest extends FunctionalTestCase
{
/**
* @group matrix-testing-server-4.2-driver-4.0-topology-sharded_cluster
* @group matrix-testing-server-4.4-driver-4.0-topology-sharded_cluster
* @group matrix-testing-server-5.0-driver-4.0-topology-sharded_cluster
*/
public function testCollMod()
{
$operation = new CreateCollection($this->getDatabaseName(), $this->getCollectionName());
Expand Down
Loading