improve collaboration and confidence with consumer-driven contracts

21
Consumer-driven contracts Improving collaboration and confidence @PierreVincent March 21st, 2017 PIPELINE

Upload: pierre-vincent

Post on 11-Apr-2017

123 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Improve collaboration and confidence with Consumer-driven contracts

Consumer-driven contractsImproving collaboration and confidence

@PierreVincent

March 21st, 2017

PIPELINE

Page 2: Improve collaboration and confidence with Consumer-driven contracts

Pierre VincentTechnical Team Lead at Newsweaver

techblog.newsweaver.com

@PierreVincent

Page 3: Improve collaboration and confidence with Consumer-driven contracts

From this... … to this.

Page 4: Improve collaboration and confidence with Consumer-driven contracts

LoginService

UserService

APIGET /users/pierre

{ "user": "pierre", "name": "Pierre Vincent", "role": "publisher"}

200 OK

How do we test this?

Page 5: Improve collaboration and confidence with Consumer-driven contracts

Running in Prod Tests Pass in Build

Implement changes

Deployed in Prod

User Service

LoginService

!

✓ ✓ ✓ ✓

{ ... "role": "editor"}

{ ... "roles": ["publisher","editor"]}

Running in Prod

✓ ✓

Page 6: Improve collaboration and confidence with Consumer-driven contracts

Maybe we should have tested before deploying to production…?

Tested what though?

Page 7: Improve collaboration and confidence with Consumer-driven contracts

UsersService

LoginService

IP CheckService

Token Gen

Service

Cert/KeyService

LoginFrontend

We only wanted to

test this bit!

Page 8: Improve collaboration and confidence with Consumer-driven contracts

Contract

LoginService

UserService

API

Authentication Team Users Team

Page 9: Improve collaboration and confidence with Consumer-driven contracts

[docs.pact.io]

PACT Specification

Verification philosophy: Tolerant Reader

Implementation guidelines

Implementations

Page 10: Improve collaboration and confidence with Consumer-driven contracts

LoginService

UserService

API

PactMock

Server

Authentication Team Users Team

PactConsumerUnit Test

Define interaction

Trigger interaction

GeneratePact

PactProvider

Test

SharePact

Replay interaction

Replay & Verify

Play &Record

Page 11: Improve collaboration and confidence with Consumer-driven contracts

Consumer

Provider

Provider State

Request

ExpectedResponse

Login Service

User Service

Given that user 'pierre' exists

Method GETPath /users/pierreHeaders

Accept: application/json

Status 200Headers

Content-Type: application/jsonBody

{ "user": "pierre", "name": "Pierre Vincent", "role": "publisher"}

Interaction

Page 12: Improve collaboration and confidence with Consumer-driven contracts

UserService

API

1. Set Provider State

2. Send Request

3. Verify Response

Interaction Verification Test

INSERT INTO users [...]

GET /users/pierreAccept: application/json

{ "user": "pierre", ...}

{ "user": "pierre", ...}

?

Page 13: Improve collaboration and confidence with Consumer-driven contracts

AuthenticationDev Team

UsersDev Team

CMSDev Team

BillingDev Team

Pact Broker

PACTPACT PACTPACT

PACTPACT

PACTPACT

PACT

PACT

Page 14: Improve collaboration and confidence with Consumer-driven contracts

Pact Broker

DependencyGraphs

Living documentation by example

✓ Versioning

✓ Tagging

✓ REST ApiBuild/Deployment Pipeline integration

Page 15: Improve collaboration and confidence with Consumer-driven contracts

Provider pipeline

Implement changes Get Pacts from Broker Replay & Verify Interactions

Deploy Service

Build

Deploy to EU

PROD-EU

Get Pacts from Broker Replay & Verify Interactions

Stop deployment of incompatible Provider

Stop introduction of breaking change

PROD-US

PROD-EU

Page 16: Improve collaboration and confidence with Consumer-driven contracts

Consumer pipeline

Implement changes

Generate Pacts (Build)

Push Pacts to Broker Tag Pacts

Each Provider verifies Pacts Deploy Service Tag Pacts

Build

Deploy to EU

HEAD

Stop deployment of incompatible

Consumer

HEAD

PROD-EU

Page 17: Improve collaboration and confidence with Consumer-driven contracts

Caution: side-effects may include teams collaborating on API design

Page 18: Improve collaboration and confidence with Consumer-driven contracts

Provider state setup for each interaction

Don’t limit contracts tohappy paths interactions

Automation withindeployment pipeline isn’t trivial

What’s the catch…?

Page 19: Improve collaboration and confidence with Consumer-driven contracts

After 2 years of CDCs...

Increased confidence when coding & deploying

✓Collaborative API design

✓Living API documentation

Page 20: Improve collaboration and confidence with Consumer-driven contracts

Pact docs.pact.io, github.com/pact-foundationSpring Cloud Contract (JVM only) https://cloud.spring.io/spring-cloud-contract

Try it out!

“Pact Matrix” (Beth Skurrie) rea.tech/enter-the-pact-matrix-or-how-to-decouple-the-release-cycles-of-your-microservices

Why should you use CDC for microservices integration teststechblog.newsweaver.com/why-should-you-use-consumer-driven-contracts-for-microservices-integration-tests

Sharing CDCs with Pact Brokertechblog.newsweaver.com/sharing-consumer-driven-contracts-with-pact-broker

More reading...

Page 21: Improve collaboration and confidence with Consumer-driven contracts

techblog.newsweaver.com

Questions?

@PierreVincent