Skip to content

Commit

Permalink
Merge pull request #1498 from input-output-hk/retest_testrun
Browse files Browse the repository at this point in the history
Add ability to retest failures in a test run
  • Loading branch information
mkoura authored Nov 21, 2022
2 parents 3074a75 + 9a1658b commit 88084bd
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/regression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ nix develop --accept-flake-config $(node_override) --command bash -c '
'
retval="$?"

# move html report to root dir
mv .reports/testrun-report.html testrun-report.html
# move reports to root dir
mv .reports/testrun-report.* ./

# create results archive
"$REPODIR"/.buildkite/results.sh .
Expand Down
26 changes: 16 additions & 10 deletions .github/workflows/regression-dbsync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ on:
workflow_dispatch:
inputs:
node_rev:
description: "cardano-node revision (default: HEAD)"
required: false
node_branch:
description: "cardano-node branch (default: master)"
description: "cardano-node revision (default: master HEAD)"
required: false
dbsync_rev:
description: "db-sync revision (default: HEAD)"
required: false
dbsync_branch:
description: "db-sync branch (default: master)"
description: "db-sync revision (default: master HEAD)"
required: false
cluster_era:
type: choice
Expand Down Expand Up @@ -44,19 +38,31 @@ on:
type: boolean
default: false
description: "Start cluster directly in target era"
testrun_name:
required: false
description: "Test run name (internal)"
skip_passed:
type: boolean
default: false
description: "Skip tests that already passed (internal)"

run-name: ${{ inputs.testrun_name && 'Run:' || ''}} ${{ inputs.testrun_name }} ${{ (inputs.testrun_name && inputs.skip_passed) && ':repeat:' || '' }}

jobs:
regression_tests:
# reusable workflow from local repo and same branch as this config
uses: ./.github/workflows/regression_reusable.yaml
with:
node_rev: ${{ inputs.node_rev }}
node_branch: ${{ inputs.node_branch }}
dbsync_rev: ${{ inputs.dbsync_rev }}
dbsync_branch: ${{ inputs.dbsync_branch }}
cluster_era: ${{ inputs.cluster_era }}
tx_era: ${{ inputs.tx_era }}
enable_p2p: ${{ inputs.enable_p2p }}
enable_dbsync: true
skip_long: ${{ inputs.skip_long }}
fast_cluster: ${{ inputs.fast_cluster }}
testrun_name: ${{ inputs.testrun_name }}
skip_passed: ${{ inputs.skip_passed }}
secrets:
TCACHE_BASIC_AUTH: ${{ secrets.TCACHE_BASIC_AUTH }}
TCACHE_URL: ${{ secrets.TCACHE_URL }}
20 changes: 15 additions & 5 deletions .github/workflows/regression.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ on:
workflow_dispatch:
inputs:
node_rev:
description: "cardano-node revision (default: HEAD)"
required: false
node_branch:
description: "cardano-node branch (default: master)"
description: "cardano-node revision (default: master HEAD)"
required: false
cluster_era:
type: choice
Expand Down Expand Up @@ -38,16 +35,29 @@ on:
type: boolean
default: false
description: "Start cluster directly in target era"
testrun_name:
required: false
description: "Test run name (internal)"
skip_passed:
type: boolean
default: false
description: "Skip tests that already passed (internal)"

run-name: ${{ inputs.testrun_name && 'Run:' || ''}} ${{ inputs.testrun_name }} ${{ (inputs.testrun_name && inputs.skip_passed) && ':repeat:' || '' }}

