Pacts to the rescue! - Let's...

26
Pacts to the rescue! Making your microservices play nicely together with Consumer Driven Contracts Beth Skurrie @bethesque / @pact_up [email protected]

Transcript of Pacts to the rescue! - Let's...

Page 1: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Pacts to the rescue!Making your microservices play nicely together !

with Consumer Driven Contracts!!!!Beth Skurrie!@bethesque / @[email protected]

Page 2: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

!!“Integrated tests are a scam. !A self replicating virus !that threatens !the very health of your codebase, !your sanity, !and I'm not exaggerating when I say, !your life.”!

- JB Rainsberger

Page 3: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Integrated Tests: The Problems

" Slow!" Easy to break!" Hard to fix!" Scales combinatorially

3 classes, 4 code paths each!4 * 4 * 4 = 64 tests

Page 4: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

A B

mock

Test Symmetry… how it works

Page 5: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Test 1

Test 2

Test 3

Integrated tests

Page 6: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!
Page 7: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

" Lack of automated tools!" Relies on developer eternal vigilance!" Does not scale

Test Symmetry: The Problem

Page 8: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Do we have the technology to achieve test symmetry?

Posed to Dius

Page 9: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

System Integration Tests: The WORST

" Slower!" Easier to break!" Harder to fix!" Scales BADLY" Lots of set up!" Flakey!" Extra infrastructure

Page 10: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Pact to the rescue!!!

Page 11: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

A B

mock

C P

pact

Pact… how it works

Page 12: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Problems with... Solved by Pact

Test symmetry!" No automated tools!" Relies on developer eternal

vigilance - not sustainable!" Does not scale!!Integrated tests!" Slow!" Easy to break!" Hard to fix!" Scales combinatorially

Test symmetry!" Automatically enforced!!Integrated tests!" Fast!" Low set up!" Reliable!" Easier to debug!" Standalone CI build!" No extra infrastructure!" Scales linearly

Page 13: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Better API design!

Page 14: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Arrange - set up mock server

Page 15: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Arrange - set up expectations

Page 16: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Act and Assert

Page 17: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!
Page 18: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Set up provider

Page 19: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Set up test dataConsumer assumed:

Provider complies:

Page 20: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Verify: Success!

Page 21: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

What’s in it for me?

• Black box testing - quicker turn around for builds!• Exploratory testing - hints as to design

weaknesses!• All testing - catch bugs before committing,

support for continuous deployment!

Page 22: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

“How is it working for you?”

Before Pact!" A “certification” environment that took 2 months to set up!" Deploy all the things => deploy new thing => integration tests

=> pass ? deploy to production : try again!" Does not scale!!With Pact!" 40+ microservices using Pact!" Green standalone CI builds ? deploy to production

Page 23: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

ProviderConsumer

In summary...

UI AppProvid

er Client

API App DB

Integrated test

Test symmetry with Pact

Page 24: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Pact allows you to:

" Reduce your defect turn around time!" Reduce the number of bugs that are committed into the

codebase - immediate feedback on potential integration breakages!

" Allows you to modify components with agility!" Have confidence that all the services in your system will work

together!" Throw away your integration tests!!!

Page 25: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

Pact!!Makes your microservices play nicely together !with Consumer Driven Contracts!!github.com/realestate-com-au/pact!@pact_up!!!Beth [email protected] @bethesque

Page 26: Pacts to the rescue! - Let's Testlets-test.com/wp-content/uploads/2014/09/Beth-Skurrie-pactletstesto… · Making your microservices play nicely together ! with Consumer Driven Contracts!!!!

P

publish pact latest pact?

tag “prod” pact

deploy script

prod pact?

C

Pact Broker