6.3 Flaky test 진단
Retry로 통과한 test는 정상 test가 아니라 flaky 신호입니다. Retry는 artifact를 얻고 CI noise를 제한하는 수단이지 원인 해결이 아닙니다.
증거 기반 분류표
- Timing: fixed sleep, 잘못된 ready signal
- Locator: 여러 element, DOM 구조 결합
- State: 공유 account, database, file
- Environment: CPU, memory, network 부족
- Product: race condition, eventual consistency
- Test: promise 누락, cleanup 실패
npx playwright test tests/problem.spec.ts --repeat-each=20 --workers=1
npx playwright test tests/problem.spec.ts --repeat-each=20 --workers=4
Single worker에서 안정적이고 parallel에서 실패하면 shared state와 resource saturation을 우선 봅니다. Browser project 하나에서만 실패하면 browser engine 차이와 product compatibility를 확인합니다.
Anti-pattern
- Timeout을 계속 늘림
.first()로 locator ambiguity를 숨김force: true로 overlay를 무시함- Serial mode로 test dependency를 유지함
- 실패 screenshot만 보고 network, trace를 버림
Flaky rate, retry 통과 수, 가장 흔한 signature를 추적합니다. Quarantine에는 owner와 만료일을 두고 main quality gate 밖에서 영구 방치하지 않습니다.
재현 matrix
npx playwright test tests/suspect.spec.ts --repeat-each=50 --workers=1
npx playwright test tests/suspect.spec.ts --repeat-each=50 --workers=8
npx playwright test tests/suspect.spec.ts --project=webkit
Single worker에서만 안정적이면 shared data/resource contention을, 특정 browser에서만 실패하면 compatibility를 의심할 수 있습니다.
원인 분류
| 분류 | 증거 | 대표 수정 |
|---|---|---|
| Locator/race | actionability, DOM snapshot | semantic locator, state assertion |
| Test data | duplicate ID, 409 | namespace, cleanup |
| Environment | CPU, server startup | resource, readiness 조정 |
| Product race | console/network timing | 제품 state machine 수정 |
| External dependency | timeout, 5xx | contract/mock, sandbox SLA |
Retry 해석
Playwright는 첫 시도 실패 후 retry 통과를 flaky로 분류할 수 있습니다. Pipeline exit code가 성공이어도 flake metric과 issue를 남깁니다.
실습
- Shared title로 병렬 collision을 만듭니다.
--repeat-each와 worker 수를 바꿔 failure rate를 측정합니다.- Signature별로 trace를 묶고 가장 빈번한 root cause를 고칩니다.
- Quarantine item에 owner, issue, 만료일, 복귀 조건을 작성합니다.
참고: Retries, Best Practices, Parallelism