Skip to content

Functional test coverage in distributed systems: what to measure and how

By Melih Sakarya · Published · 6 min read

Bu yazının Türkçesi →

CoverOps run detail: merged coverage of the run and one coverage card per application

Short answer

A functional test in a distributed system runs code in many services, in several languages, sometimes behind Kafka or RabbitMQ. This guide sets out the five numbers worth measuring, where each one breaks, and how CoverOps collects them in one run while the tests are still going.

Short answer: in a distributed system, the code a functional test exercises runs in other processes: services in containers or pods, written in different languages, some of them reached only through a message broker. Measuring it means putting a coverage agent in every one of those services, tying them to one run, and carrying the test's identity across every HTTP call and message, so each line is filed under the test that caused it. With that in place you can read five numbers: per service, per system, per test, for the changed code, and live while the run is still going.

Why functional test coverage is a different problem

Unit test coverage is measured in the process that runs the tests. A functional test, whether an end-to-end browser test, an API test or a contract check, drives a running system. The test runner's process holds almost none of the code under test. The code is in an order service on the JVM, a pricing service in Go, a notification worker in Node.js, and a legacy module in PHP. Three things follow:

  • Coverage has to be recorded where the code runs, in each service, by something that understands that runtime.
  • The pieces have to meet. Ten services each reporting their own number do not tell you what one pipeline's suite reached.
  • The test's identity has to travel. The service that runs the refund logic never sees the test runner; it sees a request from another service, or a message from a topic.

Five numbers worth measuring

  1. Per service. What share of the inventory service did the suite run? Each team wants its own number. With replicas, a line any pod ran counts as covered.
  2. Per system. All services together, each file counted once. This is the number for a release discussion, provided you know which services were measured and which were not.
  3. Per test. Which lines, in which services, did this test run? This is what test selection, failure diagnosis and gap analysis by feature are built on, and it is the first number a distributed system breaks.
  4. Changed code. Of the lines a pull request touched, in whichever services they live, how many did the build's tests execute? This is the number a merge gate should read.
  5. Live. While the run is going: is every service reporting, which steps are arriving, which tests have passed or failed so far? This is what tells you in the first minute, not the last, that a service was started without its agent.

How CoverOps collects them in one run

CoverOps puts an agent inside each service. There are agents for Java, .NET, Node.js, Python, Go and PHP, and they all speak the same protocol: the same run key rules, the same test context headers, the same chain header between services. Every service and every test runner that sends the same run key lands in the same run. In CI that key comes from the build id the agents read on their own (GITHUB_RUN_ID, BUILD_NUMBER, CI_PIPELINE_ID and others); inside a container you pass it in as COVERAGEOPS_RUN_KEY.

The test runner does three things through its CoverOps integration: it opens the run before the first test, labels the traffic of each test, and reports verdicts. A label is three values, sent as headers by an API test:

X-CoverageOps-Test: checkout%3A%3Abuys%20a%20desk
X-CoverageOps-Test-Id: AUT-45
X-CoverageOps-Run: gh-9812

A browser test sets the same three values as one covctx cookie, because a browser cannot add custom headers but sends cookies by itself. An OpenTelemetry-instrumented runner can put them in W3C baggage.

From the first service on, the agents carry the context forward as the three X-CoverageOps-* headers, beside the X-CoverageOps-Trace chain header. How much of that is automatic depends on the runtime: the Java agent forwards it on the common HTTP clients and on Kafka and RabbitMQ without code; Node.js forwards it on http, https and fetch; Go needs one transport line; Python, .NET and PHP put the agent's outbound headers on the call. The series covers each case in depth.

CoverOps run detail: merged coverage of the run and one coverage card per application

Where each number breaks, and what CoverOps does about it

  • A hop that does not carry the context. Its coverage still counts for the run, just not under the test, and the chain stops there. The service map, built from traces, shows a missing hop as a missing edge.
  • Asynchronous work. A consumer may handle a message after the test has moved on, or after the run has closed. Traffic may name a run while it is open or up to 10 minutes after it finished, so a consumer that lags a little still lands in the right run.
  • Parallel tests. When two tests reach one service process at the same time, their lines cannot be told apart by any coverage tool. CoverOps gives every overlapping test the shared window's lines and records the overlap, so no test loses a line. Requests, endpoints, services and methods come from per-request traces and stay exact.
  • Replicas and redeploys. Each pod reports as its own participant and the run shows the service once, pods merged. If a build is redeployed with a changed file while a window is open, earlier coverage of that file is dropped instead of being laid on lines that moved.
  • Environments. Each process names its environment, so test and preprod pods in one run never mix, and the run page can filter by environment.

Watching it while it happens

A run in CoverOps is not a report you wait for. While it is running, the run page shows a live trace feed: each request hop as it arrives, with the service, its methods and lines, and the passed, failed and skipped counts as they change. Each application card shows a green live mark while its service is sending trace frames. The Agents screen lists every replica that is reporting, refreshed every few seconds.

Services in a running CoverOps run, each with a live mark and a coverage percentage that changes as tests run

What you can do with the numbers

  • Find untested paths by service and by test. The run page shows each file line by line, and for every line the tests in the run that executed it.
  • Diagnose a failed test. Its footprint (endpoints, services, methods, lines) is compared with what changed since it last passed.
  • Select tests for a change, skipping a test only when its recorded footprint misses every changed line.
  • Gate a merge on changed-code coverage, even when the change spans several services.

CoverOps service map built from traces, with the edges between services and coverage per service

Limits to know

  • Only code that runs in a process with an agent is measured. Databases, stored procedures, the brokers themselves and third-party services are not.
  • Per-test attribution stops at every hop that does not carry the test context.
  • While tests overlap on one service process, per-test lines are shared, not split.
  • Timers and background queue jobs that do not adopt a message's context start no trace of their own.
  • Branch coverage is reported by the Java and Node.js agents; the others report lines and methods.

The series

The concepts guide explains runs, test context and parallel tests in full. The integration test coverage page has the product summary; for long-lived environments, see the deployed test coverage page.

Related posts

  • Parallel functional tests and per-test coverage: what stays exact, what is shared

    Functional suites run in parallel to fit into CI, and every parallel test hits the same long-running services. Line counters cannot say which of two simultaneous requests ran a line. Here is what CoverOps keeps exact anyway, what it shares and labels, how each agent draws the line, and how to keep the shared part small.

  • Paralel fonksiyonel testlerde test bazında coverage: ne kesin kalır, ne paylaşılır

    Fonksiyonel suite'ler CI süresine sığmak için paralel koşar ve her paralel test aynı uzun ömürlü servislere gider. Satır sayaçları, aynı anda gelen iki istekten hangisinin bir satırı çalıştırdığını söyleyemez. CoverOps'un yine de neyi kesin tuttuğunu, neyi paylaştırıp işaretlediğini, her agent'ın sınırı nasıl çizdiğini ve paylaşılan kısmı nasıl küçük tutacağınızı anlatıyoruz.

  • Changed-code coverage as a merge gate when a change spans services

    Diff coverage from one repository's unit tests cannot see that the new lines in the inventory consumer only run when an end-to-end test places an order. Here is how to gate a merge on the changed lines your functional tests actually ran, in every service, and how to keep a service that did not run from quietly passing the gate.

See which tests reach your own code

We connect one of your services in a demo and show what your tests executed, and what they never reached.