-
-
Notifications
You must be signed in to change notification settings - Fork 512
Add test on Atlas Search features using an MongoDB Atlas Local Docker #2829
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
Changes from 6 commits
fb5fa0e
c700b12
9c0ca9f
f38d8cd
b807b27
6468e2e
f3bb712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| name: "Atlas CI" | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - "*.x" | ||
| - "feature/*" | ||
| push: | ||
|
|
||
| jobs: | ||
| atlas-local: | ||
| runs-on: "${{ matrix.os }}" | ||
| name: "PHP/${{ matrix.php-version }} Symfony/${{ matrix.symfony }} Proxy/${{ matrix.proxy }}" | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: | ||
| - "ubuntu-latest" | ||
| php-version: | ||
| - "8.2" | ||
| - "8.3" | ||
| - "8.4" | ||
| symfony: | ||
| - "stable" | ||
| - "6.4" | ||
| proxy: | ||
| - "lazy-ghost" | ||
| include: | ||
| # Test with ProxyManager | ||
| - php-version: "8.2" | ||
| symfony: "stable" | ||
| proxy: "proxy-manager" | ||
| os: "ubuntu-latest" | ||
|
|
||
| steps: | ||
| - name: "Checkout" | ||
| uses: "actions/checkout@v5" | ||
| with: | ||
| fetch-depth: 2 | ||
|
|
||
| - name: "Create MongoDB Atlas Local" | ||
| run: | | ||
| docker run --name mongodb -p 27017:27017 --detach mongodb/mongodb-atlas-local:8.2 | ||
| until docker exec --tty mongodb mongosh --eval "db.runCommand({ ping: 1 })"; do | ||
| sleep 1 | ||
| done | ||
| until docker exec --tty mongodb mongosh --eval "db.createCollection('connection_test') && db.getCollection('connection_test').createSearchIndex({mappings:{dynamic: true}})"; do | ||
| sleep 1 | ||
| done | ||
| - name: "Show MongoDB server status" | ||
| run: | | ||
| docker exec --tty mongodb mongosh --eval "db.runCommand({ serverStatus: 1 })" | ||
| - name: Setup cache environment | ||
| id: extcache | ||
| uses: shivammathur/cache-extensions@v1 | ||
| with: | ||
| php-version: ${{ matrix.php-version }} | ||
| extensions: "mongodb, bcmath" | ||
| key: "extcache-v1" | ||
|
|
||
| - name: Cache extensions | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ${{ steps.extcache.outputs.dir }} | ||
| key: ${{ steps.extcache.outputs.key }} | ||
| restore-keys: ${{ steps.extcache.outputs.key }} | ||
|
|
||
| - name: "Install PHP" | ||
| uses: "shivammathur/setup-php@v2" | ||
| with: | ||
| php-version: "${{ matrix.php-version }}" | ||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tools: "pecl" | ||
| extensions: "mongodb, bcmath" | ||
| coverage: "none" | ||
| ini-values: "zend.assertions=1" | ||
|
|
||
| - name: "Show driver information" | ||
| run: "php --ri mongodb" | ||
|
|
||
| # Not used, skip transient dependencies | ||
| - name: "Remove phpbench/phpbench" | ||
| run: composer remove --no-update --dev phpbench/phpbench | ||
|
|
||
| - name: "Configure Symfony ${{ matrix.symfony }}" | ||
| if: "${{ matrix.symfony != 'stable' }}" | ||
| run: | | ||
| composer config minimum-stability dev | ||
| # update symfony deps | ||
| composer require --no-update symfony/console:^${{ matrix.symfony }} | ||
| composer require --no-update symfony/var-dumper:^${{ matrix.symfony }} | ||
| composer require --no-update --dev symfony/cache:^${{ matrix.symfony }} | ||
| - name: "Install dependencies with Composer" | ||
| uses: "ramsey/composer-install@v3" | ||
| with: | ||
| dependency-versions: "highest" | ||
| composer-options: "--prefer-dist" | ||
|
|
||
| - name: "Run PHPUnit with Atlas Local" | ||
| run: "vendor/bin/phpunit" | ||
|
||
| env: | ||
| DOCTRINE_MONGODB_SERVER: "mongodb://127.0.0.1:27017/?directConnection=true" | ||
| USE_LAZY_GHOST_OBJECTS: ${{ matrix.proxy == 'lazy-ghost' && '1' || '0' }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,7 +159,7 @@ jobs: | |
| topology: ${{ matrix.topology }} | ||
|
|
||
| - name: "Run PHPUnit" | ||
| run: "vendor/bin/phpunit" | ||
| run: "vendor/bin/phpunit --exclude-group=atlas" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted that this will skip the tests with |
||
| env: | ||
| DOCTRINE_MONGODB_SERVER: ${{ steps.setup-mongodb.outputs.cluster-uri }} | ||
| USE_LAZY_GHOST_OBJECTS: ${{ matrix.proxy == 'lazy-ghost' && '1' || '0' }}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| mongodb-atlas-local: | ||
| image: mongodb/mongodb-atlas-local | ||
| ports: | ||
| - "27018:27017" |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -473,7 +473,7 @@ | |||||||
|
|
||||||||
| public const VECTOR_SIMILARITY_EUCLIDEAN = 'euclidean'; | ||||||||
| public const VECTOR_SIMILARITY_COSINE = 'cosine'; | ||||||||
| public const VECTOR_SIMILARITY_DOT_PRODUCT = 'dot_product'; | ||||||||
| public const VECTOR_SIMILARITY_DOT_PRODUCT = 'dotProduct'; | ||||||||
|
||||||||
| public const VECTOR_SIMILARITY_DOT_PRODUCT = 'dotProduct'; | |
| public const VECTOR_SIMILARITY_DOT_PRODUCT = 'dotProduct'; | |
| public const VECTOR_SIMILARITY_DOT_PRODUCT_SNAKE_CASE = 'dot_product'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is not released yet. This is a bug fix as dotProduct is the value expected by MongoDB: https://www.mongodb.com/docs/php-library/current/indexes/atlas-search-index/#create-a-search-index
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| use Doctrine\Persistence\Mapping\Driver\MappingDriver; | ||
| use MongoDB\Client; | ||
| use MongoDB\Driver\Command; | ||
| use MongoDB\Driver\Exception\CommandException; | ||
| use MongoDB\Driver\Manager; | ||
| use MongoDB\Driver\Server; | ||
| use MongoDB\Model\DatabaseInfo; | ||
|
|
@@ -45,23 +46,34 @@ abstract class BaseTestCase extends TestCase | |
| protected static bool $allowsTransactions = true; | ||
| protected ?DocumentManager $dm; | ||
| protected UnitOfWork $uow; | ||
| private bool $disableFailPoints = false; | ||
|
|
||
| public function setUp(): void | ||
| protected function setUp(): void | ||
| { | ||
| $this->dm = static::createTestDocumentManager(); | ||
| $this->uow = $this->dm->getUnitOfWork(); | ||
| } | ||
|
|
||
| public function tearDown(): void | ||
| protected function tearDown(): void | ||
| { | ||
| if (! $this->dm) { | ||
| return; | ||
| } | ||
|
|
||
| $client = $this->dm->getClient(); | ||
|
|
||
| // Remove any fail points that may have been set | ||
| if ($this->disableFailPoints) { | ||
| $client->getDatabase('admin')->command([ | ||
| 'configureFailPoint' => 'failCommand', | ||
| 'mode' => 'off', | ||
| ]); | ||
| $this->disableFailPoints = false; | ||
| } | ||
|
|
||
| // Check if the database exists. Calling listCollections on a non-existing | ||
| // database in a sharded setup will cause an invalid command cursor to be | ||
| // returned | ||
| $client = $this->dm->getClient(); | ||
| $databases = iterator_to_array($client->listDatabases()); | ||
| $databaseNames = array_map(static fn (DatabaseInfo $database) => $database->getName(), $databases); | ||
| if (! in_array(DOCTRINE_MONGODB_DATABASE, $databaseNames)) { | ||
|
|
@@ -294,4 +306,28 @@ private static function detectTransactionSupport(): bool | |
|
|
||
| return $manager->selectServer()->getType() !== Server::TYPE_STANDALONE; | ||
| } | ||
|
|
||
| protected function createFailPoint(string $failCommand, bool $transient = false, int $times = 1): void | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it was adapted from what we have in PHPLIB, although this method is only useful for the Just wanted to confirm that this is perfectly suitable for ODM's present needs. In the future, you may want to make this more consistent with PHPLIB's implementation, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot about the PHPLIB implementation, this is definitely a simpler approach as we only need to add 1 fail point at a time. |
||
| { | ||
| try { | ||
| $this->dm->getClient()->getManager()->executeCommand( | ||
| 'admin', | ||
| new Command([ | ||
| 'configureFailPoint' => 'failCommand', | ||
| 'mode' => ['times' => $times], | ||
| 'data' => [ | ||
| 'errorCode' => 192, // FailPointEnabled | ||
| 'errorLabels' => $transient ? ['TransientTransactionError'] : [], | ||
| 'failCommands' => [$failCommand], | ||
| ], | ||
| ]), | ||
| ); | ||
| $this->disableFailPoints = true; | ||
| } catch (CommandException $exception) { | ||
| // no such command: 'configureFailPoint' | ||
| if ($exception->getCode() === 59) { | ||
| self::markTestSkipped('Test skipped because the server does not support fail points'); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.