Understanding Distributed Systems Flashcards
Pros of tests?
- working of current feature
- checking if current changes break existing features
- well written tests are great documentation
- by using TDD you force clean code on codebase
How TDD helps with writing clean code?
- firstly you focus on writing requirements, so tests are more functional and code has more business methods than code methods.
- To easily write tests, classes needs to be shor, well divided and often written to interfaces.
- code coverage 100% facilitates refactor
Parts of TDD?
Write failing test -> test passes -> refactor
What is SUT?
System under tests (scope of the test)
Types of tests
- unit
- integration: top-down, bottom-up, hybrid, contract tests
- end-to-end: user journey
- Nonfunctional tests like security tests, load tests, performance tests
What unit tests should check?
Public API and state of SUT, which is a class.
What is user-journey test?
It tests the whole scenario - like process of selecting an item and buying it. Exactly like user.
Pros:
- better testing most valuable functionality of app
- despite it’s big tests, quicker to write and maintain DJ test instead multiply EE tests for each step.
What contract tests check?
It defines request and response of the dependency. It is used in integration tests to simulate it AND in the dependency test suite. Thanks to this, we are sure that responses are closest to real one.
What is testing double?
This is prod code dependency which in tests needs to be somehow simulated.
Type of test doubles
- fake
- stub
- mock
What is fake in the testing scope?
lightweight implementation of a dependency, like in-memory db instead of real db.
What is stub in the testing scope?
test double which just returns things - no way to check how system interacts with it during test.
What is mock in the testing scope?
smarter stub - we can check how system interacts with it and still simulate return value.
Fake vs stub vs mock?
Usually fake > mock > stub (especially when fakes are written by an author of real dependency)
What is continuous integration?
Process of merging changes in code done by developers to master branch with additional automatic checks like “static analysis”, unit tests run on server
What is continuous delivery?
If pipeline isn’t fully automated, but automation is done as much as possible in current organization, it’s Continuous delivery. Ideally a system where there is manual check on staging env, and then its approval for prod deployment is reachable for all organizations.
What is continuous deployment?
Extreme version of “continuous” variations. Once PR is approved, everything is automated - new version hits the prod.
Quite rare
What are parts of usual CI/CD?
- Review
- Build
- Pre-prod rollout
- Prod rollout
How to do proper review in CI/CD?
Most important part.
to do:
- checking tests
- checking feature
- backward-compatibility
- logs
What preprod rollout does?
- check if app correctly startup on cluster (no NullPoitner or config exception)
- smoke tests
- the same health check system like on prod
What is canary deployment?
progressive rollout of deployment to subsets of users. Role of thumb are 3 batches. Next bigger than previous.
After each batch comprehensive checks.
When rollback (app and db) are used?
After rollout, there should be many checks (not only health check):
- performance of service
- time of response
If something isn’t correct, the engineer should retry deployment, rollback and wait on hotfix.
What is rollback?
It is bringing back previous version of app. It should be a mindless process, because decisions about rollback usually are made in stress moments on prod.
That’s why backward compatibility is so important.
What to do when there is big change which simply cannot be backward compatible?
- Divide big task on smaller tasks - thanks to this, usually will be a couple of backward-compatible tasks and one incompatible.
- Leave incompatible task as the last one.
- try to make old mechanism and new mechanism works at the same time.
Example:
task: change of producer-consumer schema:
division:
1. Consumer can handle both schema (Can be rollaback)
2. producer can produce new schema messages (Can rollback)
3. Leaving old schema (Cannot rollback, because of new messages in system)