GeezerVison is showing github.com — Merge branch 'ci/hw_test_retry_strategy' into 'master' · espressif/esptool@6ec584a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .gitlab-ci.yml +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,6 +58,10 @@ variables: | 58 | 58 | - if: $CI_PIPELINE_SOURCE == "schedule" | 59 | 59 | when: never | 60 | 60 | - when: on_success | | 61 | + # These failures end within seconds and say nothing about the code. | | 62 | + retry: | | 63 | + max: 1 | | 64 | + when: [runner_system_failure, scheduler_failure, api_failure] | 61 | 65 | before_script: | 62 | 66 | - pip install -e .[dev] --prefer-binary | 63 | 67 | artifacts: | |
Collapse file Copy file name to clipboardExpand all lines: .gitlab/README.md +12-1Lines changed: 12 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,6 +47,17 @@ Python images: `PYTHON_IMAGE_MIN` and `PYTHON_IMAGE_LATEST` in `.gitlab-ci.yml`. | 47 | 47 |
| 48 | 48 | **report** — `combine_reports` merges coverage from test jobs. | 49 | 49 |
| | 50 | +## Retries | | 51 | + | | 52 | +Failures are retried at two levels: | | 53 | + | | 54 | +- **Job retry.** `.target_test` (`target_tests.yml`) and `.windows_test` (`.gitlab-ci.yml`) retry a job once on `runner_system_failure`, `scheduler_failure` or `api_failure`. This covers every `target_<chip>` job, `target_tests_windows` and `host_tests_windows`. Timeouts are not retried: the 60 min timeouts on `esp32` and `esp8266` came from boards dropping mid-run, and a retry costs another hour. | | 55 | +- **Test rerun inside the job.** Outside the stub canary, a hardware test (a class derived from `EsptoolTestCase` in `test/test_esptool.py` or `test/test_esptool_sdm.py`) that fails on a serial-link or port error is rerun up to 2 times, 5 s apart (`flaky` mark with `only_rerun=TRANSPORT_ERRORS`). Assertion failures and boards that cannot be reached are not rerun, unless the assertion message quotes a matching esptool error. `TestReset::test_watchdog_reset` is the exception: its own mark reruns any failure, because its known failure on `esp32c5_32mb` is an assertion. | | 56 | + | | 57 | +The number of reruns per job has no cap. On a link that still connects but often fails, a slow job such as `target_esp32` or `target_esp8266` (about 30 min median) could rerun many tests and reach the 60 min timeout. pytest is then killed and writes no `test/report.xml`. This has not been observed. | | 58 | + | | 59 | +With pytest-rerunfailures, each attempt is written to `test/report.xml` as its own `<testcase>`. When a test passes on a rerun, every entry is marked passed. When every attempt fails, the earlier entries are marked passed and the last one failed. The GitLab test report view therefore shows rerun attempts as passed tests. The error of a rerun attempt is only in the job log: in the output printed while the attempt ran, and as a traceback in the "rerun test summary info" section (`-rR` lists the attempts, `--rerun-show-tracebacks` in `addopts` adds their tracebacks). The stub canary turns the in-job reruns off, so its reports hold no such entries. | | 60 | + | 50 | 61 | ## Canary | 51 | 62 |
| 52 | 63 | Nightly job that builds fresh v2 stubs from **esp-stub-lib** and runs the full test suite against them. All canary jobs use `$CANARY_IMAGE` (`ubuntu:24.04`). | @@ -71,7 +82,7 @@ Nightly job that builds fresh v2 stubs from **esp-stub-lib** and runs the full t | 71 | 82 | | `before_script` error | not run | not run | fails, reported as failed before the comparison | no file | | 72 | 83 | | pytest error (exit 2–5), git or JUnit report error | any | any | fails, reported as failed before the comparison | `error` | | 73 | 84 |
| 74 | | -Only the failed tests are rerun (`pytest --lf`). The committed stubs are restored with `git checkout`, which takes effect because the jobs install esptool in editable mode. Exit code 75 is listed in `allow_failure:exit_codes`, so it does not trigger `canary_on_failure`; the pipeline ends green with warnings and `canary_record` saves the SHA. `test/report.xml` holds the last run with the fresh stubs; `test/report-first.xml`, `test/report-committed.xml` and `test/canary-outcome.txt` are kept as artifacts. | | 85 | +Only the failed tests are rerun (`pytest --lf`). The in-job reruns of the `flaky` marks in `test/test_esptool.py` (see [Retries](#retries)) are turned off when `STUB_CANARY=1`. The rerun above still hides a stub that fails only sometimes (see the known limits below). Without the in-job reruns, a stub that sometimes fails with a transport error is reported when both canary attempts fail; with them, all 6 runs would have to fail. First-run failures also stay in `test/report-first.xml`, and rerun time stays out of the duration estimate below. The committed stubs are restored with `git checkout`, which takes effect because the jobs install esptool in editable mode. Exit code 75 is listed in `allow_failure:exit_codes`, so it does not trigger `canary_on_failure`; the pipeline ends green with warnings and `canary_record` saves the SHA. `test/report.xml` holds the last run with the fresh stubs; `test/report-first.xml`, `test/report-committed.xml` and `test/canary-outcome.txt` are kept as artifacts. | 75 | 86 |
| 76 | 87 | A job killed by the 1 h job timeout counts as CI infrastructure and is not reported, and the next night would test the same SHA and time out again. `canary_pytest.py` therefore interrupts each pytest run 5 minutes before the job timeout and fails the job with the outcome `no-time`. The interrupt is repeated every 15 s, because one that arrives while a test runs `esptool.main()` in the pytest process only fails that test; pytest is killed after 60 s. When more than 5 tests fail, the rerun with the fresh stubs is skipped; random failures hit 1–3 tests per job. Before the rerun with the committed stubs, the script estimates its time as twice the sum of the failed tests' durations, taking for each test the longer of its durations in the runs with the fresh stubs; when less time is left, the job fails with `no-time` without the comparison. A test that passes with the committed stubs before an interruption still counts as stub breakage. | 77 | 88 |
| |
Collapse file Copy file name to clipboardExpand all lines: .gitlab/target_tests.yml +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 | # committed stubs. pytest and coverage never return 75. | 26 | 26 | allow_failure: | 27 | 27 | exit_codes: [75] | | 28 | + # These failures end within seconds and say nothing about the code. Timeouts | | 29 | + # are left out: the 60 min timeouts on esp32 and esp8266 came from boards | | 30 | + # dropping mid-run, and a retry costs another hour. Outside the stub canary, | | 31 | + # serial-link and port-lock test failures are rerun inside the job by the flaky | | 32 | + # marks in test_esptool.py (see .gitlab/README.md, Retries). | | 33 | + retry: | | 34 | + max: 1 | | 35 | + when: [runner_system_failure, scheduler_failure, api_failure] | 28 | 36 | artifacts: | 29 | 37 | reports: | 30 | 38 | junit: test/report.xml | |
Collapse file Copy file name to clipboardExpand all lines: pyproject.toml +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 56 | 56 | "coverage~=6.0", | 57 | 57 | "pre-commit", | 58 | 58 | "pytest", | 59 | | - "pytest-rerunfailures", | | 59 | + "pytest-rerunfailures>=16.7", | 60 | 60 | "requests", | 61 | 61 | "czespressif", | 62 | 62 | ] | | 160 | 160 | docstring-code-format = true | 161 | 161 |
| 162 | 162 | [tool.pytest.ini_options] | 163 | | -addopts = "-sv --junitxml=test/report.xml --color=yes" | | 163 | +addopts = "-sv -rfER --rerun-show-tracebacks --junitxml=test/report.xml --color=yes" |
|