tes esting g micr croser services ces from m devel
play

Tes esting g Micr croser services: ces: From m Devel elopmen - PowerPoint PPT Presentation

Tes esting g Micr croser services: ces: From m Devel elopmen ment to Product ction Daniel Bryant @danielbryantuk Rube Goldbergs self-operating napkin 26/10/2018 @danielbryantuk Was Rube Goldberg the first microservice architect?


  1. Tes esting g Micr croser services: ces: From m Devel elopmen ment to Product ction Daniel Bryant @danielbryantuk

  2. Rube Goldberg’s self-operating napkin 26/10/2018 @danielbryantuk

  3. Was Rube Goldberg the first microservice architect? 26/10/2018 @danielbryantuk

  4. tl;dr • A lot of microservice testing attempts I see are at the fringes of a spectrum from “YOLO” to seeking absolute correctness • I believe the key tradeoffs should be around pre-prod vs post-prod tests • Contract testing, API simulation and chaos experimentation can be useful techniques for microservice testing 26/10/2018 @danielbryantuk

  5. @danielbryantuk • Independent Technical Consultant, Product Architect at Datawire • Architecture, DevOps, Java, microservices, cloud, containers oreil.ly/2E63nCR • Continuous Delivery (CI/CD) advocate • Leading change through technology and teams bit.ly/2jWDSF7 26/10/2018 @danielbryantuk

  6. Testing microservice 101 26/10/2018 @danielbryantuk

  7. Testing: Core concepts /lisacrispin.com/2011/11/08/using-the-agile-testing-quadrants/ martinfowler.com/bliki/TestPyramid.html 26/10/2018 @danielbryantuk

  8. The test pyramid (is just a model) • This model was created before the rise in popularity of microservices… • …but after David Parnas’ modularity • Applies at system and service level • Probably needs updating… martinfowler.com/bliki/TestPyramid.html 26/10/2018 @danielbryantuk

  9. New testing strategies for microservices http://distributed-systems-observability-ebook.humio.com/ https://medium.com/@copyconstruct/testing-microservices-the-sane-way-9bb31d158c16 26/10/2018 @danielbryantuk

  10. Microservice test funnel https://medium.com/@copyconstruct/testing-microservices-the-sane-way-9bb31d158c16 26/10/2018 @danielbryantuk

  11. General lessons learned (and mistakes made) 26/10/2018 @danielbryantuk

  12. I’m not suggesting that you avoid unit tests https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf https://www.youtube.com/watch?v=ZMbqbXxRthE 26/10/2018 @danielbryantuk

  13. I’m not suggesting that you avoid unit tests • 77% of production failures can be reproduced by a unit test • Testing error handling code could have prevented 58% of catastrophic failures • 35% of catastrophic failures • Empty error handler, or contains FIXME https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf • Error handler aborts system 26/10/2018 @danielbryantuk

  14. Integration/component tests If your component/integration tests look too complicated, they probably are Coupling and cohesion apply to everything! 26/10/2018 @danielbryantuk

  15. https://itnext.io/microservice-testing-coupling-and-cohesion-all-the-way-down-a9f100cda523 26/10/2018 @danielbryantuk

  16. End-to-end tests Representational data is often the weakest link Understand your data ”shape” and volume 26/10/2018 @danielbryantuk

  17. Synthetic datastores/middleware 26/10/2018 @danielbryantuk

  18. General strategies • Test outside-in • Acceptance tests for system and services • “LUFD” the context and TDD the API • Virtualise dependencies • Test contracts of unstable APIs • Invest in monitoring, synthetic txns and chaos engineerings (in this order) https://itnext.io/microservice-testing-coupling-and-cohesion-all-the-way-down-a9f100cda523 26/10/2018 @danielbryantuk

  19. Let’s look at some techniques in more depth 26/10/2018 @danielbryantuk

  20. Contract (Testing syntax) 26/10/2018 @danielbryantuk

  21. So, where do contracts fit into this… Focused on system Contract Tests Focused on service/function martinfowler.com/bliki/TestPyramid.html 26/10/2018 @danielbryantuk

  22. API contracts • APIs are service contracts • Many are producer-driven • It’s possible to design outside-in: • Consumer-Driven Contracts • martinfowler.com/articles/consumerDrivenContracts.html 26/10/2018 @danielbryantuk

  23. CDC concepts https://codefresh.io/docker-tutorial/how-to-test-microservice-integration-with-pact/ 26/10/2018 @danielbryantuk

  24. 4. 3. CDC workflow 2. 1. Consumer writes a contract that defines an interaction with the API. 1. For HTTP RPC this is simply request with acceptable params and response 2. Often the contract can be autogenerated from a test 1. 4. 2. Consumer issues a pull request to producer containing the contract 3. Producer runs the SUT (via pipeline) and tests if the contract is valid 1. If yes, then simply accept the pull request 2. If no, then modify the SUT to meet the contract (this often involves inter- team communication), and then accept the pull request 4. Producer deploys (via pipeline), and consumer deploys (via pipeline) 1. Take care in regards to backwards compatibility 26/10/2018 @danielbryantuk

  25. CDC frameworks cloud.spring.io/spring-cloud-contract github.com/spring-cloud-samples/spring-cloud-contract-samples docs.pact.io 26/10/2018 @danielbryantuk

  26. CDC for messaging • What about messaging? • Message schema are an API • Pact supports AMQP contracts • www.infoq.com/presentations/contracts-streaming-microservices 26/10/2018 @danielbryantuk

  27. CDC for messaging www.infoq.com/presentations/contracts-streaming-microservices docs.confluent.io/current/schema-registry/docs/maven-plugin.html 26/10/2018 @danielbryantuk

  28. Contract testing musings • Great in low trust or poor communication organisations • Act as a cue for a conversation • Can be used to implement TDD for the API • Resource intensive to create and maintain 26/10/2018 @danielbryantuk

  29. API Simulation (Testing semantics) 26/10/2018 @danielbryantuk

  30. 26/10/2018 @danielbryantuk

  31. 26/10/2018 @danielbryantuk

  32. 26/10/2018 @danielbryantuk

  33. 26/10/2018 @danielbryantuk

  34. 26/10/2018 @danielbryantuk

  35. 26/10/2018 @danielbryantuk

  36. 26/10/2018 @danielbryantuk

  37. API simulation musings • Great when a dependency is “expensive” to access or tricky to mock • Useful when failure modes of dependency are hard to recreate • Simulations can be fragile and/or complicated 26/10/2018 @danielbryantuk

  38. 26/10/2018 @danielbryantuk

  39. 26/10/2018 @danielbryantuk

  40. Fault injection (Testing resilience) 26/10/2018 @danielbryantuk

  41. When engineers hear the phrase “chaos engineering” 26/10/2018 @danielbryantuk

  42. 26/10/2018 @danielbryantuk

  43. When non technical folk hear the phrase “chaos engineering” 26/10/2018 @danielbryantuk

  44. 26/10/2018 @danielbryantuk

  45. https://principlesofchaos.org/ 26/10/2018 @danielbryantuk

  46. https://chaostoolkit.org/ 26/10/2018 @danielbryantuk

  47. https://www.gremlin.com/ https://www.infoq.com/news/2018/10/gremlin-alfi 26/10/2018 @danielbryantuk

  48. Chaos engineering prerequisites Tammy Butow’s three prerequisites: 1. High severity incident management 2. Monitoring 3. Measure the impact of downtime https://www.infoq.com/news/2018/03/resilient-systems-chaos-engineer 26/10/2018 @danielbryantuk

  49. Chaos engineering prerequisites Tammy Butow’s three prerequisites: 1. High severity incident management 2. Monitoring 3. Measure the impact of downtime https://www.infoq.com/news/2018/03/resilient-systems-chaos-engineer 26/10/2018 @danielbryantuk

  50. Chaos engineering musings • Great for codifying/asserting system quality attributes • Can prompt team to think about monitoring and DR/BC • Can cause a lot of damage if approached casually 26/10/2018 @danielbryantuk

  51. Wrapping up 26/10/2018 @danielbryantuk

  52. Conclusion • Try and avoid microservice testing strategies that are solely YOLO or attempting to seek absolute correctness • Balance pre-prod (generally technology facing and supporting the team) vs post-prod tests (generally business facing and critiquing the product) • Contract testing, API simulation and chaos experimentation can be useful techniques for microservice testing 26/10/2018 @danielbryantuk

  53. Thanks for listening… oreil.ly/2E63nCR Twitter: @danielbryantuk Email: daniel.bryant@tai-dev.co.uk Writing: https://www.infoq.com/profile/Daniel-Bryant Talks: https://www.youtube.com/playlist?list=PLoVYf_0qOYNeBmrpjuBOOAqJnQb3QAEtM 26/10/2018 @danielbryantuk

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend