Consumer-Driven Contracts with Pact (Sydney API Days 2015)

Post on 16-Jul-2015

674 views 0 download

transcript

Pacts to the rescue!Making your microservices play nicely together

with Consumer Driven Contracts

Beth Skurrie@bethesque / @pact_upbskurrie@dius.com.au

“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

Integrated Tests: The Problems

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

3 classes, 4 code paths each4 * 4 * 4 = 64 tests

A B

mock

Test Symmetry… how it works

Test 1

Test 2

Test 3

Integrated tests

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

Test Symmetry: The Problem

Do we have the technology to achieve test symmetry?

Posed to DiUS

Slower Easier to break

Harder to fix Scales BADLY

Lots of infrastructure

False negativesLots of set up

System Integration Tests

Pact to the rescue!!!

A B

mock

C P

pact

Pact… how it works

Slower Easier to break

Harder to fix Scales BADLY

Lots of infrastructure

False negativesLots of set up

System Integration Tests

Fast Stable

Easy to debug Reliable

No extra infrastructure

Low setupScales linearly

Pact

Better API design!

Arrange - set up mock server

Arrange - set up mock server

Arrange - set up mock server

Arrange - set up expectations

Arrange - set up expectations

Arrange - set up expectations

Act and Assert

Act and Assert

Act and Assert

Act and Assert

Act and Assert

Set up test data

Consumer assumed:

Provider complies:

Set up test data

Consumer assumed:

Provider complies:

Verify: Fail

Verify: Success!

Postel’s law

Sharing pacts

P

publish pact latest pact

C

Pact Broker

Pact Broker - Share pacts

Pact Broker - Autogenerated documentation

Pact Broker - Network graph

Support

! JSON is language independent! Ruby! JVM (Java and Scala)! .net! Javascript (consumer side, provider side WIP)! Pact specification

“How is it working for you?”

Fast feedback in isolation +

Early detection +

Rapid recovery

Pact allows you to:

! Combine the advantages of integrated tests and test symmetry! Mitigates the shortcomings of each method! Allows you to modify components with agility - quick feedback

on potential breakages! Have confidence that all the services in your system will work

together! Throw away your integration tests!!!

PactMakes your microservices play nicely together with Consumer Driven Contracts

github.com/realestate-com-au/pact@pact_up

Beth Skurriebskurrie@dius.com.au @bethesque

• Regular expressions & type based matching

• Why doesn’t Pact use JSON Schema?

• How to avoid versioning APIs • How to use Pact between teams • Should I use Pact for testing external APIs?

• How not to do it • And moar!