Skip to content

Commit c4302b9

Browse files
committed
PHPLIB-671: Load balancer testing
Add load balancer task to Evergreen. This cleans up some unused variables in run-tests.sh and copies over SSL URI handling from PHPC (needed since LB appears to be the first task using SSL). Sync all spec tests. Synced with mongodb/specifications@b508f6d Added skips for some CSFLE and command monitoring tests, which replaces a previous manual edit to azureKMS.json. Various test suite fixes for load balancers and/or sharded clusters.
1 parent 7ed839a commit c4302b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4647
-697
lines changed

.evergreen/config.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ functions:
246246
export GCP_EMAIL="${client_side_encryption_gcp_email}"
247247
export GCP_PRIVATEKEY="${client_side_encryption_gcp_privatekey}"
248248
export PATH="${PHP_PATH}/bin:$PATH"
249-
API_VERSION=${API_VERSION} PHP_VERSION=${PHP_VERSION} AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
249+
MOCK_SERVICE_ID=${MOCK_SERVICE_ID} API_VERSION=${API_VERSION} PHP_VERSION=${PHP_VERSION} AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
250250
251251
"run atlas data lake test":
252252
- command: shell.exec
@@ -323,6 +323,24 @@ functions:
323323
params:
324324
file: src/php-expansion.yml
325325

