Skip to content

Commit 5770267

Browse files
authored
Run tests with MongoDB 8.0 replica set (#2798)
* Run tests with MongoDB 8.0 replica set * Wait for replication to catch up if the read preference is not PRIMARY * Disable transactions for TimeSeriesTest Cannot insert into a time-series collection in a multi-document transaction: doctrine_odm_tests.TimeSeriesDocument
1 parent dcfc75b commit 5770267

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ jobs:
6262
dependencies: "highest"
6363
symfony-version: "stable"
6464
proxy: "lazy-ghost"
65+
# Test with a 8.0 replica set
66+
- topology: "replica_set"
67+
php-version: "8.2"
68+
mongodb-version: "8.0"
69+
driver-version: "stable"
70+
dependencies: "highest"
71+
symfony-version: "stable"
72+
proxy: "lazy-ghost"
6573
# Test with ProxyManager
6674
- php-version: "8.2"
6775
mongodb-version: "6.0"

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use MongoDB\Driver\WriteConcern;
1515
use PHPUnit\Framework\Attributes\DataProvider;
1616

17+
use function usleep;
18+
1719
/** @phpstan-type ReadPreferenceTagShape array{dc?: string, usage?: string} */
1820
class ReadPreferenceTest extends BaseTestCase
1921
{
@@ -57,7 +59,13 @@ public function testHintIsSetOnQuery(string $readPreference, array $tags = []):
5759

5860
$this->assertReadPreferenceHint($readPreference, $query->getQuery()['readPreference'], $tags);
5961

60-
$user = $query->getSingleResult();
62+
$retries = 0;
63+
do {
64+
// Wait a bit to ensure replication has caught up.
65+
usleep(1_000 * $retries);
66+
$user = $query->getSingleResult();
67+
} while ($user === null && $retries++ < 100);
68+
6169
self::assertInstanceOf(User::class, $user);
6270

6371
$groups = $user->getGroups();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testCreateTimeSeriesDocumentWithoutId(): void
4141
$document->metadata = 'energy';
4242

4343
$this->dm->persist($document);
44-
$this->dm->flush();
44+
$this->dm->flush(['withTransaction' => false]);
4545

4646
$this->assertCount(1, $this->dm->getDocumentCollection(TimeSeriesDocument::class)->find());
4747
}
@@ -57,7 +57,7 @@ public function testCreateTimeSeriesDocumentWithId(): void
5757
$document->metadata = 'energy';
5858

5959
$this->dm->persist($document);
60-
$this->dm->flush();
60+
$this->dm->flush(['withTransaction' => false]);
6161

6262
$this->assertCount(1, $this->dm->getDocumentCollection(TimeSeriesDocument::class)->find());
6363
}

0 commit comments

Comments
 (0)