JAX 2018 Testing microservices, from development to production
By: Daniel Bryant
Pre-prod vs post-prod tests
- Contract testing
- Api simulation
Boktips: Distributed Systems Observability
Microservice test funnel – Cindy Sridharan ”testing microservices the sane way”
Some tests should be done in production
- Don’t avoid unit test <== 77% production failues can be reproduced by a unit test
- Testing error handling could have prevented 58% of catastrophic failures.
- 35% of catastrpåhic failures bacause of empty error handler.
- If it looks to comlicated, it probably is
- Coupling and cohesion apply to everything!
End to end tests
- Representational data is often the weakest link
- Understand your data ”shape” and volume
- Synthetic datastores
- Testcontainers (ramverk)
- Test outisde-in
- Acceptance tests for systems and services
- ”LUFD” the context and TDD the API
- Virtualise dependencies
Makes regressions testing easier.
JMeter vs Gatling (scala), hur påverkar det lättheten att skriva lasttester?
Synthetic transactions in production <== CAREFUL!!
Test contracts of unstable API:s. Choose your battles.
Contract (Testing Syntax)
If you breake a contract, don’t blame, go communicate.
Usually fits between component test and end-to-end-tests.
API Contracts are service contracts
- Many are producer driven
- It’s possible to design outside-in
- Consumer-driven contracts (CDC)
- Pact (ramverk) on the Consumer side
- Verify expectations on Provider.
- CDC frameworks
- Spring cloud contract
- Pact supports AMQP contracts
- Hur hantera kontrakt i t.ex. Kafka?
Contract testing Musings
- Great in low trust low communication
- Act as a cue for communication
- Lesser value during incubation/startups
- Can be used to implement TDD for the API
- Resource intensive to create and maintain
API simulation (testing semantics)
- How to keep track of internal services/dependencies?
- Not always easy to mock away.
- Virtual services?
- LocalStack (AWS)
- Great when service expencive to access or tricky to mock
- Userful to test failure modes, when hard to recreate
- Can be fragile and complicated
Fault injection (testing resilience)
- ”chaos engineering”
- Principles of chaos engineering https://principlesofchaos.org
- When things go wrong unexpectantly ==> diagnostic routines, fire drills
- Gremlin (paid)
- Tammy Butow The Path to Chaos Engineering
- High Severity Incident Management
- Measure impact of downtime
- Assert system quality attributes
- Can prompt team tp think about monitoring and resilience
- Can cause a lot of damage if used wrong
Balance pre-production testing and production testing.
Don’t try to be absolutely correct.
Book tip: Continuous Delivery in Java