326+
"start load balancer":
327+
- command: shell.exec
328+
params:
329+
script: |
330+
MONGODB_URI="${MONGODB_URI}" ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh start
331+
- command: expansions.update
332+
params:
333+
file: lb-expansion.yml
334+
335+
"stop load balancer":
336+
- command: shell.exec
337+
params:
338+
script: |
339+
# Only run if a load balancer was started
340+
if [ -n "${SINGLE_MONGOS_LB_URI}" ]; then
341+
${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh stop
342+
fi
343+
326344
pre:
327345
- func: "fetch source"
328346
- func: "prepare resources"
@@ -336,6 +354,7 @@ post:
336354
# - func: "upload working dir"
337355
- func: "upload mo artifacts"
338356
- func: "upload test results"
357+
- func: "stop load balancer"
339358
- func: "stop mongo-orchestration"
340359
- func: "cleanup"
341360

@@ -432,6 +451,23 @@ tasks:
432451
PROJECT: "mongo-php-library"
433452
- func: "run serverless tests"
434453
- func: "delete serverless instance"
454+
455+
- name: "test-loadBalanced"
456+
tags: ["loadbalanced"]
457+
commands:
458+
- func: "bootstrap mongo-orchestration"
459+
vars:
460+
TOPOLOGY: "sharded_cluster"
461+
SSL: "yes"
462+
- func: "start load balancer"
463+
- func: "run tests"
464+
vars:
465+
# Testing with HAProxy requires service ID mocking
466+
MOCK_SERVICE_ID: 1
467+
# Note: loadBalanced=true should already be appended to SINGLE_MONGOS_LB_URI
468+
MONGODB_URI: "${SINGLE_MONGOS_LB_URI}"
469+
SSL: "yes"
470+
# Note: "stop load balancer" will be called from "post"
435471
# }}}
436472

437473

@@ -693,3 +729,9 @@ buildvariants:
693729
run_on: rhel70
694730
tasks:
695731
- .serverless
732+
733+
- matrix_name: "test-loadBalanced"
734+
matrix_spec: { "os-php7": "debian92-test", "php-versions": "7.3", "versions": ["5.0", "latest"], "driver-versions": "latest-dev" }
735+
display_name: "Load balanced - ${versions}"
736+
tasks:
737+
- name: "test-loadBalanced"

.evergreen/run-tests.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
set -o errexit # Exit the script with error if any of the commands fail
33

44
# Supported/used environment variables:
5-
# AUTH Set to enable authentication. Defaults to "noauth"
6-
# SSL Set to enable SSL. Defaults to "nossl"
7-
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
8-
# MARCH Machine Architecture. Defaults to lowercase uname -m
5+
# SSL Set to "yes" to enable SSL. Defaults to "nossl"
6+
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
7+
# API_VERSION Optional API_VERSION environment variable for run-tests.php
8+
# IS_MATRIX_TESTING Set to "true" to enable matrix testing. Defaults to empty string. If "true", DRIVER_MONGODB_VERSION and MONGODB_VERSION will also be checked.
9+
# MOCK_SERVICE_ID Set to "1" to enable service ID mocking for load balancers. Defaults to empty string.
910

10-
11-
AUTH=${AUTH:-noauth}
1211
SSL=${SSL:-nossl}
1312
MONGODB_URI=${MONGODB_URI:-}
14-
TESTS=${TESTS:-}
1513
API_VERSION=${API_VERSION:-}
1614
IS_MATRIX_TESTING=${IS_MATRIX_TESTING:-}
15+
MOCK_SERVICE_ID=${MOCK_SERVICE_ID:-}
1716

1817
# For matrix testing, we have to determine the correct driver version
1918
if [ "${IS_MATRIX_TESTING}" = "true" ]; then
@@ -44,10 +43,23 @@ if [ "${IS_MATRIX_TESTING}" = "true" ]; then
4443
. $DIR/install-dependencies.sh
4544
fi
4645

47-
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
48-
[ -z "$MARCH" ] && MARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
46+
# For load balancer testing, we need to enable service ID mocking
47+
if [ "${MOCK_SERVICE_ID}" = "1" ]; then
48+
PHPUNIT_OPTS="${PHPUNIT_OPTS} -d mongodb.mock_service_id=1"
49+
fi
50+
51+
# Determine if MONGODB_URI already has a query string
52+
SUFFIX=$(echo "$MONGODB_URI" | grep -Eo "\?(.*)" | cat)
53+
54+
if [ "$SSL" = "yes" ]; then
55+
if [ -z "$SUFFIX" ]; then
56+
MONGODB_URI="${MONGODB_URI}/?ssl=true&sslallowinvalidcertificates=true"
57+
else
58+
MONGODB_URI="${MONGODB_URI}&ssl=true&sslallowinvalidcertificates=true"
59+
fi
60+
fi
4961

50-
echo "Running tests with $AUTH and $SSL, connecting to: $MONGODB_URI"
62+
echo "Running tests with URI: $MONGODB_URI"
5163

5264
# Disable failing PHPUnit due to deprecations
5365
export SYMFONY_DEPRECATIONS_HELPER=999999

tests/Collection/CollectionFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ public function testRenameToDifferentDatabase(): void
356356
$toDatabase = new Database($this->manager, $toDatabaseName);
357357

358358
/* When renaming an unsharded collection, mongos requires the source
359-
* and target database to both exist on the primary shard. In practice, this
360-
* means we need to create the target database explicitly.
359+
* and target database to both exist on the primary shard. In practice,
360+
* this means we need to create the target database explicitly.
361361
* See: https://docs.mongodb.com/manual/reference/command/renameCollection/#unsharded-collections
362362
*/
363363
if ($this->isShardedCluster()) {

tests/FunctionalTestCase.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,21 @@ protected function getServerStorageEngine(?ReadPreference $readPreference = null
390390
throw new UnexpectedValueException('Could not determine server storage engine');
391391
}
392392

393+
protected function isLoadBalanced()
394+
{
395+
return $this->getPrimaryServer()->getType() == Server::TYPE_LOAD_BALANCER;
396+
}
397+
393398
protected function isReplicaSet()
394399
{
395400
return $this->getPrimaryServer()->getType() == Server::TYPE_RS_PRIMARY;
396401
}
397402

403+
protected function isMongos()
404+
{
405+
return $this->getPrimaryServer()->getType() == Server::TYPE_MONGOS;
406+
}
407+
398408
/**
399409
* Return whether serverless (i.e. proxy as mongos) is being utilized.
400410
*/
@@ -407,7 +417,18 @@ protected static function isServerless(): bool
407417

408418
protected function isShardedCluster()
409419
{
410-
return $this->getPrimaryServer()->getType() == Server::TYPE_MONGOS;
420+
$type = $this->getPrimaryServer()->getType();
421+
422+
if ($type == Server::TYPE_MONGOS) {
423+
return true;
424+
}
425+
426+
// Assume that load balancers are properly configured and front mongos
427+
if ($type == Server::TYPE_LOAD_BALANCER) {
428+
return true;
429+
}
430+
431+
return false;
411432
}
412433

413434
protected function isShardedClusterUsingReplicasets()
@@ -436,6 +457,7 @@ protected function skipIfChangeStreamIsNotSupported(): void
436457
{
437458
switch ($this->getPrimaryServer()->getType()) {
438459
case Server::TYPE_MONGOS:
460+
case Server::TYPE_LOAD_BALANCER:
439461
if (version_compare($this->getServerVersion(), '3.6.0', '<')) {
440462
$this->markTestSkipped('$changeStream is only supported on MongoDB 3.6 or higher');
441463
}
@@ -462,6 +484,7 @@ protected function skipIfCausalConsistencyIsNotSupported(): void
462484
{
463485
switch ($this->getPrimaryServer()->getType()) {
464486
case Server::TYPE_MONGOS:
487+
case Server::TYPE_LOAD_BALANCER:
465488
if (version_compare($this->getServerVersion(), '3.6.0', '<')) {
466489
$this->markTestSkipped('Causal Consistency is only supported on MongoDB 3.6 or higher');
467490
}

tests/Operation/RenameCollectionFunctionalTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ public function testRenameCollectionExistingTarget(): void
106106
$this->assertEquals(1, $writeResult->getInsertedCount());
107107

108108
$this->expectException(CommandException::class);
109-
$this->expectExceptionCode(self::$errorCodeNamespaceExists);
109+
110+
// mongos returns an inconsistent error code (see: SERVER-60632)
111+
if (! $this->isShardedCluster()) {
112+
$this->expectExceptionCode(self::$errorCodeNamespaceExists);
113+
}
114+
110115
$operation = new RenameCollection(
111116
$this->getDatabaseName(),
112117
$this->getCollectionName(),

tests/Operation/WatchFunctionalTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,10 @@ function (array $event) use (&$sessionAfterResume, &$commands): void {
11781178

11791179
public function testSessionFreed(): void
11801180
{
1181+
if ($this->isShardedCluster() && version_compare($this->getServerVersion(), '5.1.0', '>=')) {
1182+
$this->markTestSkipped('mongos still reports non-zero cursor ID for invalidated change stream (SERVER-60764)');
1183+
}
1184+
11811185
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
11821186
$changeStream = $operation->execute($this->getPrimaryServer());
11831187

tests/SpecTests/ClientSideEncryptionSpecTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ class ClientSideEncryptionSpecTest extends FunctionalTestCase
4242
{
4343
public const LOCAL_MASTERKEY = 'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk';
4444

45+
/** @var array */
46+
private static $incompleteTests = [
47+
'awsTemporary: Insert a document with auto encryption using the AWS provider with temporary credentials' => 'Not yet implemented (PHPC-1751)',
48+
'awsTemporary: Insert with invalid temporary credentials' => 'Not yet implemented (PHPC-1751)',
49+
'azureKMS: Insert a document with auto encryption using Azure KMS provider' => 'RHEL platform is missing Azure root certificate (PHPLIB-619)',
50+
];
51+
4552
public function setUp(): void
4653
{
4754
parent::setUp();
@@ -74,6 +81,10 @@ public static function assertCommandMatches(stdClass $expected, stdClass $actual
7481
*/
7582
public function testClientSideEncryption(stdClass $test, ?array $runOn = null, array $data, ?array $keyVaultData = null, $jsonSchema = null, ?string $databaseName = null, ?string $collectionName = null): void
7683
{
84+
if (isset(self::$incompleteTests[$this->dataDescription()])) {
85+
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
86+
}
87+
7788
if (isset($runOn)) {
7889
$this->checkServerRequirements($runOn);
7990
}

tests/SpecTests/FunctionalTestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class FunctionalTestCase extends BaseFunctionalTestCase
2929
public const TOPOLOGY_SINGLE = 'single';
3030
public const TOPOLOGY_REPLICASET = 'replicaset';
3131
public const TOPOLOGY_SHARDED = 'sharded';
32+
public const TOPOLOGY_LOAD_BALANCED = 'load-balanced';
3233

3334
public const SERVERLESS_ALLOW = 'allow';
3435
public const SERVERLESS_FORBID = 'forbid';
@@ -265,6 +266,7 @@ private function getTopology(): string
265266
Server::TYPE_STANDALONE => self::TOPOLOGY_SINGLE,
266267
Server::TYPE_RS_PRIMARY => self::TOPOLOGY_REPLICASET,
267268
Server::TYPE_MONGOS => self::TOPOLOGY_SHARDED,
269+
Server::TYPE_LOAD_BALANCER => self::TOPOLOGY_LOAD_BALANCED,
268270
];
269271

270272
$primaryType = $this->getPrimaryServer()->getType();
@@ -273,7 +275,7 @@ private function getTopology(): string
273275
return $topologyTypeMap[$primaryType];
274276
}
275277

276-
throw new UnexpectedValueException(sprintf('Cannot find topology for primary of type "%s".', $primaryType));
278+
throw new UnexpectedValueException(sprintf('Cannot find topology for primary of type "%d".', $primaryType));
277279
}
278280

279281
private function isServerlessRequirementSatisfied(?string $serverlessMode): bool

tests/SpecTests/RetryableWritesSpecTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testRetryableWrites(stdClass $test, ?array $runOn = null, array
3030
$this->markTestSkipped('Transaction numbers are only allowed on a replica set member or mongos (PHPC-1415)');
3131
}
3232

33-
$useMultipleMongoses = isset($test->useMultipleMongoses) && $test->useMultipleMongoses && $this->isShardedCluster();
33+
$useMultipleMongoses = isset($test->useMultipleMongoses) && $test->useMultipleMongoses && $this->isMongos();
3434

3535
if (isset($runOn)) {
3636
$this->checkServerRequirements($runOn);

tests/SpecTests/TransactionsSpecTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private function runTransactionTest(stdClass $test, ?array $runOn = null, array
152152
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
153153
}
154154

155-
$useMultipleMongoses = isset($test->useMultipleMongoses) && $test->useMultipleMongoses && $this->isShardedCluster();
155+
$useMultipleMongoses = isset($test->useMultipleMongoses) && $test->useMultipleMongoses && $this->isMongos();
156156

157157
if (isset($runOn)) {
158158
$this->checkServerRequirements($runOn);
@@ -229,8 +229,10 @@ private function provideTests(string $dir): array
229229
*/
230230
public function testStartingNewTransactionOnPinnedSessionUnpinsSession(): void
231231
{
232-
if (! $this->isShardedClusterUsingReplicasets()) {
233-
$this->markTestSkipped('Mongos pinning tests can only run on sharded clusters using replica sets');
232+
$this->skipIfTransactionsAreNotSupported();
233+
234+
if (! $this->isMongos()) {
235+
$this->markTestSkipped('Pinning tests require mongos');
234236
}
235237

236238
$client = self::createTestClient($this->getUri(true));
@@ -267,8 +269,10 @@ public function testStartingNewTransactionOnPinnedSessionUnpinsSession(): void
267269
*/
268270
public function testRunningNonTransactionOperationOnPinnedSessionUnpinsSession(): void
269271
{
270-
if (! $this->isShardedClusterUsingReplicasets()) {
271-
$this->markTestSkipped('Mongos pinning tests can only run on sharded clusters using replica sets');
272+
$this->skipIfTransactionsAreNotSupported();
273+
274+
if (! $this->isMongos()) {
275+
$this->markTestSkipped('Pinning tests require mongos');
272276
}
273277

274278
$client = self::createTestClient($this->getUri(true));

tests/SpecTests/atlas_data_lake/getMore.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
]
5555
}
5656
]
57-
}
57+
}

tests/SpecTests/atlas_data_lake/listCollections.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
]
2323
}
2424
]
25-
}
25+
}

tests/SpecTests/atlas_data_lake/listDatabases.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
]
2222
}
2323
]
24-
}
24+
}

tests/SpecTests/atlas_data_lake/runCommand.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
]
2929
}
3030
]
31-
}
31+
}

0 commit comments

Comments
 (0)