📜 ⬆️ ⬇️

Summary of the report “Monolith for hundreds of client versions” (HL2018, Badoo, Vladimir Yants)

I continue a series of abstracts with HL2018. The guys from Badoo (Vladimir Yants, vyants and Nikolay Krapivny) helped me in checking this summary, for which I thank them very much. I hope this has a positive effect on the quality of the message conveyed.

image

Features of the development process:


Responsibility of the developer does not end with the release of the backend. It responds prior to implementation on the platforms.

image
')
There is manual testing, but the client is not ready at the time of release and comes with a (unpredictable) delay. We most often do not know when customers will begin to implement it. Sometimes (not often) features start to do after a long time. Therefore, testing with your hands is hard and not everything is possible. Therefore, we need autotests.

Tests


Unit tests


They write on phpunit.

Test a small unit. They do not go to the base or to the services (they should not interact with anything).

Legacy is still there and complicates the testing process.

Developed softMocks library - intercepts all include / require and substitutes for changed.

You can wind any methods: static, private, final.
The library is available in open source.

Problem: softmocks are relaxing and letting you write non-testable code (and everything should be covered with tests).

Accepted the rules:


These rules look at the code review

Quality tests


Mutation Testing



There are ready-made solutions (Humbug, Infection), but they did not fit (not compatible with softmocks, there are difficulties with code coverage). Therefore, they wrote their own.

Mutation testing is not yet available for a manual test. Available to run manually from the console. Now we introduce in CI pipeline, we build process. The result will be on Habré.

Integration tests


We test the work of several components in a bundle; We check the work with the database and / or services.

Standard approach to database testing (DBUnit):

  1. Raise the test database
  2. Fill it
  3. Run the test
  4. Clearing the database

Problems:


Solution: DBMocks library (custom)

Principle of operation:


The library is small but not yet launched in open source.

Results:


API tests



Typically, such tests require an authorized user. It must be created before the test and removed after. This brings additional risks (replication, background tasks).

Solution: Made a pool of test users. Learned to clean them.

image

Test users are in the same real environment, because devel! = Prod. It is necessary to isolate test and live users.

For isolation, the user added the is_test_user flag. And these users are also excluded from the analytics and the results of a / b tests.

You can do it cheaper - send test users "to Antarctica", where no one will see them (except penguins).

QA API


A tool for preparing the environment in api tests, essentially a backdoor in the backend for quickly changing user / environment settings.


Allows you to change the user immutable data (for example, the date of registration).

Protection required:


There is a BugsBounty program on HackerOne. Pay for the found vulnerabilities. One cant with QA API found with its help.

Remote mocks


Moki for remote backend.

Work on the base of soft mocks. The test asks the backend to initialize for the mock session. When a request is received, the backend checks the list of mocks for the session and applies them using SoftMocks.

Test example:

image

API tests are too convenient. There is a temptation to write them instead of Unit. But API tests are much slower.

Adopted a set of rules:


Ui tests


Do not write backend command.

The feature is covered with Ui tests when it stabilizes.
Used selenium for the web. For mobile calabash.

Test run


100,000 unit tests. 6,000 integration tests, 14,000 tests.
In 1 flow time 40 min / 90 min / 10 hours.

Have made TestCloud - a cloud for start of tests.

image

Distribution of the test between threads:


Decision:


The problem with api tests is a long time, a lot of resources and they don’t allow others to execute.

To solve, the cloud was divided into 2 parts:

  1. Runs quick tests only.
  2. Runs both types of tests.

The result is an acceleration of time to:


Code coverage run


What tests to perform? Show code coverage.

  1. Get branch diff
  2. Create a list of changed files
  3. Get the list of tests for these files.
  4. Run the suite from these tests only.

Coverage is formed once a day, at night, for a master branch. Results (diff) add to the database.

Pros:


Minuses:


If the developer needs to see the code-coverage immediately, that is, the tool that can be run in the console and immediately get a fresh metric on the coverege of a specific file / component.
It is considered cunning: the data on the coverege of the master is taken, all the modified tests are added, a small suite is obtained for which the coverage is already considered.

Results



Links


Source: https://habr.com/ru/post/429776/


All Articles