Skip to content
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

INTPYTHON-449 Use local atlas for testing #36

Merged
merged 7 commits into from
Dec 12, 2024
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
7 changes: 6 additions & 1 deletion .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ jobs:
run: make tests
working-directory: ${{ inputs.working-directory }}

- name: Start local Atlas
run: bash scripts/start_local_atlas.sh

- name: Get MongoDB URI
run: cat .local_atlas_uri >> $GITHUB_ENV

- name: Run integration tests
env:
MONGODB_URI: ${{ secrets.MONGODB_ATLAS_URI }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: make integration_tests
working-directory: ${{ inputs.working-directory }}
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ jobs:
run: |
make test

- name: Start local Atlas
working-directory: .
run: bash scripts/start_local_atlas.sh

- name: Get MongoDB URI
working-directory: .
run: cat .local_atlas_uri >> $GITHUB_ENV

- name: Run integration tests
env:
MONGODB_URI: ${{ secrets.MONGODB_ATLAS_URI }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
# Only run on the min python version.
if [[ "${{ matrix.python-version }}" == "3.9" ]]; then
make integration_tests
fi
fi
run: make integration_tests
working-directory: ${{ inputs.working-directory }}

- name: Ensure the tests did not create any additional files
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
.mypy_cache_test
.env
.venv*
.local_atlas_uri
2 changes: 1 addition & 1 deletion libs/mongodb/tests/integration_tests/test_chain_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def collection() -> Collection:


@pytest.mark.skipif(
"OPENAI_API_KEY" not in os.environ, reason="Requires OpenAI for chat responses."
os.environ.get("OPENAI_API_KEY") is not None, reason="Requires OpenAI for chat responses."
)
def test_chain(
collection: Collection,
Expand Down
2 changes: 1 addition & 1 deletion libs/mongodb/tests/integration_tests/test_retrievers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def embedding_openai() -> Embeddings:
model="text-embedding-3-small",
)
except Exception:
pytest.fail("test_retrievers expects OPENAI_API_KEY in os.environ")
pytest.skip("test_retrievers expects OPENAI_API_KEY in os.environ")


@pytest.fixture(scope="module")
Expand Down
23 changes: 23 additions & 0 deletions scripts/start_local_atlas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -eu

echo "Starting the container"

IMAGE=mongodb/mongodb-atlas-local:latest
podman pull $IMAGE

CONTAINER_ID=$(podman run --rm -d -e DO_NOT_TRACK=1 --name mongodb_atlas_local -P $IMAGE)

function wait() {
CONTAINER_ID=$1
echo "waiting for container to become healthy..."
podman logs mongodb_atlas_local
}

wait "$CONTAINER_ID"

EXPOSED_PORT=$(podman inspect --format='{{ (index (index .NetworkSettings.Ports "27017/tcp") 0).HostPort }}' "$CONTAINER_ID")
export CONN_STRING="mongodb://127.0.0.1:$EXPOSED_PORT/?directConnection=true"
SCRIPT_DIR=$(realpath "$(dirname ${BASH_SOURCE[0]})")
ROOT_DIR=$(dirname $SCRIPT_DIR)
echo "MONGODB_URI=mongodb://127.0.0.1:$EXPOSED_PORT/?directConnection=true" > $ROOT_DIR/.local_atlas_uri
Loading