I don't know what are the common concurrency problems, and how can I say that I am the boss! !

1. Concurrent testing

Recently, Xiao Diaosi has been immersed in the performance knowledge (zi) consciousness (shi)~.
It's hard work.
However, Xiao Diaosi’s recent problems are quite tricky.
For example:
Xiao Diaosi: Brother Yu, do you mean this performance test is a concurrent test?
Xiaoyu: Performance testing and concurrent testing are two concepts, and concurrent testing is not the same as performance testing.
Xiao Diaosi: Brother Yu, do you mean that performance testing includes concurrent testing?
Xiaoyu: Hematemesis... The performance test is just a subcategory of concurrent testing.
Xiaoyusi: Oh, the performance test...
Xiaoyu: Shut up! ! Don't ask, I'm counseling~ I will tell you in detail what concurrency testing is, and analyze common concurrency problems for you from my actual projects!
Xiao Diaosi: Digging grass, this time I made a lot of money!
Xiao Diaosi: Brother Yu, please start your performance! !

1.1 Definition of concurrent testing

1. In the definition of concurrent testing, there are two main points:
①On the point level:
For example, at 7:30 a.m. Monday morning, elementary school students must go to the playground to raise the national flag.
>>That is: do something at the same time ②On the
line level:
For example: 11:30-13:00 noon, some elementary school students jump rubber bands, some play football, but at the same time exert pressure on the server.
>>That is: do different things in one time period

2. Concurrent testing is not equal to performance testing
. When I was interviewing, I asked multiple job seekers. The first reaction of most job seekers was to say that concurrent testing is performance testing!
In performance testing, concurrency is divided into load and stress testing.
Although concurrent testing and performance testing have intersections, concurrency testing is not just applied to performance testing. Concurrent testing is more used in other areas.

1.2 Classification of concurrent testing

Concurrent testing is not only a performance test, it has various test stages, and the purpose of the test is different.
Functional concurrency testing : Concurrent testing of test single business function scenarios should be performed first, and concurrent testing of mixed business function scenarios should be performed.
>>The purpose of the function concurrency test is to verify whether the system functions meet the requirements of the requirements specification.
②Performance concurrent test : Under the premise of meeting certain system performance indicators at the same time, let the tested object undertake different workloads to evaluate the maximum processing capacity of the tested object and whether there are defects.
>>The purpose of the performance concurrent test is to verify whether the system performance indicators meet the requirements of the requirements specification.
③Concurrent stability test : to judge the long-term stable operation ability of the test system.
>>The purpose of the stability concurrency test is to verify whether the stability of the system meets the requirements of the requirements specification.
Abnormal concurrent test : The simulation system runs under poor and abnormal resource configuration to evaluate the working status of the tested object under the condition of insufficient resources.
>>The purpose of the abnormal concurrency test is to verify whether the abnormal response mechanism of the system meets the requirements of the requirement specification.

2. Common concurrency problems

A fashionable software design concept is now popular, called "microservices".
Split the complex function combination into several independent services for development, and then selectively combine and execute each service.
The microservice development framework is conducive to concurrent test design. Each service is an entry point for testing and can be executed separately. In other words, the more test entry points, the better the design of test scenarios and the effective execution of concurrent use cases.
Concurrent entry points to find statistics from the following three aspects:
①Client operation : Use tools to capture requests submitted to the server, analyze links and parameters for testing.
②System interface : consult relevant interface documents, develop and simulate other system functions for testing.
③Timing tasks : Depending on the development framework, timing tasks may require secondary development and testing in the form of interfaces.

The problem of concurrent testing is a comprehensive syndrome, and there are often multiple errors intertwined, so "medicine" should not be used indiscriminately.
Solving this type of problem is usually divided into the following 5 steps ( 2 steps more than putting the elephant in the refrigerator ):
①Find the fault point through concurrent testing;
②Analyze the cause of the problem by the phenomenon of the fault point;
③Discuss the solution after determining the cause ;
④ solution according repair;
⑤ repair with concurrent test to verify the situation.

2.1 The problem of transaction concurrency

