Skip to content

PHPORM-266 Run tests on Atlas Local #3216

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 2 commits into from
Jan 3, 2025
Merged
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- "5.0"
- "6.0"
- "7.0"
- "Atlas"
php:
- "8.1"
- "8.2"
Expand All @@ -45,15 +46,24 @@ jobs:
- uses: "actions/checkout@v4"

- name: "Create MongoDB Replica Set"
if: ${{ matrix.mongodb != 'Atlas' }}
run: |
docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=unittest --detach mongo:${{ matrix.mongodb }} mongod --replSet rs --setParameter transactionLifetimeLimitSeconds=5

if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
until docker exec --tty mongodb $MONGOSH_BIN 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do
sleep 1
sleep 1
done
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: "Create MongoDB Atlas Local"
if: ${{ matrix.mongodb == 'Atlas' }}
run: |
docker run --name mongodb -p 27017:27017 -e MONGO_INITDB_DATABASE=unittest --detach mongodb/mongodb-atlas-local:latest
until docker exec --tty mongodb mongosh 127.0.0.1:27017 --eval "db.runCommand({ ping: 1 })"; do
sleep 1
done

- name: "Show MongoDB server status"
run: |
if [ "${{ matrix.mongodb }}" = "4.4" ]; then MONGOSH_BIN="mongo"; else MONGOSH_BIN="mongosh"; fi
Expand Down Expand Up @@ -93,4 +103,4 @@ jobs:
- name: "Run tests"
run: "./vendor/bin/phpunit --coverage-clover coverage.xml"
env:
MONGODB_URI: 'mongodb://127.0.0.1/?replicaSet=rs'
MONGODB_URI: 'mongodb://127.0.0.1/'
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary to connect to the Atlas container? The subtle impact of this change means that you're going to establish a direct connection to the host instead of constructing a replica set connection. It'd be preferable to figure out what the appropriate replica set name is for each environment and fill that in here.

Copy link
Member Author

Choose a reason for hiding this comment

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

The Atlas Local container creates a replica set automatically, using the hostname of the container. But I can't connect using this replica set name.

$ docker run --rm -d -t -p27017:27017 mongodb/mongodb-atlas-local:latest
a4e8da8c44ce38e990644497bda0aa4105a82f88c143aceaf4efae9a3d041feb

$ docker ps
CONTAINER ID   IMAGE                                COMMAND                  CREATED         STATUS                            PORTS                                           NAMES
a4e8da8c44ce   mongodb/mongodb-atlas-local:latest   "/usr/local/bin/runn…"   4 seconds ago   Up 4 seconds (health: starting)   0.0.0.0:27017->27017/tcp, :::27017->27017/tcp   competent_rosalind

$ mongosh 'mongodb://127.0.0.1:27017/' --eval 'rs.status().set'
a4e8da8c44ce

$ mongosh 'mongodb://127.0.0.1:27017/?replicaSet=a4e8da8c44ce'
Current Mongosh Log ID: 67781475e943141095ff0bb1
Connecting to:          mongodb://127.0.0.1:27017/?replicaSet=0ac71f55cba3&serverSelectionTimeoutMS=2000&appName=mongosh+2.3.2
MongoNetworkError: getaddrinfo ENOTFOUND a4e8da8c44ce

Solution: skip the replica set configuration and use implicit direct connect for Atlas local.

Loading