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

tes esting g micr croser services ces from m devel
SMART_READER_LITE
LIVE PREVIEW

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?


slide-1
SLIDE 1

Tes esting g Micr croser services: ces: From m Devel elopmen ment to Product ction

Daniel Bryant @danielbryantuk

slide-2
SLIDE 2

Rube Goldberg’s self-operating napkin

26/10/2018 @danielbryantuk

slide-3
SLIDE 3

Was Rube Goldberg the first microservice architect?

26/10/2018 @danielbryantuk

slide-4
SLIDE 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

slide-5
SLIDE 5

@danielbryantuk

  • Independent Technical Consultant, Product Architect at Datawire
  • Architecture, DevOps, Java, microservices, cloud, containers
  • Continuous Delivery (CI/CD) advocate
  • Leading change through technology and teams

26/10/2018 @danielbryantuk

bit.ly/2jWDSF7

  • reil.ly/2E63nCR
slide-6
SLIDE 6

Testing microservice 101

26/10/2018 @danielbryantuk

slide-7
SLIDE 7

Testing: Core concepts

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

slide-8
SLIDE 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…

26/10/2018 @danielbryantuk martinfowler.com/bliki/TestPyramid.html

slide-9
SLIDE 9

New testing strategies for microservices

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

slide-10
SLIDE 10

Microservice test funnel

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

slide-11
SLIDE 11

General lessons learned (and mistakes made)

26/10/2018 @danielbryantuk

slide-12
SLIDE 12

I’m not suggesting that you avoid unit tests

26/10/2018 @danielbryantuk https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf https://www.youtube.com/watch?v=ZMbqbXxRthE

slide-13
SLIDE 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
  • Error handler aborts system

26/10/2018 @danielbryantuk https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf

slide-14
SLIDE 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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

End-to-end tests

Representational data is often the weakest link Understand your data ”shape” and volume

26/10/2018 @danielbryantuk

slide-17
SLIDE 17

Synthetic datastores/middleware

26/10/2018 @danielbryantuk

slide-18
SLIDE 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)

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

slide-19
SLIDE 19

Let’s look at some techniques in more depth

26/10/2018 @danielbryantuk

slide-20
SLIDE 20

Contract (Testing syntax)

26/10/2018 @danielbryantuk

slide-21
SLIDE 21

So, where do contracts fit into this…

26/10/2018 @danielbryantuk martinfowler.com/bliki/TestPyramid.html

Contract Tests Focused on system Focused on service/function

slide-22
SLIDE 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

slide-23
SLIDE 23

CDC concepts

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

slide-24
SLIDE 24

CDC workflow

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

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

1. 2. 3. 4. 4.

slide-25
SLIDE 25

CDC frameworks

26/10/2018 @danielbryantuk

docs.pact.io

cloud.spring.io/spring-cloud-contract github.com/spring-cloud-samples/spring-cloud-contract-samples

slide-26
SLIDE 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

slide-27
SLIDE 27

CDC for messaging

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

slide-28
SLIDE 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

slide-29
SLIDE 29

API Simulation (Testing semantics)

26/10/2018 @danielbryantuk

slide-30
SLIDE 30

26/10/2018 @danielbryantuk

slide-31
SLIDE 31

26/10/2018 @danielbryantuk

slide-32
SLIDE 32

26/10/2018 @danielbryantuk

slide-33
SLIDE 33

26/10/2018 @danielbryantuk

slide-34
SLIDE 34

26/10/2018 @danielbryantuk

slide-35
SLIDE 35

26/10/2018 @danielbryantuk

slide-36
SLIDE 36

26/10/2018 @danielbryantuk

slide-37
SLIDE 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

slide-38
SLIDE 38

26/10/2018 @danielbryantuk

slide-39
SLIDE 39

26/10/2018 @danielbryantuk

slide-40
SLIDE 40

Fault injection (Testing resilience)

26/10/2018 @danielbryantuk

slide-41
SLIDE 41

When engineers hear the phrase “chaos engineering”

26/10/2018 @danielbryantuk

slide-42
SLIDE 42

26/10/2018 @danielbryantuk

slide-43
SLIDE 43

When non technical folk hear the phrase “chaos engineering”

26/10/2018 @danielbryantuk

slide-44
SLIDE 44

26/10/2018 @danielbryantuk

slide-45
SLIDE 45

26/10/2018 @danielbryantuk

https://principlesofchaos.org/

slide-46
SLIDE 46

26/10/2018 @danielbryantuk

https://chaostoolkit.org/

slide-47
SLIDE 47

26/10/2018 @danielbryantuk

https://www.gremlin.com/ https://www.infoq.com/news/2018/10/gremlin-alfi

slide-48
SLIDE 48

Chaos engineering prerequisites

Tammy Butow’s three prerequisites:

  • 1. High severity incident management
  • 2. Monitoring
  • 3. Measure the impact of downtime

26/10/2018 @danielbryantuk https://www.infoq.com/news/2018/03/resilient-systems-chaos-engineer

slide-49
SLIDE 49

Chaos engineering prerequisites

26/10/2018 @danielbryantuk https://www.infoq.com/news/2018/03/resilient-systems-chaos-engineer

Tammy Butow’s three prerequisites:

  • 1. High severity incident management
  • 2. Monitoring
  • 3. Measure the impact of downtime
slide-50
SLIDE 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

slide-51
SLIDE 51

Wrapping up

26/10/2018 @danielbryantuk

slide-52
SLIDE 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

slide-53
SLIDE 53

Thanks for listening…

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

  • reil.ly/2E63nCR