Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Avoiding common pitfalls with modern microserv...

Avoiding common pitfalls with modern microservices testing

Have you ever wondered why your microservices break in production after all the tests have passed during CI/CD? Have you ever wondered if you’re testing too much or too little? If you want to learn about common pitfalls and how to catch them at build time rather than at runtime, this session is for you!

In this session we’ll share some common battle scars from our experiences in the field. Additionally, we will introduce the testing pyramid and explain why it is important in helping to continuously deploy microservices independently without fear. We will demonstrate, through a test-driven development approach, how the combination of Pact contract testing combined with Quarkus developer joy can help prevent your microservices from breaking in production.

Holly Cummins

April 05, 2023
Tweet

More Decks by Holly Cummins

Other Decks in Programming

Transcript

  1. Holly Cummins Sr. Principal Software Engineer Red Hat @holly_cummins Eric

    Deandrea Sr. Principal Developer Advocate Red Hat @edeandrea Avoiding common pitfalls with modern microservices testing
  2. @holly_cummins @edeandrea #DevNexus #RedHat Free copy (while they last)! Come

    see Eric at the Red Hat booth 
 (at 2:45 PM today, not now) https://red.ht/quarkus-spring-devs
  3. @holly_cummins @edeandrea #DevNexus #RedHat Disclaimer! We are not testers. (or

    even test experts) That’s ok– testing is every developer’s job!
  4. @holly_cummins @edeandrea #DevNexus #RedHat Netflix microservice architecture Testing with microservices

    is easy! Everything is decoupled! But….. If you only test the points, And not the lines…. Does the thing actually work?
  5. @holly_cummins @edeandrea #DevNexus #RedHat “It is all that is left

    unsaid upon which tragedies are built.” - Kreia, Star Wars Knights of the Old Republic II: The Sith Lords
  6. @holly_cummins @edeandrea #DevNexus #RedHat “You lied to me. How many

    other lies have I been told by the Council? And how do you know that you even have the truth?” – Anakin Skywalker
  7. @holly_cummins @edeandrea #DevNexus #RedHat “Many of the truths that we

    cling to depend on our viewpoint.” — Obi-Wan Kenobi, Return of the Jedi
  8. end-to-end tests unit tests integration tests low effort high realism

    tests with application server test REST endpoints tests with a database
  9. @holly_cummins @edeandrea #DevNexus #RedHat our mock our code ✔ tests

    ✘ reality our code their actual code Why mocks aren’t enough
  10. @holly_cummins @edeandrea #DevNexus #RedHat Demo The limitations of unit tests

    https://github.com/edeandrea/pact-quarkus-wookie-carpet-demo
  11. @holly_cummins @edeandrea #DevNexus #RedHat “Will someone get this big walking

    carpet out of my way?” – Princess Leia Demo The limitations of unit tests https://github.com/edeandrea/pact-quarkus-wookie-carpet-demo
  12. @holly_cummins @edeandrea #DevNexus #RedHat “Will someone get this big walking

    carpet out of my way?” – Princess Leia Demo The limitations of unit tests https://github.com/edeandrea/pact-quarkus-wookie-carpet-demo
  13. @holly_cummins @edeandrea #DevNexus #RedHat ✔ our tests ✔ their tests

    ✔ reality our code their code contract test mock functional test A better mock
  14. @holly_cummins @edeandrea #DevNexus #RedHat ✔ our tests ✘ their tests

    ✘ reality our code their code contract test mock functional test A better mock
  15. @holly_cummins @edeandrea #DevNexus #RedHat ✘ our tests ✔ their tests

    ✘ reality A better mock our code their code contract test mock functional test
  16. @holly_cummins @edeandrea #DevNexus #RedHat Some contract testing options • Pact

    • Spring Cloud Contract • OpenAPI schema validation + mock generation • Prism • Schemathesis
  17. @holly_cummins @edeandrea #DevNexus #RedHat Team maintaining the “other side” is

    not using Pact Consumer and provider do not have good communication P ! P
  18. @holly_cummins @edeandrea #DevNexus #RedHat Consumers can’t be identified (i.e. for

    public APIs) Consumer and provider do not have good communication Team maintaining the “other side” is not using Pact
  19. @holly_cummins @edeandrea #DevNexus #RedHat Can’t control data being used for

    provider responses Consumer and provider do not have good communication Team maintaining the “other side” is not using Pact Consumers can’t be identified (i.e. for public APIs)
  20. @holly_cummins @edeandrea #DevNexus #RedHat “Pass-through” APIs Consumer and provider do

    not have good communication Team maintaining the “other side” is not using Pact Consumers can’t be identified (i.e. for public APIs) Can’t control data being used for provider responses
  21. @holly_cummins @edeandrea #DevNexus #RedHat “Pass-through” APIs Consumer and provider do

    not have good communication Team maintaining the “other side” is not using Pact Consumers can’t be identified (i.e. for public APIs) Can’t control data being used for provider responses
  22. @holly_cummins @edeandrea #DevNexus #RedHat Functional, performance, or load testing Consumer

    and provider do not have good communication Team maintaining the “other side” is not using Pact Consumers can’t be identified (i.e. for public APIs) Can’t control data being used for provider responses “Pass-through” APIs
  23. @holly_cummins @edeandrea #DevNexus #RedHat Functional, performance, or load testing Consumer

    and provider do not have good communication Team maintaining the “other side” is not using Pact Consumers can’t be identified (i.e. for public APIs) Can’t control data being used for provider responses “Pass-through” APIs
  24. @holly_cummins @edeandrea #DevNexus #RedHat Pact vs Spring Cloud Contract? •

    Pact is polyglot! • Pact generates JSON acceptance contracts (pacts) • Pact is consumer-driven whereas SCC is provider-driven • Pact allows consumers to specify provider test states • Pact broker
  25. @holly_cummins @edeandrea #DevNexus #RedHat …but I use Swagger/OpenAPI It has

    the same syntax, but the semantics are different. It looks the same, but the behaviour is different.
  26. @holly_cummins @edeandrea #DevNexus #RedHat …but I use Swagger/OpenAPI It has

    the same syntax, but the semantics are different. It looks the same, but the behaviour is different. Looks like a storm trooper. Behaves like Luke. (because it it is Luke)
  27. @holly_cummins @edeandrea #DevNexus #RedHat how annoying, the provider is returning

    204. the contract expects 404, so my test is broken. quarkus will return 204 by default. 204 vs 404 - it’s more about the theory behind REST...if a caller asks for a resource the server doesn't have, it should be a 404 - same way if a user types in an invalid URL into the browser ugh, it’s too late at night to care about REST theory. I’m just going to update the expectations in the test to match reality. what?! why is my other contract test broken now? 
 oh … because what I’m changing is a mock…. Based on a true story….
  28. @holly_cummins @edeandrea #DevNexus #RedHat Kubernetes Native Java with Quarkus Deployment

    Developer Joy • Quickly & easily build Kubernetes-Native Java applications • Industry leader in startup time and memory utilization for native and JVM applications • One step native executable generation • Leverage existing Java, Jakarta, MicroProfile, & Spring expertise • Imperative & reactive APIs side-by-side • Live coding with zero config https://www.infoq.com/articles/native-java-quarkus