AI Hints
Home›CI/CD with GitHub Actions Tutorial›Smoke Tests, Rollbacks, and Flags
CI/CD with GitHub Actions · Lesson 94 of 138

Smoke Tests

Is it really up?.

⏱ 2 min read▶ Video at 1:48:35🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

A deploy step that finishes without errors doesn't prove the app works. Maybe it crashed on start, or can't reach its database. A smoke test is a quick check, right after deploying, that the app is really up.

Smoke Tests
From the video: Smoke Tests
  • Deploy finished
  • But does it work?
  • A quick check after

A health endpoint

Many apps have a health endpoint, a URL that answers if the app is fine. We start a tiny Python server in the background. Curl asks for slash health, and gets status ok. A missing page gives a four oh four error.

Terminal
python3 serve.py & for i in $(seq 1 50); do curl -s localhost:8000/health > /dev/null && break; done
curl -s localhost:8000/health; echo
{"status": "ok"}
curl -s -o /dev/null -w "%{http_code}\n" localhost:8000/nope
404

The smoke test script

Cat shows the smoke test. It retries until the app answers, then checks slash health, and fails the step if it doesn't answer. While the server runs, the smoke test passes. When we stop the server, it fails, and in a pipeline, that would stop the release.

Terminal
cat smoke.sh
url=http://localhost:8000/health
for i in $(seq 1 50); do
  curl -sf "$url" > /dev/null && break
done
if curl -sf "$url"; then
  echo; echo "Smoke test passed"
else
  echo "Smoke test FAILED"; exit 1
fi
python3 serve.py & bash smoke.sh
{"status": "ok"}
Smoke test passed
kill %1; bash smoke.sh
Smoke test FAILED

Summary

Smoke tests check that a fresh deploy really works, often with a health endpoint. If they fail, stop, or roll back. Next, rolling back.

Key takeaways
  • /health endpoint
  • Check right after deploy
  • Fail the job
Next up: Rollbacks — undo a bad release