Current limiting strategy testing method, system, computer readable medium and electronic device
By using the JMeter program to automatically test the current limiting policy, and count and analyze the number of successful and failed API accesses, the problem of inaccurate current limiting policy testing in the existing technology is solved, and automated and accurate verification of the current limiting policy is achieved.
Patent Information
- Application Number
- CN202210158731.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-21
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2042-02-21
AI Technical Summary
The existing technology cannot accurately test and verify the current limiting policy, especially when the current limiting size is large, manual refresh of the page cannot effectively test, and it is impossible to accurately determine whether the current limiting policy is correctly set.
Use the JMeter program to access the tested end of the current limiting policy, count the number of successful and failed API accesses, and determine whether the current limiting policy setting is successful through analysis, including creating a thread group, adding an HTTP header manager and an HTTP cookie manager, and adding Synchronize timers, collect statistics, and record access results to determine whether the cause of access failures and the number of successes comply with the current limiting policy.
Automated current-limiting policy testing is implemented, replacing manual verification. It can accurately measure the current-limiting size without being affected by the current-limiting size, ensuring the accuracy of current-limiting policy settings.
Smart Images

Figure CN114629810B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of testing a current limiting strategy of a server, and in particular to a current limiting strategy testing method, system, computer-readable medium and electronic device. Background Art
[0002] When the volume of visits increases rapidly, the service may encounter some problems, such as response timeout, service failure, and non-core services affecting the performance of the core process (destructive service), so it is necessary to limit the flow of the system.
[0003] In the past, the testing of flow-limiting strategies was mostly done by developers adjusting the flow-limiting size and testers frantically refreshing the page. However, this solution has an obvious disadvantage: the flow limit is too large, and testing cannot be done by manually refreshing the page. On the other hand, it is impossible to accurately know whether the flow limit is correct, and only whether the flow-limiting strategy is successful or not. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a current limiting strategy testing method, system, computer-readable medium and electronic device in view of at least one defect in the prior art.
[0005] The technical solution adopted by the present invention to solve the technical problem is: constructing a current limiting strategy testing method, comprising the following steps:
[0006] S1: Access the tested end running the current limiting strategy through the configured JMeter program, and count the APIs that succeeded and failed to access;
[0007] S2: Analyze the APIs that are successfully accessed and those that fail to be accessed to determine whether the current limiting strategy is set successfully.
[0008] Preferably, in the current limiting strategy testing method of the present invention, counting the number of APIs that are successfully and unsuccessfully accessed in step S1 includes:
[0009] Count the number of successful and failed API accesses, and record the reasons for the failed API accesses.
[0010] Preferably, in the current limiting strategy testing method of the present invention, step S2 includes:
[0011] S21: Determine whether the reason for the failed access to the API is access denied, if so, execute step S22; if not, execute step S1;
[0012] S22: Determine whether the number of successfully accessed APIs is equal to the current limiting size of the current limiting strategy. If so, the current limiting strategy is set successfully; if not, the current limiting strategy fails to be set.
[0013] Preferably, in the current limiting strategy testing method of the present invention, configuring the JMeter program to access the tested end that runs the current limiting strategy includes:
[0014] S11: Create a thread group;
[0015] S12: adding elements to the thread group, including at least one of an HTTP header manager, an HTTP Cookie manager, and an HTTP request default value;
[0016] S13: adding an API of the tested end that runs the current limiting strategy to the thread group;
[0017] S14: Add a synchronization timer and set the number of simulated user groups to the thread group size.
[0018] Preferably, in the current limiting strategy testing method of the present invention, the JMeter program is configured to count the number of successful and failed API accesses, including:
[0019] A table view result tree plug-in is added to the thread group for counting and viewing the number of successful and failed API accesses through a table.
[0020] Preferably, in the current limiting strategy testing method of the present invention, configuring the JMeter program to record the reason for the failed access to the API includes:
[0021] A view result tree plug-in for recording and viewing the reason for the failed API access is added to the thread group.
[0022] The present invention also constructs a current limiting strategy testing system, including:
[0023] The access module is used to access the tested end running the current limiting strategy through the configured JMeter program, and count the successful and failed APIs;
[0024] The analysis module is used to analyze the APIs that have been successfully and unsuccessfully accessed to determine whether the current limiting strategy has been successfully set.
[0025] Preferably, in the current limiting strategy testing system of the present invention, the analysis module includes:
[0026] The first judgment module is used to judge whether the reason for the failed access to the API is access denied, and if so, execute the second judgment module; if not, execute the access module;
[0027] The second judgment module is used to judge whether the number of successfully accessed APIs is equal to the current limiting size of the current limiting strategy. If so, the current limiting strategy is set successfully; if not, the current limiting strategy fails to be set.
[0028] The present invention also constructs a computer-readable medium on which a computer program is stored. When the computer program is executed by a processor, the current limiting strategy testing method as described in any one of the above items is implemented.
[0029] The present invention also constructs an electronic device, comprising:
[0030] one or more processors;
[0031] A storage device is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the current limiting strategy testing method as described in any one of the above items.
[0032] By implementing the present invention, the following beneficial effects are achieved:
[0033] The present invention adopts JMeter to test the current limiting strategy. Specifically, the tested end running the current limiting strategy is accessed through the configured JMeter program, and the successful and failed APIs are counted, and the successful and failed APIs are analyzed to determine whether the current limiting strategy is set successfully, thereby replacing the manual verification of the current limiting strategy, and is not affected by the current limiting size. At the same time, the size of the current limiting flow can also be accurately measured. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0035] Figure 1 This is a schematic diagram of the flow of the current limiting strategy testing method of the present invention. Figure 1 ;
[0036] Figure 2 This is a schematic diagram of the flow of the current limiting strategy testing method of the present invention. Figure 2 ;
[0037] Figure 3 It is a module block diagram of the current limiting strategy testing system of the present invention. DETAILED DESCRIPTION
[0038] In order to have a clearer understanding of the technical features, purposes and effects of the present invention, specific embodiments of the present invention are now described in detail with reference to the accompanying drawings.
[0039] It should be noted that the flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor do they have to be executed in the order described. For example, some operations / steps can be decomposed, while some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0040] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0041] like Figure 1 As shown, the present invention discloses a current limiting strategy testing method, comprising the following steps:
[0042] Step S1: Access the tested end running the current limiting strategy through the configured JMeter program, and count the APIs that are successfully and unsuccessfully accessed. Counting the APIs that are successfully and unsuccessfully accessed includes: counting the number of APIs that are successfully and unsuccessfully accessed, and recording the reasons for the failed APIs.
[0043] In some embodiments, configuring the JMeter program to access the tested end that runs the current limiting strategy specifically includes:
[0044] Step S11: create a thread group;
[0045] Step S12: Add elements to the thread group, including at least one of an HTTP header manager, an HTTP Cookie manager, and an HTTP request default value. In some scenarios, when the request header of the API needs to be verified, an HTTP header manager needs to be added. In some scenarios where the login status of the API needs to be verified, an HTTP Cookie manager needs to be added. The HTTP request default value is to reduce the workload of the script and avoid repeated writing of common parts, such as: protocol version, domain name, port. In this example, since there is no need to verify the login status of the API or the request header of the API, only the HTTP request default value needs to be added.
[0046] Step S13: Add the API of the tested end that runs the current limiting strategy to the thread group;
[0047] Step S14: Add a synchronization timer and set the number of simulated user groups to the thread group size. The synchronization timer is used to simulate a collection point, and the number of assembled threads will be released synchronously only when the number of assembled threads reaches a preset target value.
[0048] In some embodiments, the JMeter program is configured to count the number of successful and failed API accesses, specifically including:
[0049] Add a table view result tree plug-in to the thread group to count and view the number of successful and failed API accesses through a table. Adding a table view result is to intuitively view the execution results of the current limiting strategy.
[0050] In some embodiments, configuring the JMeter program to record reasons for failed API access includes: adding a View Results Tree plug-in for recording and viewing reasons for failed API access to the thread group.
[0051] Step S2: Analyze the APIs that are successfully and unsuccessfully accessed to determine whether the current limiting strategy is set successfully. Figure 2 As shown, specifically including:
[0052] Step S21: Determine whether the reason for the failed access to the API is access denied, if so, execute step S22; if not, execute step S1;
[0053] Step S22: Determine whether the number of successfully accessed APIs is equal to the current limiting size of the current limiting strategy. If so, the current limiting strategy is set successfully; if not, the current limiting strategy fails.
[0054] For example, the tested end running the current limiting strategy is the Baidu homepage, whose API is: https: / / www.baidu.com / . The current limiting strategy is to limit the current to 100, the number of threads is set to 200, and it is accessed through the JMeter program.
[0055] In the first case, the number of successful API accesses in the table is 100; the number of failed API accesses in the table is 100. By checking the result tree for secondary confirmation, the reason for the failed API access is access denied, usually returning error code 403. After secondary confirmation, the failed API accesses all return error code 403, so the number of successful accesses = the number of current limits = 100, and the current limit policy is set successfully.
[0056] In the second case, the number of successful API accesses in the table statistics is 50, and the number of failed API accesses in the table statistics is 150. After checking the result tree for secondary confirmation, all API access failures return error code 403. Therefore, the number of successful accesses < the number of current limit = 100, and the current limit strategy fails.
[0057] In the third case, the number of successful API accesses in the table statistics is 150, and the number of failed API accesses in the table statistics is 50. After checking the result tree for secondary confirmation, all API access failures return error code 403. Therefore, the number of successful accesses > the number of current limit = 100, and the current limit strategy fails.
[0058] Special case: The APIs that fail to access are not all due to access denied. They may be caused by errors such as 400, 404, 500, 502, etc. In this case, you need to execute the JMeter program again until the APIs that fail to access are all due to access denied.
[0059] like Figure 3 As shown, the present invention also discloses a current limiting strategy testing system, including an access module and an analysis module.
[0060] In this embodiment, the access module is used to access the tested end running the current limiting strategy through the configured JMeter program, and count the APIs that are successfully and unsuccessfully accessed. Among them, counting the APIs that are successfully and unsuccessfully accessed includes: counting the number of APIs that are successfully and unsuccessfully accessed, and recording the reasons for the APIs that failed to be accessed.
[0061] In some embodiments, configuring the JMeter program to access the tested end that runs the current limiting strategy specifically includes:
[0062] Create a thread group;
[0063] Add components to the thread group, including at least one of the HTTP Header Manager, HTTP Cookie Manager, and HTTP Request Defaults. In some scenarios, when the API request header needs to be verified, the HTTP Header Manager needs to be added. In some scenarios where the API login status needs to be verified, the HTTP Cookie Manager needs to be added. The HTTP request defaults are to reduce the workload of the script and avoid repeated writing of common parts, such as protocol version, domain name, and port. In this example, since there is no need to verify the API login status or the API request header, only the HTTP request defaults need to be added.
[0064] Add the API of the tested end that runs the current limiting strategy to the thread group;
[0065] Add a synchronization timer and set the number of simulated user groups to the thread group size. The synchronization timer is used to simulate a collection point. The number of assembled threads will be released synchronously only when the number of assembled threads reaches the preset target value.
[0066] In some embodiments, the JMeter program is configured to count the number of successful and failed API accesses, specifically including:
[0067] Add a table view result tree plug-in to the thread group to count and view the number of successful and failed API accesses through a table. Adding a table view result is to intuitively view the execution results of the current limiting strategy.
[0068] In some embodiments, configuring the JMeter program to record reasons for failed API access includes: adding a View Results Tree plug-in for recording and viewing reasons for failed API access to the thread group.
[0069] In this embodiment, the analysis module is used to analyze the APIs that are successfully and unsuccessfully accessed to determine whether the current limiting strategy is set successfully.
[0070] Specifically, the analysis module includes:
[0071] The first judgment module is used to judge whether the reason for the failed access to the API is access denied. If so, the second judgment module is executed; if not, the access module is executed;
[0072] The second judgment module is used to judge whether the number of successfully accessed APIs is equal to the current limiting size of the current limiting strategy. If so, the current limiting strategy is set successfully; if not, the current limiting strategy fails.
[0073] For example, the tested end running the current limiting strategy is the Baidu homepage, whose API is: https: / / www.baidu.com / . The current limiting strategy is to limit the current to 100, the number of threads is set to 200, and it is accessed through the JMeter program.
[0074] In the first case, the number of successful API accesses in the table is 100; the number of failed API accesses in the table is 100. By checking the result tree for secondary confirmation, the reason for the failed API access is access denied, usually returning error code 403. After secondary confirmation, the failed API accesses all return error code 403, so the number of successful accesses = the number of current limits = 100, and the current limit policy is set successfully.
[0075] In the second case, the number of successful API accesses in the table statistics is 50, and the number of failed API accesses in the table statistics is 150. After checking the result tree for secondary confirmation, all API access failures return error code 403. Therefore, the number of successful accesses < the number of current limit = 100, and the current limit strategy fails.
[0076] In the third case, the number of successful API accesses in the table statistics is 150, and the number of failed API accesses in the table statistics is 50. After checking the result tree for secondary confirmation, all API access failures return error code 403. Therefore, the number of successful accesses > the number of current limit = 100, and the current limit strategy fails.
[0077] Special case: The APIs that fail to access are not all due to access denied. They may be caused by errors such as 400, 404, 500, 502, etc. In this case, you need to execute the JMeter program again until the APIs that fail to access are all due to access denied.
[0078] The present invention also discloses a computer-readable medium on which a computer program is stored. When the computer program is executed by a processor, the current limiting strategy testing method as described above is implemented, which will not be described in detail here.
[0079] The present invention also discloses an electronic device, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by one or more processors, the one or more processors implement a current limiting strategy testing method such as any of the above-mentioned ones, which will not be repeated here.
[0080] By implementing the present invention, the following beneficial effects are achieved:
[0081] The present invention adopts JMeter to test the current limiting strategy. Specifically, the tested end running the current limiting strategy is accessed through the configured JMeter program, and the successful and failed APIs are counted, and the successful and failed APIs are analyzed to determine whether the current limiting strategy is set successfully, thereby replacing the manual verification of the current limiting strategy, and is not affected by the current limiting size. At the same time, the size of the current limiting flow can also be accurately measured.
[0082] It can be understood that the above embodiments only express the preferred implementation modes of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the patent scope of the present invention. It should be pointed out that, for ordinary technicians in this field, the above technical features can be freely combined without departing from the concept of the present invention, and several deformations and improvements can be made, which all belong to the protection scope of the present invention. Therefore, all equivalent changes and modifications made to the scope of the claims of the present invention should belong to the coverage of the claims of the present invention.
Claims
1. A current limiting strategy testing method, characterized in that: The following steps are involved: S1: Access the tested end running the current limiting strategy through the configured JMeter program, and count the APIs that succeeded and failed to access; S2: Analyze the APIs that are successfully accessed and those that fail to access, to determine whether the current limiting strategy is set successfully; Among them, in step S1, the JMeter program is configured to access the tested end that runs the current limiting strategy, including: S11: Create a thread group; S12: adding elements to the thread group, including at least one of an HTTP header manager, an HTTP Cookie manager, and an HTTP request default value; S13: adding an API of the tested end that runs the current limiting strategy to the thread group; S14: adding a synchronization timer, setting the number of simulated user groups to the size of the thread group; the synchronization timer is used to synchronously release the number of assembled threads when the number of assembled threads reaches a preset target value; In step S1, statistics on successful and failed access to APIs include: Count the number of successful and failed API accesses, and record the reasons for failed API accesses; Step S2 includes: S21: Determine whether the reason for the failed access to the API is access denied, if so, execute step S22; if not, execute step S1; S22: Determine whether the number of successfully accessed APIs is equal to the current limiting size of the current limiting strategy. If so, the current limiting strategy is set successfully; if not, the current limiting strategy fails to be set.
2. The current limiting strategy testing method according to claim 1 is characterized in that: Configure the JMeter program to count the number of successful and failed API accesses, including: A table view result tree plug-in is added to the thread group for counting and viewing the number of successful and failed API accesses through a table.
3. The current limiting strategy testing method according to claim 1 is characterized in that: Configure the JMeter program to record the reasons for the failed API access, including: A view result tree plug-in for recording and viewing the reason for the failed API access is added to the thread group.
4. A current limiting strategy testing system, characterized in that: include: The access module is used to access the tested end running the current limiting strategy through the configured JMeter program, and count the successful and failed APIs; An analysis module is used to analyze the APIs that have been successfully and unsuccessfully accessed to determine whether the current limiting strategy is set successfully; Among them, configure the JMeter program to access the tested end that runs the current limiting strategy, including: Create a thread group; Adding elements to the thread group, including at least one of an HTTP header manager, an HTTP Cookie manager, and an HTTP request default value; Adding an API of the tested end that runs the current limiting strategy to the thread group; Add a synchronization timer and set the number of simulated user groups to the size of the thread group; when the number of assembled threads reaches a preset target value, the synchronization timer is used to synchronously release the number of assembled threads; The statistics of successful and failed access to the API include: Count the number of successful and failed API accesses, and record the reasons for failed API accesses; The analysis module comprises: The first judgment module is used to judge whether the reason for the failed access to the API is access denied, and if so, execute the second judgment module; if not, execute the access module; The second judgment module is used to judge whether the number of successfully accessed APIs is equal to the current limiting size of the current limiting strategy. If so, the current limiting strategy is set successfully; if not, the current limiting strategy fails to be set.
5. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the current limiting strategy testing method as described in any one of claims 1 to 3 is implemented.
6. An electronic device, characterized in that: include: one or more processors; A storage device, used to store one or more programs, when the one or more programs are executed by the one or more processors, enables the one or more processors to implement the current limiting strategy testing method as described in any one of claims 1-3.
