Skip to content

Fix tests for MongoDB 7.0 #2579

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

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ jobs:
os:
- ubuntu-latest
mongodb:
- '4.0'
- '4.2'
- '4.4'
- '5.0'
- '6.0'
- '7.0'
php:
- '8.1'
- '8.2'
services:
mysql:
image: mysql:5.7
image: mysql:8.0
ports:
- 3307:3306
env:
Expand All @@ -58,13 +58,16 @@ jobs:
- name: Create MongoDB Replica Set
run: |
docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=unittest --detach mongo:${{ matrix.mongodb }} mongod --replSet rs --setParameter transactionLifetimeLimitSeconds=5
until docker exec --tty mongodb mongo 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do

if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does mongosh come from? IIRC it's not distributed with the server package, so if we download it separately we should be able to use it with 4.4 as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in the mongodb docker image. We can remove this line after February 2024 when support for 4.4 will end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Fine with me :)

until docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do
sleep 1
done
sudo docker exec --tty mongodb mongo 127.0.0.1:27017 --eval "rs.initiate({\"_id\":\"rs\",\"members\":[{\"_id\":0,\"host\":\"127.0.0.1:27017\" }]})"
sudo docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "rs.initiate({\"_id\":\"rs\",\"members\":[{\"_id\":0,\"host\":\"127.0.0.1:27017\" }]})"
- name: Show MongoDB server status
run: |
docker exec --tty mongodb mongo 127.0.0.1:27017 --eval "db.runCommand({ serverStatus: 1 })"
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ serverStatus: 1 })"
- name: "Installing php"
uses: shivammathur/setup-php@v2
with:
Expand Down
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
ARG PHP_VERSION=8.1
ARG COMPOSER_VERSION=2.5.4

FROM php:${PHP_VERSION}-cli

RUN apt-get update && \
apt-get install -y autoconf pkg-config libssl-dev git libzip-dev zlib1g-dev && \
apt-get install -y autoconf pkg-config libssl-dev git unzip libzip-dev zlib1g-dev && \
pecl install mongodb && docker-php-ext-enable mongodb && \
pecl install xdebug && docker-php-ext-enable xdebug && \
docker-php-ext-install -j$(nproc) pdo_mysql zip

COPY --from=composer:${COMPOSER_VERSION} /usr/bin/composer /usr/local/bin/composer
COPY --from=composer:2.5.8 /usr/bin/composer /usr/local/bin/composer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having it at the top of the file made it easier to locate the version for an update, but no objection to inlining it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work with my setup.

Docker version 24.0.5, build ced0996600
Docker Compose version 2.20.3
colima version 0.5.5

There is a workaroud if I alias the composer image.
docker/for-mac#2155 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no worries then 👍


WORKDIR /code

COPY composer.* ./

RUN composer install

COPY ./ ./

ENV COMPOSER_ALLOW_SUPERUSER=1

RUN composer install

CMD ["./vendor/bin/phpunit"]
CMD ["./vendor/bin/phpunit", "--testdox"]
16 changes: 13 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: '3.5'

services:
tests:
Expand All @@ -10,9 +10,14 @@ services:
volumes:
- .:/code
working_dir: /code
environment:
MONGODB_URI: 'mongodb://mongodb/'
MYSQL_HOST: 'mysql'
depends_on:
- mongodb
- mysql
mongodb:
condition: service_healthy
mysql:
condition: service_started

mysql:
container_name: mysql
Expand All @@ -29,3 +34,8 @@ services:
image: mongo:latest
ports:
- "27017:27017"
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh mongodb:27017 --quiet
interval: 10s
timeout: 10s
retries: 5
1 change: 0 additions & 1 deletion tests/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ public function testTransactionRespectsRepetitionLimit(): void
$this->fail('Expected exception during transaction');
} catch (BulkWriteException $e) {
$this->assertInstanceOf(BulkWriteException::class, $e);
$this->assertStringContainsString('WriteConflict', $e->getMessage());
}

$this->assertSame(2, $timesRun);
Expand Down