Skip to content

Commit

Permalink
Run tests on sharded clusters (#2272)
Browse files Browse the repository at this point in the history
* Run tests on sharded clusters

* Skip secondary read preference test on sharded clusters

* Remove unnecessary command result checks
  • Loading branch information
alcaeus authored Jan 19, 2021
1 parent 81fe43d commit fa967ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
32 changes: 21 additions & 11 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ env:
fail-fast: true

jobs:
phpunit-standalone:
name: "PHPUnit on standalone servers"
phpunit:
name: "PHPUnit"
runs-on: "${{ matrix.os }}"

strategy:
matrix:
os:
- "ubuntu-20.04"
- "ubuntu-18.04"
php-version:
- "7.2"
- "7.3"
Expand All @@ -28,23 +28,25 @@ jobs:
- "4.4"
- "4.2"
- "4.0"
- "3.6"
driver-version:
- "stable"
topology:
- "server"
deps:
- "normal"
include:
- deps: "low"
os: "ubuntu-20.04"
os: "ubuntu-16.04"
php-version: "7.2"
mongodb-version: "3.6"
driver-version: "1.5.0"

services:
mongodb:
image: "mongo:${{ matrix.mongodb-version }}"
ports:
- "27017:27017"
topology: "server"
- topology: "sharded_cluster"
os: "ubuntu-18.04"
php-version: "8.0"
mongodb-version: "4.4"
driver-version: "stable"
deps: "normal"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -94,5 +96,13 @@ jobs:
run: "composer update --no-interaction --no-progress --prefer-dist --prefer-lowest"
if: "${{ matrix.deps == 'low' }}"

- id: setup-mongodb
uses: mongodb-labs/drivers-evergreen-tools@master
with:
version: ${{ matrix.mongodb-version }}
topology: ${{ matrix.topology }}

- name: "Run PHPUnit"
run: "vendor/bin/phpunit"
env:
DOCTRINE_MONGODB_SERVER: ${{ steps.setup-mongodb.outputs.cluster-uri }}
14 changes: 11 additions & 3 deletions tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ protected function getServerVersion()
protected function skipTestIfNotSharded($className)
{
$result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true])->toArray()[0];
if (! $result['ok']) {
$this->markTestSkipped('Could not check whether server supports sharding');
}

if (array_key_exists('shardCollection', $result['commands'])) {
return;
Expand All @@ -144,6 +141,17 @@ protected function skipTestIfNotSharded($className)
$this->markTestSkipped('Test skipped because server does not support sharding');
}

protected function skipTestIfSharded($className)
{
$result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true])->toArray()[0];

if (! array_key_exists('shardCollection', $result['commands'])) {
return;
}

$this->markTestSkipped('Test does not apply on sharded clusters');
}

protected function requireVersion($installedVersion, $requiredVersion, $operator, $message)
{
if (! version_compare($installedVersion, $requiredVersion, $operator)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function testHintIsNotSetByDefault()
*/
public function testHintIsSetOnQuery($readPreference, array $tags = [])
{
$this->skipTestIfSharded(User::class);

$query = $this->dm->getRepository(User::class)
->createQueryBuilder()
->setReadPreference(new ReadPreference($readPreference, $tags))
Expand Down

0 comments on commit fa967ea

Please sign in to comment.