jobs:
regression_tests:
# reusable workflow from local repo and same branch as this config
uses: ./.github/workflows/regression_reusable.yaml
with:
node_rev: ${{ inputs.node_rev }}
node_branch: ${{ inputs.node_branch }}
cluster_era: ${{ inputs.cluster_era }}
tx_era: ${{ inputs.tx_era }}
enable_p2p: ${{ inputs.enable_p2p }}
skip_long: ${{ inputs.skip_long }}
fast_cluster: ${{ inputs.fast_cluster }}
testrun_name: ${{ inputs.testrun_name }}
skip_passed: ${{ inputs.skip_passed }}
secrets:
TCACHE_BASIC_AUTH: ${{ secrets.TCACHE_BASIC_AUTH }}
TCACHE_URL: ${{ secrets.TCACHE_URL }}
30 changes: 30 additions & 0 deletions .github/workflows/regression_reusable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ on:
required: false
type: boolean
default: false
testrun_name:
required: false
type: string
default: ""
skip_passed:
required: false
type: boolean
default: false
secrets:
TCACHE_BASIC_AUTH:
required: false
TCACHE_URL:
required: false

jobs:
reusable_run:
Expand All @@ -77,13 +90,28 @@ jobs:
echo "CI_ENABLE_DBSYNC=${{ inputs.enable_dbsync }}" >> .github_ci_env
echo "CI_SKIP_LONG=${{ inputs.skip_long }}" >> .github_ci_env
echo "CI_FAST_CLUSTER=${{ inputs.fast_cluster }}" >> .github_ci_env
echo "CI_TESTRUN_NAME=${{ inputs.testrun_name }}" >> .github_ci_env
echo "CI_SKIP_PASSED=${{ inputs.skip_passed }}" >> .github_ci_env
if [ -e "${{ inputs.env-path }}" ]; then cat "${{ inputs.env-path }}" >> .github_ci_env; fi
- name: Export env variables
run: |
cat .github_ci_env
cat .github_ci_env >> $GITHUB_ENV
- name: Get previous test results
if: inputs.testrun_name && inputs.skip_passed
run: |
if [ -n "${{ secrets.TCACHE_BASIC_AUTH }}" ] && [ -n "${{ secrets.TCACHE_URL }}" ]; then
curl -s -u ${{ secrets.TCACHE_BASIC_AUTH }} "${{ secrets.TCACHE_URL }}/${{ inputs.testrun_name }}/pypassed" > deselected_tests.txt
echo "DESELECT_FROM_FILE=deselected_tests.txt" >> $GITHUB_ENV
fi
- name: Run CLI regression tests
run: .github/regression.sh
- name: Report test results
if: (success() || failure()) && inputs.testrun_name
run: |
if [ -n "${{ secrets.TCACHE_BASIC_AUTH }}" ] && [ -n "${{ secrets.TCACHE_URL }}" ]; then
curl -s -X PUT --fail-with-body -u ${{ secrets.TCACHE_BASIC_AUTH }} "${{ secrets.TCACHE_URL }}/${{ inputs.testrun_name }}/${{ github.run_number }}/import" -F "junitxml=@testrun-report.xml"
fi
- name: Upload testing artifacts on failure
uses: actions/upload-artifact@v3
if: failure()
Expand Down Expand Up @@ -113,3 +141,5 @@ jobs:
cli_coverage.json
scheduling.log.xz
errors_all.log
testrun-report.xml
deselected_tests.txt
32 changes: 26 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,42 @@ ifndef NO_ARTIFACTS
endif

ifndef PYTEST_ARGS
HTML_REPORT_ARGS := --html=$(REPORTS_DIR)/testrun-report.html --self-contained-html
TESTRUN_REPORT_ARGS := --html=$(REPORTS_DIR)/testrun-report.html --self-contained-html --junitxml=$(REPORTS_DIR)/testrun-report.xml
endif

ifdef DESELECT_FROM_FILE
DESELECT_FROM_FILE_ARGS := --deselect-from-file=$(DESELECT_FROM_FILE)
endif

CLEANUP := yes
RUN_SKIPS := yes

ifdef PYTEST_ARGS
CLEANUP := no
RUN_SKIPS := no
endif

ifdef DESELECT_FROM_FILE
RUN_SKIPS := no
endif

.dirs:
mkdir -p $(ARTIFACTS_DIR) $(COVERAGE_DIR) $(REPORTS_DIR)

