Making Performance Tests Deterministic Enough for CI
Make CI performance checks trustworthy by controlling owned variance, using comparative gates, and being honest about what a test cannot prove.
Running a performance test in CI does not make it trustworthy. You earn trust by controlling the variance you own, stating the variance you cannot control, and using a decision rule that matches the evidence. You don’t need a perfectly repeatable number. You need a check stable enough to catch a real change without teaching people to click “rerun” until it goes green.
Begin with the smallest performance question CI can answer. A pull-request check might verify that a critical flow completes under a bounded smoke load. A release check can use a production-like environment and broader traffic mix. A scheduled baseline can characterize capacity and tail behavior. Treat these as different test classes with different expectations.
Define the comparison contract
Write down commit, runtime, configuration, dataset, target environment, generator location, load shape, duration, and cache preparation. Keep those inputs versioned or emitted with the result. If an input changes, decide whether the result is comparable before looking at the outcome.
Keep scenario labels and assertions stable. A renamed label can create an apparent new time series and hide the old path. Removing an assertion to reduce flakiness makes the test less meaningful. It does not make it more deterministic. If the product behavior changes, update the contract intentionally and explain the new baseline.
The run comparison guide describes the evidence a reviewer needs. CI should publish that evidence as a link or artifact, not only as a pass/fail badge.
Control environment variance
Use a test environment with known ownership and a predictable lifecycle. Avoid overlapping migrations, background jobs, autoscaling experiments, or unrelated load when a result is expected to block a change. If the environment cannot be isolated, capture its condition and classify the check as advisory.
Control the generator as well. Pin its runtime and dependencies, watch CPU and network, and fail or quarantine a run when it cannot deliver the requested pressure. A slow worker can change arrival timing and produce a false target result. Record worker health as part of the CI artifact.
Data preparation deserves a contract. Reset or seed fixtures consistently, bound random generation, and state cache state. A candidate that runs against a warmer cache may look faster. A candidate that shares a database with another job may look worse. Both are signals about the environment unless the condition was intentional.
Use bounded scenarios
CI scenarios should finish within a known window and apply a known workload. Avoid an open-ended soak in every pull request. Use a short journey with enough samples to detect obvious breakage, then schedule longer runs for endurance and capacity questions. Make the ramp and duration explicit so a timeout is distinguishable from an application failure.
Keep the flow realistic without making it enormous. A single endpoint can be too narrow if a change affects authentication or data setup. A complete product tour can be too broad to diagnose. Choose one critical path and include only the steps needed to prove it.
Don’t hide retries inside the test tool. Count original attempts and recovered operations, and set a retry policy that reflects the client. Otherwise CI may convert a real failure into a green result while increasing dependency pressure.
Prefer effect thresholds to magic exactness
An exact latency equality is rarely a useful CI rule. A fixed threshold can be useful when it expresses a service objective, but it should be paired with an environment contract. Comparative rules can ask whether a named percentile or error segment moved beyond a predeclared effect threshold. Base the value on the path and its known noise, not on a number copied from elsewhere.
Use a quarantine path for an inconclusive result, with ownership and an expiry. Quarantine must not become a permanent bypass. It should preserve the artifact, record why the signal is uncertain, and require a follow-up decision. A failed test that is automatically retried without evidence teaches the team that the test is optional.
Apply stricter criteria to failures that matter most. A stable smoke can require no assertion failures on a login or write path, while allowing an advisory latency observation until the baseline is mature. State the rule in human language next to the CI check.
Make failures reproducible
A failure message should include run link, commit, scenario label, load shape, first failing window, observed value, expected rule, and generator status. Include enough identifiers to replay the data case without exposing secrets. Avoid dumping full response bodies into public logs.
When a check fails, first rerun the same artifact and inputs, not a subtly different script. Compare target and generator health, cache and data state, throughput, and error classes. If the result changes, preserve both outcomes and investigate variance. If it repeats, hand the named segment to its service owner.
Know what CI cannot prove
Give the CI gate a bounded purpose. It can compare a controlled scenario with a nearby baseline and catch a real change in a known signal. It cannot set a universal capacity limit for every deployment shape. Keep infrastructure noise visible by recording runner health, queue wait, environment version, and workload revision. If a gate fails, first check whether the application result changed at the same offered load and whether the run completed its planned lifecycle. If the evidence is incomplete, retry under the same conditions rather than silently widening the threshold. When the test or runtime changes, create a new baseline deliberately and explain why old comparisons no longer apply. A deterministic-enough gate is a decision aid with explicit limits. If you treat it as a perfect measurement system, you get both flaky blocks and unsafe exceptions.
A deterministic smoke cannot prove peak capacity, multi-region behavior, recovery, or absence of rare tail failures. Say so. It can prove that a defined journey still meets a defined contract in a defined environment. That limited claim is useful because it is honest and repeatable.
The CI gate use case shows how to make the gate part of a release workflow. Pair it with scheduled deeper runs and incident-informed experiments. Do not ask one check to answer every performance question.
Consider a check whose p95 moves slightly on every run but whose assertion and error behavior remain stable. Before widening the threshold, compare generator health, offered throughput, cache preparation, and resource contention. If those inputs are uncontrolled, classify the check as advisory and fix the environment. If they are controlled and the same named operation moves repeatedly after one change, the evidence supports a blocking rule. The order matters. A threshold should describe a decision. It should not cover for a missing experiment.
A good CI artifact also records why the test ran and what it cannot establish. Keep the scenario definition, expanded parameters, result link, and comparison context together. Review the artifact when changing the gate itself. That way you improve determinism with evidence, instead of editing numbers until the pipeline goes quiet.
Keep changes to the test itself reviewable. A new fixture mix, timer, assertion, or runtime version can explain a changed result even when application code is untouched. Include those changes in the same review record and establish a fresh baseline deliberately. This preserves the meaning of the gate for the team that depends on it.