RousselTMLEARNING

DevOps

Testing continuously and in production: contracts, performance and chaos engineering

Going beyond the test pyramid: component tests with Testcontainers, contract tests (Pact), mutation testing, performance tests with thresholds in the pipeline, chaos engineering (principles, tools, game days) and testing in production (canary, synthetics, shadow traffic).

1. A complete test strategy #

Shift-left and shift-right.

Beyond the pyramid #

Continuous test strategy
Test typeWhat it provesTools
Componenta service works with its real dependencies (database, queue) started in throwaway containersTestcontainers
Contractan API provider honours what its consumers expect, without a shared environmentPact, Spring Cloud Contract
Mutationtests really catch errors: the code is altered and a test must failStryker, PIT
Property-baseda rule holds for thousands of generated inputsHypothesis, fast-check
Best practice : Code coverage tells which lines run, not whether they are checked: the mutation score is a much better indicator of test quality.

2. Performance #

Measure before users do.

Performance testing #

TypeQuestion
Loaddo we handle expected traffic with target response times?
Stresswhere is the breaking point, and how does the system degrade?
Spikewhat happens during a sudden surge (sales, campaign)?
Soakdo memory or connection leaks appear after hours?
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [{ duration: '1m', target: 50 }, { duration: '3m', target: 50 }, { duration: '30s', target: 0 }],
  thresholds: {
    http_req_failed: ['rate<0.01'],          // less than 1% errors
    http_req_duration: ['p(95)<300'],        // 95% of requests under 300 ms
  },
};

export default function () {
  const res = http.get(`${__ENV.BASE_URL}/api/produits`);
  check(res, { 'status 200': (r) => r.status === 200 });
  sleep(1);
}

Thresholds turn a load test into a quality gate: if a threshold is crossed, k6 exits with code 99 and the pipeline fails. Always compare with a baseline measured on the previous version.

3. Chaos engineering #

Cause failures so you no longer suffer them.

Chaos engineering #

Chaos experiment
  • Principles (Principles of Chaos Engineering): define a measurable steady state, state a hypothesis, inject realistic events (pod failure, latency, zone loss), experiment as close to production as possible, automate and minimize the blast radius.
  • Tools: Chaos Mesh and LitmusChaos (Kubernetes), AWS Fault Injection Service, Azure Chaos Studio, Toxiproxy (network latency and cuts in tests), Gremlin.
  • A game day gathers the team to play out a failure scenario: alerts, runbooks and coordination are checked, not just the technology.
apiVersion: chaos-mesh.org/v1alpha1
kind: PodChaos
metadata:
  name: kill-one-cart-pod
  namespace: staging
spec:
  action: pod-kill
  mode: one                    # a single pod: limited blast radius
  selector:
    namespaces: [staging]
    labelSelectors: { app: cart }
Watch out : No chaos without observability and a stop button: if you cannot measure the steady state, you cannot interpret the experiment or stop it in time.

4. In production #

The last safety net.

Testing in production #

  • Canary with automated analysis: the new version gets a share of traffic and its metrics are compared with the old one (Argo Rollouts, Flagger).
  • Synthetic monitoring: robots play critical journeys continuously from several regions.
  • Feature flags: enable a feature for a few internal users, then widen.
  • Shadow traffic: duplicate real requests to the new version without returning its responses to users.

Commands to know #

Commands to know
  • k6 run --env BASE_URL=https://recette.exemple.fr charge.js : load test with thresholds
  • echo $? # 99 = seuil dépassé : k6 exit code
  • kubectl apply -f panne-pod.yaml : start a Chaos Mesh experiment
  • npx stryker run : mutation testing (JavaScript)
  • pact-broker can-i-deploy --pacticipant panier --version $SHA --to-environment production : check contracts before deploying

Sources #

Related articles

DevOps, Agile, Lean and ITSM: frameworks that fit together

Placing DevOps among other frameworks: the agile manifesto, Scrum and Kanban, Lean thinking (flow, waste, the…

Leading a DevOps transformation: start, change, measure

Running a DevOps transformation in an organization: assess the starting point, choose a pilot team, lead chan…

Organizing DevOps: value streams, teams and a blameless culture

Set up a DevOps organization: value chain and value stream mapping, Team Topologies, « you build it, you run …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!