Skip to content

Commit fa967ea

Browse files
authored
Run tests on sharded clusters (#2272)
* Run tests on sharded clusters * Skip secondary read preference test on sharded clusters * Remove unnecessary command result checks
1 parent 81fe43d commit fa967ea

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ env:
1111
fail-fast: true
1212

1313
jobs:
14-
phpunit-standalone:
15-
name: "PHPUnit on standalone servers"
14+
phpunit:
15+
name: "PHPUnit"
1616
runs-on: "${{ matrix.os }}"
1717

1818
strategy:
1919
matrix:
2020
os:
21-
- "ubuntu-20.04"
21+
- "ubuntu-18.04"
2222
php-version:
2323
- "7.2"
2424
- "7.3"
@@ -28,23 +28,25 @@ jobs:
2828
- "4.4"
2929
- "4.2"
3030
- "4.0"
31-
- "3.6"
3231
driver-version:
3332
- "stable"
33+
topology:
34+
- "server"
3435
deps:
3536
- "normal"
3637
include:
3738
- deps: "low"
38-
os: "ubuntu-20.04"
39+
os: "ubuntu-16.04"
3940
php-version: "7.2"
4041
mongodb-version: "3.6"
4142
driver-version: "1.5.0"
42-
43-
services:
44-
mongodb:
45-
image: "mongo:${{ matrix.mongodb-version }}"
46-
ports:
47-
- "27017:27017"
43+
topology: "server"
44+
- topology: "sharded_cluster"
45+
os: "ubuntu-18.04"
46+
php-version: "8.0"
47+
mongodb-version: "4.4"
48+
driver-version: "stable"
49+
deps: "normal"
4850

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

99+
- id: setup-mongodb
100+
uses: mongodb-labs/drivers-evergreen-tools@master
101+
with:
102+
version: ${{ matrix.mongodb-version }}
103+
topology: ${{ matrix.topology }}
104+
97105
- name: "Run PHPUnit"
98106
run: "vendor/bin/phpunit"
107+
env:
108+
DOCTRINE_MONGODB_SERVER: ${{ steps.setup-mongodb.outputs.cluster-uri }}

tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ protected function getServerVersion()
133133
protected function skipTestIfNotSharded($className)
134134
{
135135
$result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true])->toArray()[0];
136-
if (! $result['ok']) {
137-
$this->markTestSkipped('Could not check whether server supports sharding');
138-
}
139136

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

144+
protected function skipTestIfSharded($className)
145+
{
146+
$result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true])->toArray()[0];
147+
148+
if (! array_key_exists('shardCollection', $result['commands'])) {
149+
return;
150+
}
151+
152+
$this->markTestSkipped('Test does not apply on sharded clusters');
153+
}
154+
147155
protected function requireVersion($installedVersion, $requiredVersion, $operator, $message)
148156
{
149157
if (! version_compare($installedVersion, $requiredVersion, $operator)) {

tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function testHintIsNotSetByDefault()
4646
*/
4747
public function testHintIsSetOnQuery($readPreference, array $tags = [])
4848
{
49+
$this->skipTestIfSharded(User::class);
50+
4951
$query = $this->dm->getRepository(User::class)
5052
->createQueryBuilder()
5153
->setReadPreference(new ReadPreference($readPreference, $tags))

0 commit comments

Comments
 (0)