.run_tests:
# First just skip all tests so Allure has a list of runable tests. Also delete artifacts from previous runs.
# Run only if no pytest args were specified.
ifndef PYTEST_ARGS
rm -f $(REPORTS_DIR)/{*-attachment.txt,*-result.json,*-container.json,testrun-report.html}
# delete artifacts from previous runs
ifeq ($(CLEANUP),yes)
rm -f $(REPORTS_DIR)/{*-attachment.txt,*-result.json,*-container.json,testrun-report.*}
rm -f $(COVERAGE_DIR)/cli_coverage_*
endif

# first just skip all tests so Allure has a list of all tests that were supposed to run
ifeq ($(RUN_SKIPS),yes)
pytest -s cardano_node_tests $(MARKEXPR) --skipall --alluredir=$(REPORTS_DIR) >/dev/null
endif

# run tests for real and produce Allure results
pytest cardano_node_tests $(PYTEST_ARGS) $(CI_ARGS) $(MARKEXPR) -n $(TEST_THREADS) $(ARTIFACTS_ARGS) --cli-coverage-dir=$(COVERAGE_DIR) --alluredir=$(REPORTS_DIR) $(HTML_REPORT_ARGS)
pytest cardano_node_tests $(PYTEST_ARGS) $(CI_ARGS) $(MARKEXPR) $(DESELECT_FROM_FILE_ARGS) -n $(TEST_THREADS) $(ARTIFACTS_ARGS) --cli-coverage-dir=$(COVERAGE_DIR) --alluredir=$(REPORTS_DIR) $(TESTRUN_REPORT_ARGS)


# run all tests, generate allure report
Expand Down
6 changes: 6 additions & 0 deletions cardano_node_tests/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def pytest_configure(config: Any) -> None:
config._metadata["cardano-cli exe"] = shutil.which("cardano-cli") or ""
config._metadata["cardano-node exe"] = shutil.which("cardano-node") or ""

testrun_name = os.environ.get("CI_TESTRUN_NAME")
if testrun_name:
skip_passed = os.environ.get("CI_SKIP_PASSED") == "true"
config._metadata["CI_TESTRUN_NAME"] = testrun_name
config._metadata["CI_SKIP_PASSED"] = str(skip_passed)

network_magic = configuration.NETWORK_MAGIC_LOCAL
if configuration.BOOTSTRAP_DIR:
with open(
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
packageOverrides = self: _: {
allure = self.callPackage ./nix/allure.nix { };
pytest-allure = self.callPackage ./nix/pytest-allure.nix { };
pytest-select = self.callPackage ./nix/pytest-select.nix {};
cardano-clusterlib = self.callPackage ./nix/cardano-clusterlib.nix { };
};
};
Expand Down Expand Up @@ -65,6 +66,7 @@
pytest-allure
pytest-html
pytest-order
pytest-select
pytest_xdist
pyyaml
setuptools
Expand Down
2 changes: 2 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let
packageOverrides = self: _: {
allure = self.callPackage ./allure.nix {};
pytest-allure = self.callPackage ./pytest-allure.nix {};
pytest-select = self.callPackage ./pytest-select.nix {};
cardano-clusterlib = self.callPackage ./cardano-clusterlib.nix {};
};
};
Expand All @@ -31,6 +32,7 @@ let
pytest-allure
pytest-html
pytest-order
pytest-select
pytest_xdist
pyyaml
setuptools
Expand Down
12 changes: 12 additions & 0 deletions nix/pytest-select.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ stdenv, buildPythonPackage, fetchPypi, pytest }:

buildPythonPackage rec {
pname = "pytest-select";
version = "0.1.2";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-FGqq8pQDT2TMAyZEjQTAP6U98ZckjJh0cS8hqRnOQU4=";
};
doCheck = false;
propagatedBuildInputs = [ pytest ];
}
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ install_requires =
pytest-html
pytest-metadata
pytest-order
pytest-select
pytest-xdist
pyyaml
requests
Expand Down

0 comments on commit 88084bd

Please sign in to comment.