QA Interview Hub · Knowledge base · Quizzes · Українська

System Design › CI/CD, parallelization and sharding

Tests in the pipeline: stages and quality gates

A quality gate is a rule that blocks a merge or a deploy; technically it is a required status check in the branch rules. Tests are arranged by stage: fast checks (lint, typecheck, unit, smoke) on the PR, more expensive ones later. A gate must be deterministic, fast and have an owner, so a flaky test is moved to quarantine with an owner and a deadline instead of staying in the gate.

System design · CI and parallelism

Smoke on a PR fails because of an unstable test, and the team merges past it. What should block a merge?

A smoke test on a PR goes red once in ten runs. The team gets used to pressing «rerun», then to looking past the red, and one day merges a real defect because «it is the same flaky one». The pipeline existed, but the gate did not. This lesson covers how to arrange tests into stages, what a quality gate is and why the reliability of a gate matters more than its strictness.

How it works and why. Tests differ in price and signal. Cheap ones (lint, typecheck, unit) answer in minutes and catch most breakages; expensive ones (full e2e, cross-browser, performance) are slow but cover what the cheap ones do not see. The pipeline principle: fast feedback from cheap tests, and the expensive ones run when it makes sense. So the suite is arranged by the moment of the run.

What to run and when

PR: lint, unit, API, smokeblocks merge, target 5-10 minutesmain: full API and e2etarget up to 15 minutesNightly: long and cross-browsercostly tests that rarely breakRelease: smoke on staging and proda check after deploy
Figure 1. The time targets are anchors for a discussion, not a norm: they are agreed with the team.

A quality gate is a rule that blocks a merge or a deploy: all unit and API tests are green, smoke is green, coverage of changed files has not dropped. Technically it is a required status check in the branch rules (branch protection or a ruleset in GitHub): the test job is named in the rule, and without a green result the merge button does not activate. A gate has four properties: determinism (the same code gives the same result), speed, an owner and a transparent bypass (an emergency merge is possible but leaves a trace).

What to run on a PR. The full suite on every PR is often too expensive. Selection options:

  • A smoke set with a tag: in Playwright the tag is set in the test declaration, and the run goes through --grep @smoke.
  • Tests tied to changed files: --only-changed=origin/main takes the changes between HEAD and the given ref (without a ref only uncommitted changes, so CI passes the ref explicitly and sets fetch-depth: 0 in actions/checkout, which fetches a single commit by default) and runs the changed test files plus those that import changed modules. For a backend change that tests do not import, it tells nothing.
  • Rerunning only the failed ones: --last-failed, handy locally.

For fintech the PR set must include the critical money scenarios: a transfer, a top-up, a refusal on insufficient balance. The cost of a mistake there is the highest, so they are not deferred to the nightly run.

Example: a PR pipeline. Cheap checks go first, smoke starts only when they are green. Note the --grep-invert filter: it takes unstable tests out of the gate.

name: pr
on:
  pull_request:
jobs:
  fast:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: lts/*
          cache: npm
      - run: npm ci
      - run: npm run lint && npm run typecheck && npm test
  smoke:
    needs: fast
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: lts/*
          cache: npm
      - run: npm ci
      - run: npx playwright install --with-deps chromium
      - run: npx playwright test --grep @smoke --grep-invert @quarantine

A test is tagged like this:

test('transfer reduces the balance', { tag: '@smoke' }, async ({ funded }) => {
  // ...
});

The @quarantine tag works the same way but in reverse: a test with it does not block a PR, a separate job runs it (so you can see whether it is still unstable), and it has an owner and a deadline. Without a deadline quarantine becomes a graveyard.

An unstable test in the gate

Typical

A gate on an unstable test

Smoke fails for no reason. The team reruns until green, and then starts merging past it.

Better

Quarantine with an owner

The unstable test leaves the gate but stays in a separate run with an owner and a deadline.

Figure 2. A gate works as long as it is trusted.

Limits and alternatives. Required checks are tied to job names: a matrix job with eight shards gives eight names, so a separate summary job that waits for all and shows the overall result is handier. There is also a trap with path filters: if a workflow did not start because of paths, the required status stays «Pending» and the merge is blocked, so it must be taken into account when configuring. A merge queue checks changes in the queue rather than separately and catches conflicts between PRs, but adds time. For a small project two stages are enough: PR and main.

Common mistakes.

  • Making an unstable test a gate: the team learns to ignore red, and the gate loses meaning.
  • Running the full e2e on every PR without need: expensive and slow, feedback arrives late.
  • Relying on --only-changed for changes that tests do not import: smoke or API tests are needed as a floor.
  • Quarantine with no owner and no deadline: a test lives in it for years.
  • A gate with no bypass for an emergency: people get around it through repository rules instead of legally.

Check yourself

Smoke on a PR fails in roughly one of ten runs with no code change. What to do, and what happens if nothing is done?

Answer

If nothing is done, the team gets used to rerunning and ignoring, and the gate loses trust: a real defect slips through as «the same flaky one». The right move: take the test into quarantine (outside the gate) with an owner and a deadline, find the cause and bring it back, and keep only deterministic tests in the gate.

A PR changes only the code of a backend service that tests do not import. Why does --only-changed not protect here?

Answer

It selects tests that import the changed files. Tests do not import the service code, so there is no link and the needed test may not be selected. Such changes need a smoke or API set as a required floor.

In an interview. Junior: I build the pipeline in layers: fast checks and smoke on a PR, the full set on main, long and cross-browser tests at night, smoke in production after a deploy. The gate blocks a merge only with stable tests. Middle/Senior: A gate is a required status check, so it must be deterministic, fast and have an owner. I move unstable tests into quarantine with a deadline instead of leaving them in the gate, otherwise the team stops trusting red. On a PR I take tagged smoke and the critical money scenarios, and treat --only-changed as a supplement, not a floor. For a matrix I make a summary job and remember path filters.

More articles in this chapter