Move fast and consumer driven contract test things

Download Move fast and consumer driven contract test things

Post on 21-Jan-2018

60 views

Category:

Software

3 download

Embed Size (px)

TRANSCRIPT

<ol><li> 1. Making SoundClouds -services safe(r) to deploy Move Fast and Consumer-Driven- Contract-Test Things XP Days Ukraine 2017 </li><li> 2. 2.5 years @ SoundCloud Monetization Team Backend Engineer @alonpeer </li><li> 3. About SoundCloud a cloud full of sounds 135M tracks, 175M listeners, 12 hours/minute 300+ services / 50+ teams </li><li> 4. Agenda Testing, monolith style My first steps @ SoundCloud Introducing contract tests Pactifying our services Caveats QA Q&amp;A </li><li> 5. Testing, monolith style </li><li> 6. One service, one client API changes are easy One client team to sync with for migrations API deprecation is easy Testing, monolith style The good ol days </li><li> 7. Different requirements per client =&gt; Code complexity increases Harder to deploy without breaking at least one client Testing, monolith style Mo clients, mo problems </li><li> 8. More manual QA expensive, slow, prone to human error, doesnt scale More end-to-end tests Maintenance nightmare, flaky, slow, creates bottlenecks Testing, monolith style Mo clients, mo problems </li><li> 9. My first steps @ SoundCloud </li><li> 10. My first steps @ SoundCloud Whoa, micro-services </li><li> 11. My first steps @ SoundCloud Testing strategy E2E Unit Integration </li><li> 12. My first steps @ SoundCloud Digging into post-mortems ofsmallthings </li><li> 13. My first steps @ SoundCloud A lack of trust in the acceptance tests caused us to largely ignore the warnings they generated. We couldnt figure out the impact of the broken acceptance tests, and assumed the only problem was the tests themselves, rather than the underlying code. The commit went through as there weren't any tests for the serialisation from the client to the backend. Digging into post-mortems ofsmallthings </li><li> 14. Introducing contract tests </li><li> 15. Introducing contract tests My daily routine LockeSteerpike </li><li> 16. Introducing contract tests My daily routine rickandmorty.com </li><li> 17. Unit tests are not enough Introducing contract tests #cake &gt;&gt; { result = call(cake) assert(result == lie) } GET /cake: return lie </li><li> 18. Unit tests are not enough Introducing contract tests GET /cake: return truth #cake &gt;&gt; { result = call(cake) assert(result == lie) } </li><li> 19. Unit tests are not enough Introducing contract tests import JsonLibFoo GET /cake: return toJson(current_state) // { current_state : lie } import JsonLibFoo #cake &gt;&gt; { result = fromJson(call(cake)) assert(result == lie) } </li><li> 20. Unit tests are not enough Introducing contract tests import JsonLibBar GET /cake: return toJson(current_state) // { currentState : lie } import JsonLibBar #cake &gt;&gt; { result = fromJson(call(cake)) assert(result == lie) } </li><li> 21. Introducing contract tests How this works? Consumer Provider End-to-End Test </li><li> 22. Introducing contract tests How this works? Consumer Provider Unit Test Unit Test </li><li> 23. Introducing contract tests How this works? Consumer Provider Unit Test Unit Test </li><li> 24. Introducing contract tests How this works? Requesting /cake. Expecting a JSON response with a key current_state. Asserting deserialization of the response succeeds. import JsonLibFoo GET /cake: return toJson(current_state) // { current_state : lie } Consumer Provider </li><li> 25. Pactifying our services http://pact.io </li><li> 26. Whats Pact? Pactifying our services A family of frameworks designed for consumer driven contract testing. Supports JSON over HTTP. Impl. for Java, Scala, Go, Ruby, .Net, Swift, JS etc. Tests run locally, no external dependencies. </li><li> 27. Whats Pact? Pactifying our services Step 1: Define consumer expectations pact.io </li><li> 28. Whats Pact? Pactifying our services Step 2: Verify expectations on provider pact.io </li><li> 29. Consumer: client code (LikesClient) </li><li> 30. Consumer: client code (LikesClient) </li><li> 31. Consumer: client code (LikesClient) </li><li> 32. Consumer: client code (LikesClient) </li><li> 33. Consumer: client code (LikesClient) </li><li> 34. Consumer: client code (LikesClient) </li><li> 35. Consumer: client unit test </li><li> 36. Consumer: client unit test </li><li> 37. Consumer: client unit test </li><li> 38. Consumer: client unit test </li><li> 39. Consumer: client contract unit test </li><li> 40. Consumer: client contract unit test </li><li> 41. Consumer: client contract unit test </li><li> 42. Consumer: client contract unit test </li><li> 43. Consumer: client contract unit test </li><li> 44. Consumer: client contract unit test </li><li> 45. Consumer: client contract unit test </li><li> 46. Consumer: client contract unit test </li><li> 47. Consumer: my-consumer-likes.json </li><li> 48. Consumer: my-consumer-likes.json </li><li> 49. Consumer: my-consumer-likes.json </li><li> 50. Consumer: my-consumer-likes.json </li><li> 51. Consumer: my-consumer-likes.json </li><li> 52. Consumer: my-consumer-likes.json </li><li> 53. Consumer: my-consumer-likes.json </li><li> 54. Pactifying our services Provider side verification Collect pact files from consumers and verify them all. Keep your provider environment isolated. Dockerized databases. Test doubles for upstream services. </li><li> 55. Pactifying our services Provider states </li><li> 56. Pactifying our services Provider states Likes App Likes DB </li><li> 57. Pactifying our services Provider states Set state: User 1000 has liked 2 tracks Likes App Likes DB </li><li> 58. Pactifying our services Provider states INSERT likes Set state: User 1000 has liked 2 tracks Likes App Likes DB </li><li> 59. Pactifying our services Provider states INSERT likes Set state: User 1000 has liked 2 tracks HTTP Request: GET /likes/1000 Likes App Likes DB </li><li> 60. Pactifying our services Provider states HTTP Request: GET /likes/1000 HTTP Response: 200 OK INSERT likes Set state: User 1000 has liked 2 tracks Likes App Likes DB </li><li> 61. Pactifying our services Provider states Likes App Likes DB HTTP Response: 200 OK INSERT likes Set state: User 1000 has liked 2 tracks HTTP Request: GET /likes/2000 HTTP Response: 404 Not Found Set state: User 2000 has liked no tracks HTTP Request: GET /likes/1000 DELETE likes </li><li> 62. Pactifying our services Pact broker Share pact files between projects. API for pact frameworks to fetch all pacts by provider. Support for versioning and tagging. Useful UI and visualization of the network. </li><li> 63. Pactifying our services Pact broker pact broker </li><li> 64. Pactifying our services Pact broker pact broker </li><li> 65. Pactifying our services Pact broker pact broker </li><li> 66. Pactifying our services Our CI pipeline Push new change Generate consumer contracts Deploy Upload pacts &amp; tag with prod Consumer pipeline </li><li> 67. Pactifying our services Our CI pipeline Push new change Deploy Upload pacts &amp; tag with prod Consumer pipeline Push new change Verify all prod-tagged pacts Deploy Provider pipeline Generate consumer contracts </li><li> 68. Communication is key. Caveats </li><li> 69. Communication is key. New moving parts. Caveats </li><li> 70. Communication is key. New moving parts. Learning curve per pact framework. Caveats </li><li> 71. Communication is key. New moving parts. Learning curve per pact framework. Frameworks are WIP. Caveats </li><li> 72. Communication is key. New moving parts. Learning curve per pact framework. Frameworks are WIP. Provider side setup is time consuming. Caveats </li><li> 73. Communication is key. New moving parts. Learning curve per pact framework. Frameworks are WIP. Provider side setup is time consuming. Automating consumer-triggered provider verification. Caveats </li><li> 74. Communication is key. New moving parts. Learning curve per pact framework. Frameworks are WIP. Provider side setup is time consuming. Automating consumer-triggered provider verification. Adoption is essential. Caveats </li><li> 75. Recap </li><li> 76. Recap Write contract tests Consum ers </li><li> 77. Recap Write contract tests Generate pact files Consum ers </li><li> 78. Recap Write contract tests Generate pact files Publish to broker Consum ers </li><li> 79. Recap Write contract tests Generate pact files Publish to brokerVerify pacts Consum ers Providers </li><li> 80. Recap Write contract tests Generate pact files Publish to brokerVerify pacts Consum ers Providers </li><li> 81. QA Q&amp;A @alonpeer </li></ol>