From bcf5393af8e948b54ad3148976aedf80ad1b2af8 Mon Sep 17 00:00:00 2001 From: Jennifer Hamon Date: Tue, 26 Dec 2023 10:38:39 -0600 Subject: [PATCH] Parameterize integration tests on environment (#256) ## Problem I want to be able to run the integration tests with a variety of environments. ## Solution Add some variables to the test matrix and wire them into the test execution. We can expand this list over time to grow our test surface area. ## Type of Change - [x] Infrastructure change (CI configs, etc) --- .github/workflows/testing.yaml | 18 +++++++++++++++--- tests/integration/conftest.py | 18 +++++++++++++++--- tests/integration/helpers/helpers.py | 5 +++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index fd822de5..1306bf3b 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -37,19 +37,25 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.8, 3.11] pineconeEnv: - prod # - staging + testConfig: + - python-version: 3.8 # Do one test run with 3.8 for sanity check + pod: { environment: 'us-east1-gcp'} + serverless: { cloud: 'aws', region: 'us-west-2'} + - python-version: 3.11 + pod: { environment: 'us-east1-gcp'} + serverless: { cloud: 'aws', region: 'us-west-2'} max-parallel: 1 fail-fast: false steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python ${{ matrix.testConfig.python-version }} uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.testConfig.python-version }} - name: Setup Poetry uses: ./.github/actions/setup-poetry @@ -61,6 +67,9 @@ jobs: PINECONE_CONTROLLER_HOST: 'https://api.pinecone.io' PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} GITHUB_BUILD_NUMBER: "${{ github.run_number }}-p-${{ matrix.python-version}}" + POD_ENVIRONMENT: ${{ matrix.testConfig.pod.environment }} + SERVERLESS_CLOUD: ${{ matrix.testConfig.serverless.cloud }} + SERVERLESS_REGION: ${{ matrix.testConfig.serverless.region }} - name: Run integration tests (REST, staging) if: matrix.pineconeEnv == 'staging' @@ -69,6 +78,9 @@ jobs: PINECONE_CONTROLLER_HOST: 'https://api-staging.pinecone.io' PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY_STAGING }} GITHUB_BUILD_NUMBER: "${{ github.run_number }}-s-${{ matrix.python-version}}" + POD_ENVIRONMENT: ${{ matrix.testConfig.pod.environment }} + SERVERLESS_CLOUD: ${{ matrix.testConfig.serverless.cloud }} + SERVERLESS_REGION: ${{ matrix.testConfig.serverless.region }} units-grpc: name: Unit tests (GRPC) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index d8d333e2..4e8f3b9a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -9,15 +9,27 @@ def client(): api_key = get_environment_var('PINECONE_API_KEY') return Pinecone(api_key=api_key) +@pytest.fixture() +def pod_environment(): + return get_environment_var('POD_ENVIRONMENT', 'us-east1-gcp') + +@pytest.fixture() +def serverless_cloud(): + return get_environment_var('SERVERLESS_CLOUD', 'aws') + +@pytest.fixture() +def serverless_region(): + return get_environment_var('SERVERLESS_REGION', 'us-west-2') + @pytest.fixture() def environment(): return get_environment_var('PINECONE_ENVIRONMENT') @pytest.fixture() -def create_sl_index_params(index_name): +def create_sl_index_params(index_name, serverless_cloud, serverless_region): spec = {"serverless": { - 'cloud': 'aws', - 'region': 'us-west-2' + 'cloud': serverless_cloud, + 'region': serverless_region }} return dict(name=index_name, dimension=10, metric='cosine', spec=spec) diff --git a/tests/integration/helpers/helpers.py b/tests/integration/helpers/helpers.py index 1e40f6fa..1d19e823 100644 --- a/tests/integration/helpers/helpers.py +++ b/tests/integration/helpers/helpers.py @@ -2,6 +2,7 @@ import os import random import string +from typing import Any def random_string(length): return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) @@ -37,8 +38,8 @@ def generate_index_name(test_name: str) -> str: return index_name.lower() -def get_environment_var(name: str) -> str: - val = os.getenv(name) +def get_environment_var(name: str, defaultVal: Any = None) -> str: + val = os.getenv(name, defaultVal) if (val is None): raise Exception('Expected environment variable ' + name + ' is not set') else: