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

Mark flaky tests #813

Merged
merged 28 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
606e18c
mark flaky tests using pytest.mark
mikealfare May 6, 2024
1d6fc06
split integration test runs by flaky and non-flaky
mikealfare May 6, 2024
14a3ca9
fix the posargs syntax for tox
mikealfare May 6, 2024
c535de5
force flaky tests to run in series, fix python version getting truncated
mikealfare May 6, 2024
7b2c02a
revert the integration test job name to match the existing names
mikealfare May 6, 2024
19e76a6
separate flaky tests as a separate matrix of jobs
mikealfare May 6, 2024
0bb9ac1
recombine the integration tests
mikealfare May 7, 2024
c583d07
allow integration tests to run fully in parallel for non-flaky tests
mikealfare May 7, 2024
0e24eda
remove windows from integration test matrix since we weren't original…
mikealfare May 7, 2024
5b6e336
add windows back in
mikealfare May 7, 2024
69ec8a2
register the custom marker with pytest
mikealfare May 7, 2024
b0c8be9
revert the combination of integration tests
mikealfare May 7, 2024
9bc24fa
configure a pytest return of 5 to be 0
mikealfare May 7, 2024
d5563f0
fix test order to avoid unnecessary change
mikealfare May 7, 2024
8e6975b
mark more flaky tests
mikealfare May 7, 2024
201cbc2
Merge branch 'main' into mark-flaky-tests
mikealfare May 7, 2024
80f141c
mark more flaky tests
mikealfare May 7, 2024
c30ec4b
pin windows images to 2019 to avoid datadog traceport failures
mikealfare May 7, 2024
ca39198
pinning windows images to 2019 didn't solve datadog issue, updating p…
mikealfare May 7, 2024
6d9215a
turn off telemetry warnings (and telemetry)
mikealfare May 7, 2024
409023c
mark more tests as flaky
mikealfare May 7, 2024
7803c26
mark more tests as flaky
mikealfare May 7, 2024
7f4930d
Merge branch 'refs/heads/main' into mark-flaky-tests
mikealfare May 7, 2024
ece78fd
Merge branch 'main' into mark-flaky-tests
mikealfare May 8, 2024
2671439
Merge branch 'main' into mark-flaky-tests
mikealfare May 8, 2024
59aec05
incorporate feedback
mikealfare May 9, 2024
8a59160
Merge remote-tracking branch 'origin/mark-flaky-tests' into mark-flak…
mikealfare May 9, 2024
2cab2f4
incorporate feedback
mikealfare May 9, 2024
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
87 changes: 0 additions & 87 deletions .github/scripts/integration-test-matrix.js

This file was deleted.

172 changes: 100 additions & 72 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,85 +53,32 @@ defaults:
shell: bash

jobs:
# generate test metadata about what files changed and the testing matrix to use
test-metadata:
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
test:
name: redshift / python ${{ matrix.python-version }} / ${{ matrix.os }}

# run if not a PR from a forked repository or has a label to mark as safe to test
if: >-
github.event_name != 'pull_request_target' ||
github.event.pull_request.head.repo.full_name == github.repository ||
contains(github.event.pull_request.labels.*.name, 'ok to test')
runs-on: ubuntu-latest

outputs:
matrix: ${{ steps.generate-matrix.outputs.result }}

steps:
- name: Check out the repository (non-PR)
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v3
with:
persist-credentials: false

- name: Check out the repository (PR)
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v3
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}

- name: Check if relevant files changed
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
if: github.event_name == 'pull_request_target'
# https://github.com/marketplace/actions/paths-changes-filter
# For each filter, it sets output variable named by the filter to the text:
# 'true' - if any of changed files matches any of filter rules
# 'false' - if none of changed files matches any of filter rules
# also, returns:
# `changes` - JSON array with names of all filters matching any of the changed files
uses: dorny/paths-filter@v2
id: get-changes
with:
token: ${{ secrets.GITHUB_TOKEN }}
filters: |
redshift:
- 'dbt/**'
- 'tests/**'
- 'dev-requirements.txt'

