Skip to content

Commit

Permalink
INTPYTHON-449 Use local atlas for testing (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Dec 12, 2024
1 parent 6047a6e commit 5ede100
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
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

0 comments on commit 5ede100

Please sign in to comment.