Concurrency issues caused by transaction processing, we need to understand what a transaction is.
The definition of a transaction : it is the smallest unit of database operations, which is a series of operations performed as a single logical unit of work; these operations are submitted to the system as a whole, either executed or not executed; a transaction is a set of indivisible operations (Working logic unit).
System internal transaction control : The quality of transaction control often depends on the development technology, business understanding ability, and concentration of the code farmers. The bugs caused by such errors are very low-level and serious ( you must show a yellow card for warning )!
Let's take an example to illustrate that
one day, Xiao Diaosi received an invitation from Bai Fumi, saying that she was going to watch a "xx brand" movie, and asked Xiao Diaosi to help book a ticket.
Digging grass~~Xiao's silk chicken is frozen, quickly take out his iphone4, open a group, find a certain movie, select the location, and click "OK", then enter the payment page, submit the order, select Alipay to pay, pay SMS successfully received.
Let’s share the first half of the story scene :
Xiao Diaosi opens a group with her mobile phone, finds the movie that Bai Fumi wants to watch, chooses a seat, and submits the order to the payment page.
Both "seat selection" and "order submission" are internal interfaces of a certain group.
If these two are regarded as a transaction, there are the following four characteristics:
Atomicity : Either all are integrated or not.
consistency : Lock the seat after submitting an order must be generated order number, the order is canceled unlock the seat.
Isolation : seat selected by others, there is no network failure operation log record and the like.
Persistence : After the transaction is committed, it will exist permanently and will not be affected by any failure.
As a tester, the test points that need to be considered are:
①A seat is locked by multiple accounts, and an order is generated;
②The seat is locked successfully, but no order is generated;
③The order is cancelled, and the seat is not unlocked;
④A duplicate order number is generated;
⑤ The operation log does not fully record all actions.
Let’s analyze the second half of the movie ticket booking scene :
Xiao Diaosi uses Alipay to pay on the payment page. After the payment is successful, he receives the platform SMS.
"Payment successful" is the external interface. For transaction control of external interfaces, two system designs need to be considered.
For concurrent interface testing of payment interfaces, transaction issues to be considered:
①The same order cannot be selected in multiple ways at the same time, and multiple payments cannot be made;
②Repeated notification to upload the payment result (payment successful, payment timed out), and can only be processed once Order.
③The log record completely records the payment information sent and received, which matches the content of the test case.

2.2 Limit value concurrency

Concurrency problems caused by the limit value, then, what is the limit value?
Limit value : the limit of the numerical range required by the standard. "Limit value" is also called "limit value", "critical value", "limit value".
Let’s take an example to illustrate
that it was the first snow in 2020. Bai Fumi wants to have a birthday party. In order to enliven the atmosphere, Bai Fumi wants to organize a lottery, so she finds Xiao Diaosi, tells Xiao Diaosi the specific arrangements, and asks Xiao Diaosi Go yard.
The specific arrangement is: friends who are still present at 23:00 ~ 23:59 that day, each person will have a gift ( Huawei P50 must be arranged ), and each person will have another 3 chances to draw a lottery ( digging grass ~ this is Hyun Father?? ), and send at the same time The high-profile show off in the circle of friends can still get a chance to draw a lottery. Those who have already drawn the first prize cannot win the second and third prizes. The probability of winning is calculated according to the estimated probability. If the number of winnings reaches the upper limit, The lottery must be stopped.
Xiao Diaosi completed the code development and conducted concurrent tests according to Bai Fumi's needs.
Concurrent test scenarios designed by Xiao Diaosi :
①At 23:00 ~ 23:59 on the day, give everyone present a gift;
②Everyone present has 3 chances to draw a lottery;
③High-profile Moments for friends, you can have another chance to draw;
④ Those who have won the first prize cannot win the second and third prizes;
⑤The probability of winning the prize is set according to the estimated probability;
⑥The prize is stopped if the number of winnings reaches the upper limit of the number of prizes.

In this scenario, the first analysis test objects are: activity time, number of draws, probability of winning, upper limit of the number of prizes, and rules of winning.
The coverage points of concurrent test cases designed by Xiao Diaosi are as follows:
①Test activities: You can participate in the lottery if you are not within the time range of the activity;
②The number of lottery draws: the number of draws is more than 3 times if you haven't shared your circle of friends;
③Number of draws: the high-profile circle of friends Show off, the number of draws is more than 1;
④Probability of winning: Set the number of decimal places for the probability of winning;
⑤Simplify the upper limit of the number: control the upper limit of the number of awards;
⑥The rules of winning: have won the first prize, can you still win the second prize, Third prize.

2.3 The problem of pressure concurrency

