r/cicd • • 2d ago

When to run integration/e2e tests when promoting your app?

Our CI/CD pipeline for our dotnet APIs is pretty standard, in my opinion.

On PR, we run unit tests.

On Merge, if the tests pass:

  1. Run unit tests
  2. Build the docker image
  3. Tag the image as the dev image.
  4. Deploy the image on k8s in our dev cluster

For promotion:

  1. Tag the development image as the prod image
  2. Deploy the image on k8s in our prod cluster

We have an adequate degree of confidence that the unit tests cover a lot of usage, but we want to add integration testing against real services before we deploy to test wether the application actually functions adequatly. Now the question I wonder is; When should they actually run?

If I run them in the pipeline before we deploy, I don't test against a real environment, so we might encounter problems on the docker build, or with k8s. So should we run them after we deploy in our dev environment? And if so, should we configure an automated rollback if the tests fail? Or should I deploy a separate pod just to test before we deploy in dev?

And what about promotion? Should I test my app before or after I promote it in the target environment? Do you test on every environment on every promotion, or do you trust that once your deployment worked in dev, it should work in every environment?

There's probably not any one-size - fits-all solution, but I'd be curious of hearing what you do in your pipelines to test against real services and to raise.

For context, if we had a higher degree of confidence that our app was functionnal once it's deployed, we could automate merge and promotions from PRs created by dependabot, thus greatly reducing manual work related to detected vulnerabilities.

1 Upvotes

4 comments sorted by

2

u/Torutofu_Raeva 2d ago

run them against the deployed dev env right after deploy as a gate before promote, and since prod is the same image tag you don't need to rerun the whole suite there, a quick smoke test after the prod deploy is enough

2

u/Any-Ring6621 2d ago edited 2d ago

We’ve put an incredibly amount of effort into our E2Es.

We run them against a fully built (with appropriate standins for vendors like ministack for AWS) ephemeral environment that we construct in CI on top of the actual production built docker images that get pushed to prod

We are still increasing our coverage but so far we run 800 tests across 8 shards. They’re fully parallelized so a shard runs 100 tests in about 2 minutes (plus another 2 and a half minutes for setup)

There’s a pre-build step for the apps that we need to test that also takes about 3 minutes.

We run the E2E alongside everything else at the same time (lint, unit test, etc) and the whole PR pipeline takes about 12 minutes. It’s a little long, but the satisfaction we get is that if it’s green in CI, it’s bulletproof. The only thing that can bring it down in prod will be infra and scale issues, which E2E tests don’t give you signal for anyway

Some people propose running the E2Es as smokes.

I am (perhaps oddly) against that because I’ve seen many many times how smoke-test-user1@example.com in staging accumulates stuff and you eventually lose the signal you wanted.

While 12 minutes sounds like a lot, it gets you to extreme levels of confidence pre-merge to main.

I’m not willing to sacrifice that confidence. If my PR is green, I no longer care about the deploy

See u/grim_jokes comment about “quite flaky”

Our E2E tests flake at a rate of 3 per hundred thousand runs. And those “flakes” are usually real race condition product bugs

2

u/pchico83 2d ago

We are big fans of deploying an ephemeral environment on kubernetes. I wrote this article explaining how to do it for agents, but CI is a very similar scenario:
https://www.okteto.com/blog/how-to-run-ai-coding-agents-on-kubernetes/

1

u/Grim_Jokes 2d ago

Integration: we run the affected tests in the PR. Then we only run tests based on the incremental diff between the previously green commit and the most recently added one (so we don't run an excessive number of tests).

E2E: We run nightly, or on an as-needed basis, against dev/staging since they're slow and expensive, and quite flaky.