- name: Generate integration test matrix
id: generate-matrix
uses: actions/github-script@v6
env:
CHANGES: ${{ steps.get-changes.outputs.changes }}
with:
script: |
const script = require('./.github/scripts/integration-test-matrix.js')
const matrix = script({ context })
console.log(matrix)
return matrix
test:
name: ${{ matrix.adapter }} / python ${{ matrix.python-version }} / ${{ matrix.os }}

# run if not a PR from a forked repository or has a label to mark as safe to test
# also checks that the matrix generated is not empty
if: >-
needs.test-metadata.outputs.matrix &&
fromJSON( needs.test-metadata.outputs.matrix ).include[0] &&
(
github.event_name != 'pull_request_target' ||
github.event.pull_request.head.repo.full_name == github.repository ||
contains(github.event.pull_request.labels.*.name, 'ok to test')
)
runs-on: ${{ matrix.os }}

needs: test-metadata

strategy:
fail-fast: false
max-parallel: 3
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
matrix: ${{ fromJSON(needs.test-metadata.outputs.matrix) }}
matrix:
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
os: [ubuntu-22.04, macos12, windows-2022]
python-version: ["3.8"]
include:
- os: ubuntu-22.04
python-version: "3.9"
- os: ubuntu-22.04
python-version: "3.10"
- os: ubuntu-22.04
python-version: "3.11"

env:
TOXENV: integration-${{ matrix.adapter }}
TOXENV: integration-redshift
PYTEST_ADDOPTS: "-v --color=yes -n4 --csv integration_results.csv"
DBT_INVOCATION_ENV: github-actions
DD_CIVISIBILITY_AGENTLESS_ENABLED: true
Expand Down Expand Up @@ -202,7 +149,6 @@ jobs:
AWS_REGION: ${{ vars.REDSHIFT_TEST_REGION }}

- name: Run tox (redshift)
if: matrix.adapter == 'redshift'
env:
REDSHIFT_TEST_DBNAME: ${{ secrets.REDSHIFT_TEST_DBNAME }}
REDSHIFT_TEST_PASS: ${{ secrets.REDSHIFT_TEST_PASS }}
Expand All @@ -218,7 +164,7 @@ jobs:
DBT_TEST_USER_1: dbt_test_user_1
DBT_TEST_USER_2: dbt_test_user_2
DBT_TEST_USER_3: dbt_test_user_3
run: tox -- --ddtrace
run: tox -- -m "not flaky" --ddtrace

- uses: actions/upload-artifact@v3
if: always()
Expand All @@ -235,11 +181,93 @@ jobs:
- uses: actions/upload-artifact@v3
if: always()
with:
name: integration_results_${{ matrix.python-version }}_${{ matrix.os }}_${{ matrix.adapter }}-${{ steps.date.outputs.date }}.csv
name: integration_results_${{ matrix.python-version }}_${{ matrix.os }}_redshift-${{ steps.date.outputs.date }}.csv
path: integration_results.csv

test-flaky:
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
name: redshift / python ${{ matrix.python-version }} / ubuntu-22.04 - flaky

# run this after the norm integration tests to avoid collisions
needs: test

# run if not a PR from a forked repository or has a label to mark as safe to test
if: >-
github.event_name != 'pull_request_target' ||
github.event.pull_request.head.repo.full_name == github.repository ||
contains(github.event.pull_request.labels.*.name, 'ok to test')
runs-on: ubuntu-22.04

strategy:
fail-fast: false
max-parallel: 1
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

env:
TOXENV: integration-redshift
PYTEST_ADDOPTS: "-v --color=yes -n1 --csv integration_results.csv"
DBT_INVOCATION_ENV: github-actions
DD_CIVISIBILITY_AGENTLESS_ENABLED: true
DD_INSTRUMENTATION_TELEMETRY_ENABLED: false
DD_API_KEY: ${{ secrets.DATADOG_API_KEY }}
DD_SITE: datadoghq.com
DD_ENV: ci
DD_SERVICE: ${{ github.event.repository.name }}