Concurrency problems caused by stressful loads can be classified as performance problems.
Questions about the performance, I have written several articles before, such as:
performance analysis process
tuning
MySQL performance monitoring
if there do not understand or ignorant, you can directly read the three articles.
But today I want to talk about the isolation level of some database transactions.
>>>There are 4 isolation levels, from low to high as follows:
Read uncommitted (unauthorized read, read uncommitted)
If one transaction has started to write data, another transaction is not allowed to write at the same time, but it is allowed Other transactions read this row of data. This isolation level can be achieved by "exclusive write lock".
This isolation level avoids loss of updates, but dirty reads may occur.
>> That is, transaction B read the uncommitted data of transaction A.
Read committed (authorized read, read commit)
The transaction that reads the data allows other transactions to continue to access the row of data, but the uncommitted write transaction will prohibit other transactions from accessing the row.
This isolation level avoids dirty reads, but non-repeatable reads may occur.
>> That is, transaction A reads the data first, transaction B then updates the data and raises the price of the transaction, and when transaction A reads the data again, the data has changed.
Repeatable read (repeatable read)
transactions that read data will prohibit write transactions, and write transactions prohibit any other transactions.
This isolation level avoids non-repeatable reads and dirty reads, but sometimes phantom reads may occur. This can be achieved with "shared read lock" and "exclusive write lock".
Serializable (serialization)
provides strict transaction isolation. It requires serialized execution of transactions, transactions can only be executed one after another, but not concurrently. If transaction serialization cannot be achieved only through "row-level locks", other mechanisms must be used to ensure that the newly inserted data will not be accessed by the transaction that just performed the query operation.
Sequence table is the highest transaction isolation level, and it is also the most expensive and the lowest performance, and it is generally rarely used. At this level, transactions are executed in obedient order, which not only avoids dirty reads and non-repeatable reads, but also avoids phantom reads.
So, what are dirty reading, non-repeatable reading, and phantom reading, can you explain it?
This can't trouble Xiaoyu.
(1) Dirty read
A transaction reads the uncommitted data operation result of another transaction.
(2) Loss of update Loss of
update includes the following two situations:
Loss of rollback
>> When two transactions update the same data source, if the first transaction is committed and the other transaction is cancelled, it will be combined with the first transaction. The update made by a transaction is also cancelled, that is, the update made by the first transaction is lost.
Loss of coverage
>> When two or more transactions query the same record and each will update the row with the original query results, it will cause loss of coverage, because every thing does not know the existence of other transactions, the last transaction pair Modifications made to the record will overwrite the committed updates made to the record by other transactions.
(3) Non-repeatable Reads (Non-repeatable Reads)
A transaction reads the same row of data twice, but obtains different results, including the following situations.
Dummy read : After transaction R1 reads a certain data, transaction R2 modifies it, and when transaction R1 reads the data again, it gets a different value.
phantom read : Transaction query twice during the operation, the result of the second query contains the data for the first time the query does not appear or cancel the data in the first query appear (does not require two sql queries The statement is the same). This is caused by another transaction inserting data during the two queries.
The default isolation level of the usual database settings is Read committed (authorized read, read commit) .

2.4 The problem of abnormal data interference concurrency

The abnormal data test for this kind of situation can also be called the system robustness test.
The focus of the test is to construct test data that can cause anomalies based on business logic or system-related configuration conditions. These data must not be treated as normal data, nor can they affect other normal data ( this is very difficult ).

For example:
testers construct test scenarios to continuously trigger regular batch processing tasks. If the code farmers ignore the logic processing of abnormal data in the code, it will cause the database connection pool to be full, memory overflow, and direct error interruption when encountering abnormal data (tasks to be executed) More and more queues) and other issues.

The focus of this type of concurrency testing is not synchronous concurrency, but a gradually increasing amount of concurrency.
Compared with the previous questions, this difficulty has raised a level,
because it requires the testers to understand the system architecture configuration and data flow logic, so this requires a lot of hard work by the testers. Strive for all full stacks! !

Xiaoyu: Xiao Diaosi, the common concurrency problems are almost summarized.
Besides, this is a bit faster. Can I go for a cup of coffee first?
Xiao Diaosi: Brother Yu, use me to pour it for you, right?
Xiaoyu: Can you be more realistic?
Xiao Diaosi: No... can... can you...
Xiao Diaosi: Brother Yu, I heard that you got up at four or five o'clock in the morning, and you didn't sleep at more than twelve o'clock this evening. You're so energetic, you're pretty awesome!
Xiaoyu: Poverty makes me work hard! !
Xiao Di Si: Brother Yu, are you kidding me?
Xiao Diaosi: Brother Yu, in your current state, you seem to have
known each other... Xiao Yu: Uh ... who knows you? ?
Diaosi: Dad Ma...
Xiaoyu: Uh, Diaosi, your phone rang!
Xiao Diaosi: Digging grass~ ~ Bai Fumei v me, bye bye, fish brother, I'm busy now~ ~
Xiaoyu:...
Insert picture description here

Guess you like

Origin blog.csdn.net/wuyoudeyuer/article/details/106596423