steps:
- name: Check out the repository
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v3
with:
persist-credentials: false

# explicity checkout the branch for the PR,
# this is necessary for the `pull_request_target` event
- name: Check out the repository (PR)
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v3
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install python dependencies
run: |
python -m pip install --user --upgrade pip
python -m pip install tox
python -m pip --version
tox --version

- name: Update dev_requirements.txt
if: inputs.dbt-core-branch != ''
run: |
pip install bumpversion
./.github/scripts/update_dbt_core_branch.sh ${{ inputs.dbt-core-branch }}

- name: Run tox (redshift)
env:
REDSHIFT_TEST_DBNAME: ${{ secrets.REDSHIFT_TEST_DBNAME }}
REDSHIFT_TEST_PASS: ${{ secrets.REDSHIFT_TEST_PASS }}
REDSHIFT_TEST_USER: ${{ secrets.REDSHIFT_TEST_USER }}
REDSHIFT_TEST_PORT: ${{ secrets.REDSHIFT_TEST_PORT }}
REDSHIFT_TEST_HOST: ${{ secrets.REDSHIFT_TEST_HOST }}
REDSHIFT_TEST_REGION: ${{ vars.REDSHIFT_TEST_REGION }}
REDSHIFT_TEST_CLUSTER_ID: ${{ vars.REDSHIFT_TEST_CLUSTER_ID }}
REDSHIFT_TEST_IAM_USER_PROFILE: ${{ vars.REDSHIFT_TEST_IAM_USER_PROFILE }}
REDSHIFT_TEST_IAM_USER_ACCESS_KEY_ID: ${{ vars.REDSHIFT_TEST_IAM_USER_ACCESS_KEY_ID }}
REDSHIFT_TEST_IAM_USER_SECRET_ACCESS_KEY: ${{ secrets.REDSHIFT_TEST_IAM_USER_SECRET_ACCESS_KEY }}
REDSHIFT_TEST_IAM_ROLE_PROFILE: ${{ vars.REDSHIFT_TEST_IAM_ROLE_PROFILE }}
DBT_TEST_USER_1: dbt_test_user_1
DBT_TEST_USER_2: dbt_test_user_2
DBT_TEST_USER_3: dbt_test_user_3
run: tox -- -m flaky --ddtrace

require-label-comment:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

needs: test

Expand All @@ -262,7 +290,7 @@ jobs:
check_for_duplicate_msg: true

post-failure:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: test
if: ${{ failure() }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-12, windows-latest]
os: [ubuntu-22.04, macos-12, windows-2022]
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ env_files =
testpaths =
tests/unit
tests/functional
markers =
flaky: marks tests as flaky so they run one at a time (de-select with '-m "not flaky"')
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
pytest_plugins = ["dbt.tests.fixtures.project"]


def pytest_sessionfinish(session, exitstatus):
"""
Configures pytest to treat a scenario with no tests as passing

pytest returns a code 5 when it collects no tests in an effort to warn when tests are expected but not collected
We don't want this when running tox because some combinations of markers and test segments return nothing
"""
if exitstatus == 5:
session.exitstatus = 0
2 changes: 2 additions & 0 deletions tests/functional/adapter/catalog_tests/test_get_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def my_information_schema(self, adapter, my_schema):
identifier="INFORMATION_SCHEMA",
).information_schema()

@pytest.mark.flaky
def test_get_one_catalog_by_relations(
self,
adapter,
Expand All @@ -120,6 +121,7 @@ def test_get_one_catalog_by_relations(
# note the underlying table is missing as it's not in `my_relations`
assert len(catalog) == 12

@pytest.mark.flaky
def test_get_one_catalog_by_schemas(
self,
adapter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def docs(self, project):
run_dbt(["run"])
yield run_dbt(["docs", "generate"])

@pytest.mark.flaky
@pytest.mark.parametrize(
"node_name,relation_type",
[
Expand Down
Loading
Loading