Interface idempotent test method, computing device and computer readable storage medium

By generating shadow requests in the test device and automatically comparing the execution results, the problems of low efficiency and inaccurate results of traditional interface idempotence testing are solved, and automated testing is realized, improving efficiency and accuracy.

CN119739580AActive Publication Date: 2025-04-01HONOR DEVICE CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202510244584.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-03
Publication Date
2025-04-01
Estimated Expiration
2045-03-03

AI Technical Summary

Technical Problem

Traditional interface idempotence testing relies on manual testing and artificial comparison, resulting in inefficiency and inaccurate results.

Method used

The idempotence of the interface is determined by generating shadow requests in the test device and automatically comparing the execution results of the original request and shadow requests.

Benefits of technology

Without manual intervention, the test device can automatically perform interface idempotence testing, significantly improving testing efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119739580A_ABST
    Figure CN119739580A_ABST
Patent Text Reader

Abstract

The invention provides an interface idempotent test method, computing equipment and a computer readable storage medium, and relates to the technical field of communication. The method comprises the steps that a test device receives a first request, the first request is used for requesting idempotence of an interface corresponding to a service provided by a test application, and the first request carries request information of the service; then, generating a shadow request based on the first request, the request information of the service carried by the shadow request being the same as the request information of the service carried by the first request; then obtaining a first execution result obtained after the service is executed based on the request information carried by the first request and a second execution result obtained after the service is executed based on the request information carried by the second request; and determining whether the interface has idempotence based on the first execution result and the second execution result. Thus, the idempotent of the interface does not need to be manually tested, the testing device automatically tests the idempotent of the interface, and the testing efficiency and accuracy can be greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a method, a computing device, and a computer-readable storage medium for testing interface idempotence. Background Art

[0002] Applications can provide multiple services, and the application programming interface (API) has gradually become the main business entrance of applications. With the widespread application of APIs, the performance of APIs will affect the operation of applications. In order to find API defects in a timely manner, APIs need to be tested. API testing is also called interface testing, and its purpose is to verify whether the API meets the requirements of function, performance, reliability, security, etc. Among them, an important interface test is the interface idempotence test.

[0003] Interface idempotence means that for the same request, no matter how many times it is executed, the execution result of the request should be consistent. In other words, if an interface is called multiple times, but the result it produces is the same as when it is called only once, then this interface is considered idempotent. The purpose of interface idempotence testing is to verify whether the interface can maintain data consistency and service reliability when processing repeated requests.

[0004] Traditional interface idempotency testing often relies on manual testing and manual comparison of test results. Specifically, when the application is configured as the interface idempotency test mode, manually click the business control in the interface of the application being tested, and click twice. In response to the two click operations, the electronic device calls the interface to generate two requests, and then executes the two requests to obtain two execution results. Then manually compare the two execution results to see if they are consistent. This method is not only labor-intensive, but also prone to errors in the comparison of execution test results due to human factors (such as carelessness, blurred vision, etc.), which in turn leads to low efficiency of interface idempotency testing and inaccurate interface idempotency testing results. Summary of the invention

[0005] The present application provides a method, computing device and computer-readable storage medium for interface idempotence testing, which can improve the efficiency and accuracy of interface idempotence testing to a certain extent.

[0006] The present application provides a memory management method, a computing device, and a computer-readable storage medium, which can, to a certain extent, enable applications running in the foreground to have more sufficient memory usage, enable them to run more smoothly, and improve user experience.

[0007] In order to achieve the above objectives, this application adopts the following technical solutions: In a first aspect, the present application provides a method for testing the idempotence of an interface, which is applied to a testing device, and the method includes: receiving a first request, the first request being used to request the idempotence of an interface corresponding to a service provided by a test application, the first request carrying request information of the service; generating a shadow request based on the first request, the request information of the service carried by the shadow request being the same as the request information of the service carried by the first request; obtaining a first execution result and a second execution result, the first execution result being an execution result obtained after executing the service based on the request information carried by the first request, and the second execution result being an execution result obtained after executing the service multiple times based on the request information carried by the shadow request; determining whether the interface has idempotence based on the first execution result and the second execution result; wherein, when the first execution result is the same as the second execution result, the interface has idempotence; and when the first execution result is different from the second execution result, the interface does not have idempotence.

[0008] In the above scheme, the test device can determine the idempotence test result of the above interface based on the comparison result of the execution result of the request and the execution result of the shadow request. In this way, there is no need to manually test the idempotence of the interface. The test device automatically tests the idempotence of the interface, which can greatly improve the test efficiency and accuracy.

[0009] In a possible implementation manner of the first aspect, the first request may further carry indication information of the idempotence of the interface of the test service, so as to trigger the test device to perform the idempotence test of the interface.

[0010] In a possible implementation manner of the first aspect, the method further includes: sending a test result to the electronic device, where the test result is used to indicate whether the interface has idempotence.

[0011] In a possible implementation of the first aspect, the first execution result includes first status information and first response information of the business after executing the business based on the first request; the second execution result includes second status information and second response information of the business after executing the business based on the shadow request; when the first status information and the second status information are the same, and the first response information and the second response information are the same, the first execution result is the same as the second execution result; when the first status information and the second status information are different, and / or the first response information and the second response information are different, the first execution result is different from the second execution result.

[0012] In a possible implementation manner of the first aspect, obtaining the first execution result and the second execution result includes: sending a first request to a business server and sending shadow requests multiple times; and receiving the first execution result and the second execution result from the business server.

[0013] In a possible implementation manner of the first aspect, the number of times the shadow request is sent is 2 times.

[0014] In the above scheme, the shadow request is sent twice, and the idempotence of the interface is tested with a smaller number of sending times. On the one hand, the power consumption of testing the idempotence of the interface is reduced, and on the other hand, the efficiency of testing the idempotence of the interface is improved.

[0015] In a possible implementation manner of the first aspect, a time interval between two consecutive shadow requests is less than a threshold.

[0016] In the above scheme, since the time of sending the two shadow requests is close, this can simulate the concurrent call scenario and test the idempotence of the interface in the concurrent scenario.

[0017] In a possible implementation manner of the first aspect, obtaining the first execution result and the second execution result includes: executing a first request to obtain the first execution result; and executing multiple shadow requests to obtain the second execution result.

[0018] In the above scheme, the shadow request is sent multiple times, and the shadow request is executed multiple times accordingly.

[0019] In a possible implementation manner of the first aspect, the shadow request is executed twice.

[0020] In the above scheme, the shadow request is sent twice, corresponding to the shadow request being executed twice. Testing the idempotence of the interface with a smaller number of shadow request executions reduces the power consumption of testing the idempotence of the interface on the one hand, and improves the efficiency of testing the idempotence of the interface on the other hand.

[0021] In the second aspect, the present application provides a method for testing the idempotence of an interface, which is applied to a business server, comprising: receiving a first request and multiple shadow requests sent by a test device; the first request is used to request the idempotence of an interface corresponding to a business provided by a test application, the first request carries request information of the business, the shadow request carries request information of the business, and the request information of the business carried by the shadow request is the same as the request information of the business carried by the first request; executing the business based on the request information of the business carried by the first request to obtain a first execution result, and executing the business multiple times based on the request information of the business carried by multiple shadow requests, and sending the first execution result and the second execution result to the test device; wherein the first execution result and the second execution result are used to determine whether the interface has idempotence.

[0022] In the above solution, the business server sends the first execution result and the second execution result to the test device, so that the test device can determine the idempotence test result of the above interface based on the comparison result of the execution result of the request and the execution result of the shadow request. In this way, there is no need to manually test the idempotence of the interface. The test device automatically tests the idempotence of the interface, which can greatly improve the test efficiency and accuracy.

[0023] In a possible implementation of the second aspect, the first execution result includes first status information and first response information of the business after executing the business based on the first request; the second execution result includes second status information and second response information of the business after executing the business based on the shadow request.

[0024] In a possible implementation manner of the second aspect, the first state information is stored in a first data table of the service server, and the second state information is stored in a second data table of the service server.

[0025] In a possible implementation of the second aspect, before receiving the first request, the first data table stores initial status information of the business, and the second data table does not include status information of the business; after receiving the first request and multiple shadow requests sent by the test device, the method also includes: synchronizing the initial status information in the first data table to the second data table; wherein the first status information is status information after the initial status information of the business stored in the first data table is updated after the business is executed based on the first request; the second status information is status information after the initial status information of the business stored in the second data table is updated after the business is executed multiple times based on multiple shadow requests.

[0026] In the above solution, the business status information stored in the first data table is updated as the first request is executed, and the business status information stored in the second data table is updated as the shadow request is executed multiple times.

[0027] In a possible implementation manner of the second aspect, obtaining the first execution result and the second execution result includes: sending a first request to a business server and sending shadow requests multiple times; and receiving the first execution result and the second execution result from the business server.

[0028] In a possible implementation manner of the second aspect, the number of times the shadow request is sent is 2 times.

[0029] In the above scheme, the shadow request is sent twice, and the idempotence of the interface is tested with a smaller number of sending times. On the one hand, the power consumption of testing the idempotence of the interface is reduced, and on the other hand, the efficiency of testing the idempotence of the interface is improved.

[0030] In a possible implementation manner of the second aspect, a time interval between two consecutive shadow requests is less than a threshold.

[0031] In the above scheme, since the time of sending the two shadow requests is close, this can simulate the concurrent call scenario and test the idempotence of the interface in the concurrent scenario.

[0032] In a possible implementation manner of the second aspect, obtaining the first execution result and the second execution result includes: executing a first request to obtain the first execution result; and executing multiple shadow requests to obtain the second execution result.

[0033] In the above scheme, the shadow request is sent multiple times, and the shadow request is executed multiple times accordingly.

[0034] In a possible implementation manner of the second aspect, the shadow request is executed twice.

[0035] In the above scheme, the shadow request is sent twice, corresponding to the shadow request being executed twice. Testing the idempotence of the interface with a smaller number of shadow request executions reduces the power consumption of testing the idempotence of the interface on the one hand, and improves the efficiency of testing the idempotence of the interface on the other hand.

[0036] In a third aspect, the present application provides a method for testing the idempotence of an interface, which is applied to a test system, wherein the test system includes a test device and a service server, including: the test device receives a first request, the first request is used to request the idempotence of an interface corresponding to a service provided by a test application, and the first request carries request information of the service; the test device generates a shadow request based on the first request, and the request information of the service carried by the shadow request is the same as the request information of the service carried by the first request; the test device sends the first request to the service server, and sends the shadow request multiple times; the service server executes the service based on the request information of the service carried by the received first request, obtains a first execution result, and executes the service multiple times based on the request information of the service carried by the received multiple shadow requests, and the service server sends the first execution result and the second execution result to the test device; the test device determines whether the interface has idempotence based on the first execution result and the second execution result; wherein, when the first execution result is the same as the second execution result, the interface has idempotence; when the first execution result is different from the second execution result, the interface does not have idempotence.

[0037] In the above scheme, the test device can determine the idempotence test result of the above interface based on the comparison result of the execution result of the request and the execution result of the shadow request. In this way, there is no need to manually test the idempotence of the interface. The test device automatically tests the idempotence of the interface, which can greatly improve the test efficiency and accuracy.

[0038] In a fourth aspect, the present application provides a computing device, the computing device comprising at least: a memory and one or more processors. The memory is used to store computer instructions, and when the one or more processors execute the computer instructions, the computing device executes the method of any one of the first aspect or the second aspect.

[0039] In a fifth aspect, the present application provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on a computing device, the computing device executes a method as described in any one of the first or second aspects above.

[0040] In a sixth aspect, the present application provides a computer program product, which, when executed on a computing device, enables the computing device to execute a method as described in any one of the first or second aspects above.

[0041] Among them, the technical effects brought about by any design method in the fourth to sixth aspects can refer to the technical effects brought about by different design methods in the first, second and third aspects, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A schematic diagram of a test system provided in an embodiment of the present application is shown; Figure 2 A schematic diagram of the structure of a computer provided in an embodiment of the present application is shown; Figure 3 A schematic diagram of the structure of a testing device provided in an embodiment of the present application is shown; Figure 4 It is a flowchart of a method for testing interface idempotence; Figure 5 A schematic diagram of a computer interface showing test results of an interface having idempotency; Figure 6 A schematic diagram of a computer interface showing a test result of an interface not having idempotency; Figure 7 A schematic diagram of a computer interface showing an idempotence verification list is shown; Figure 8 A schematic diagram of a details page is shown; Fig. 9 A schematic diagram showing the structure of a service module of a service gateway and a service server provided in an embodiment of the present application is shown; Fig.10 A schematic diagram of the structure of a service module of a service gateway and a service server provided in another embodiment of the present application is shown. DETAILED DESCRIPTION

[0043] The technical solutions in the embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application. Among them, in the description of the embodiments of the present application, the terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "a", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one or more (including two). The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships can exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.

[0044] References to "one embodiment" or "some embodiments" etc. described in this specification mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Thus, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways. The term "connection" includes direct connection and indirect connection, unless otherwise specified. "First" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated.

[0045] In the embodiments of the present application, the words "exemplarily" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplarily" or "for example" is intended to present related concepts in a specific way.

[0046] As described in the background technology above, traditional interface idempotence testing often relies on manual testing and manual comparison of test results. This method is not only labor-intensive, but also prone to comparison errors in test results (such as the execution results of requests) due to human factors (such as carelessness, blurred vision, etc.), which in turn leads to low efficiency of interface idempotence testing and inaccurate interface idempotence testing results.

[0047] In order to solve this technical problem, an embodiment of the present application proposes a method for testing the idempotency of an interface. The method includes: when the application being tested is configured as an idempotency test mode, the electronic device installed with the application being tested can call an interface for implementing the service to generate a request after receiving a trigger operation of a user on a control of a certain service. After that, the electronic device can send the request to the test device. After the test device receives a request initiated by a call to an interface of the application being tested, a shadow request identical to the request can be automatically generated. The request and the shadow request are used to trigger the execution of the corresponding service. After the service is executed, a corresponding execution result can be generated. Then, the test device can obtain the execution result of the request and the execution result of the shadow request, and automatically compare the execution results. After that, the test device can determine the idempotency test result of the above interface based on the comparison result of the execution result of the request and the execution result of the shadow request. In this way, there is no need to manually test the idempotency of the interface, and the test device automatically tests the idempotency of the interface, which can greatly improve the test efficiency and accuracy.

[0048] The interface idempotence testing method provided in the embodiment of the present application can be applied to a test system, which is used to test the idempotence of an interface. For example, Figure 1 A schematic diagram of a test system provided in an embodiment of the present application is shown as follows: Figure 1 As shown, the test system includes an electronic device 100 and a test device. In some embodiments, as Figure 1 In (a), the test device is illustrated as the service gateway 200-1. The test device may also be a module or a combination of modules in the service gateway 200-1 for implementing the interface idempotence test, which is not specifically limited in the present embodiment of the application.

[0049] like Figure 1 As shown in (a), the electronic device 100 is installed with the application to be tested. The application can be a system application or a third-party application. The application to be tested can be various types of applications. For example, payment applications, shopping applications, enterprise management applications, game applications, video applications, etc., but not limited to these. The embodiments of the present application are not specifically limited here.

[0050] The application under test may provide one or more services. The above services may be services provided by the application under test whose corresponding interfaces need to be tested for idempotence. The interface under test is the interface corresponding to the above services.

[0051] A browser may be installed in the electronic device 100, and the tested application may also be opened in the browser. Specifically, the user may enter the URL of the tested application in the browser and perform an operation to open the URL, and the electronic device may respond to the operation to open the tested application.

[0052] When the application under test is configured in idempotency test mode, the electronic device 100 can generate a request by calling the interface corresponding to the service of the application under test based on the user's triggering operation on a control of a service in a certain interface of the application. Afterwards, the electronic device 100 can send the request to the service gateway 200-1, which can trigger the service gateway 200-1 to perform an idempotency test on the interface.

[0053] For example, after receiving the request, the business gateway 200-1 automatically generates a shadow request based on the request. The shadow request is the same as the request, such as the request information of the business carried by the request and the shadow request is the same. Then, the business gateway 200-1 can obtain the execution result of the request and the execution result of the shadow request. For example, the test system may also include a business server 200-2. The business gateway 200-1 and the business server 200-2 may be referred to as a business service system 200. The business gateway 200-1 may send the request and the shadow request to the business server 200-2. The business server 200-2 may execute the request and the shadow request to obtain the execution result of the request and the execution result of the shadow request, and feed it back to the business gateway 200-1. Afterwards, the business gateway 200-1 can obtain the execution result of the request and the execution result of the shadow request.

[0054] After the service gateway 200-1 obtains the execution result of the request and the execution result of the shadow request, it can automatically compare the execution results of the request and the shadow request, and determine the idempotence test result of the interface based on the comparison result of the execution results of the request and the shadow request. The service gateway 200-1 can also feedback the idempotence test result of the interface to the electronic device 100.

[0055] Specifically, in some embodiments, the service gateway 200-1 may generate multiple (such as two or more) shadow requests and send them to the service server 200-2 so that it can execute the multiple shadow requests. Afterwards, the service gateway 200-1 compares the execution result of the request with the execution results after executing the multiple shadow requests to determine the idempotence test result of the interface.

[0056] In this way, there is no need to manually test the idempotence of the interface. The business service system 200 can automatically test the idempotence of the interface, which can improve the efficiency and accuracy of the idempotence test of the interface to a certain extent.

[0057] It is understandable that the business server 200-2 may include one or more. Different business servers correspond to different businesses. For example, the transfer business corresponds to the transfer server, and the payment business corresponds to the payment server. Alternatively, one business server corresponds to different businesses of an application, for example, the payment business and the transfer business in the payment application correspond to a business server of the payment application. Different businesses can be triggered by different requests.

[0058] After receiving the request sent by the electronic device 100, the service gateway 200-1 may generate a shadow request and send the request and the shadow request to the service server 200-2. For example, the service server 200-2 may be a service server corresponding to the service requested by the request. Afterwards, the service server 200-2 corresponding to the service requested by the request executes the request and the shadow request to obtain the execution result of the request and the execution result of the shadow request.

[0059] Among them, in other embodiments, such as Figure 1 (b) in the figure is illustrated by taking the test device as the server 300. The test device may also be a module or a combination of modules in the server 300 for implementing the interface idempotence test, which is not specifically limited in the embodiment of the present application.

[0060] like Figure 1 As shown in (b), Figure 1 The electronic device 100 shown in (b) is the same as the above Figure 1 The electronic device is the same as that shown in (a) and will not be described again here.

[0061] When the application under test is configured in idempotency test mode, the electronic device 100 can generate a request by calling the interface corresponding to the service of the application under test based on the user's triggering operation on a control of a service in the interface of the application. Afterwards, the electronic device 100 can send the request to the server 300, which can trigger the server 300 to perform an idempotency test on the interface.

[0062] For example, after receiving the request, the server 300 automatically generates a shadow request based on the request. The shadow request is the same as the request, such as the request and the information carried by the shadow request are the same. Then, the server 300 can execute the request and the shadow request to obtain the execution result of the request and the execution result of the shadow request. After the server 300 obtains the execution result of the request and the execution result of the shadow request, the execution results of the request and the shadow request can be automatically compared, and the idempotence test result of the interface can be determined based on the comparison result of the execution results of the request and the shadow request. The server 300 can also feedback the idempotence test result of the interface to the electronic device 100. Specifically, in some embodiments, the server 300 can generate multiple (such as two, or more than two) shadow requests to execute these multiple shadow requests. Afterwards, the server 300 compares the execution result of the request and the execution result after executing multiple shadow requests to determine the idempotence test result of the interface.

[0063] That is, the server 300 has both the functions of the business server 200 - 2 and the functions of the business gateway 200 - 1 .

[0064] In this way, there is no need to manually test the idempotence of the interface, and the server 300 can automatically test the idempotence of the interface, which can improve the efficiency and accuracy of the idempotence test of the interface to a certain extent.

[0065] The electronic device 100 provided in the embodiment of the present application is a variety of devices that can be installed with the application to be tested. The electronic device 100 provided in the embodiment of the present application can be a computer, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), and other electronic devices. The embodiment of the present application does not impose any special restrictions on the specific form of the electronic device 100.

[0066] For example, the electronic device 100 is a computer. Figure 2 , which shows a schematic diagram of the structure of a computer provided in an embodiment of the present application. Figure 2 As shown, the computer may include: a processor 110, an internal memory 121, a universal serial bus (USB) interface 130, a display screen 150, an antenna, a communication module 160, an audio module 170, a speaker (i.e., a horn) 170A, a microphone 170C, an earphone interface 170B, a keyboard 190, and a camera 191, etc.

[0067] It is to be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the computer. In other embodiments, the computer may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0068] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a controller, a memory, etc. Among them, different processing units may be independent devices or integrated into one or more processors. In an embodiment of the present application, when the application under test is configured in idempotence test mode, the processor 110 may generate a request by calling the interface corresponding to the service of the application under test based on the user's triggering operation on a control of a service in the interface of the application, and send the request to other devices (such as a test device), and the request may trigger the test device to perform an idempotence test on the interface.

[0069] The controller can be the nerve center and command center of the computer. The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.

[0070] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0071] In some embodiments, the processor 110 may include one or more interfaces. The interface may include a USB interface, etc.

[0072] It is understandable that the interface connection relationship between the modules illustrated in this embodiment is only a schematic illustration and does not constitute a structural limitation on the computer. In other embodiments, the computer may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0073] In some embodiments, the antenna of the computer is coupled to the communication module 160, so that the computer can communicate with other devices through wireless communication technology. In the embodiment of the present application, the computer can communicate with the business service system through wireless communication technology.

[0074] The computer can implement the display function through the display screen 150. The display screen 150 is used to display images, videos, etc. In an embodiment of the present application, the display screen 150 can display the interface of the application. Among them, the application may include the application being tested. For example, the interface of the application being tested may include controls for various services of the application being tested. When the application is configured in idempotence test mode, the computer responds to the user's triggering operation on the control of a certain service, such as a click operation, and can call the interface corresponding to the service to generate a corresponding request, and then send a request to other devices (such as a test device), wherein the request is used to trigger other devices (such as a test device) to perform idempotence testing of the interface corresponding to the service.

[0075] Take the tested application as a shopping application as an example. For example, the interface of the shopping application may include a control for payment services, such as a payment control, which is used to implement payment services. When the shopping application is configured in idempotence test mode, the computer responds to the user clicking the payment control, calls the payment interface to generate a payment request, and then sends the payment request to other devices. The payment request is used to trigger other devices to perform idempotence testing of the payment interface.

[0076] Taking the tested application as a payment application as an example, for example, the interface of the payment application may include a control for the transfer service of the payment application, such as a transfer control, which is used to implement the transfer service. When the payment application is configured in idempotence test mode, the computer responds to the user clicking the transfer control, calls the transfer interface to generate a transfer request, and sends the transfer request to other devices. The transfer request is used to trigger other devices to perform idempotence test of the transfer interface.

[0077] Taking the enterprise management application as an example, the interface of the enterprise management application may include a control for saving the overtime application information of the enterprise management application, such as a save control, which is used to implement the overtime application information saving service. When the enterprise management application is configured in idempotency test mode, the computer may call the overtime application information saving interface to generate a request to save the overtime application information in response to the user clicking the save control of the overtime application information. The request to save the overtime application information is also used to trigger other devices to perform idempotency tests on the overtime application information saving interface.

[0078] For another example, the interface of the enterprise management application may include a control for the application service of the overtime application of the enterprise management application, such as an application control, which is used to implement the overtime application service. When the enterprise management application is configured in idempotency test mode, the computer responds to the user clicking the application control for the overtime application, calls the application interface of the overtime application to generate an application request for the overtime application. The application request for the overtime application is used to trigger other devices to perform idempotency test on the application interface of the overtime application.

[0079] The computer can realize the shooting function through the ISP, the camera 191 , the video codec, the GPU, the display screen 150 , and the application processor, etc. The ISP is used to process the data fed back by the camera 191 .

[0080] The internal memory 121 may be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the computer by running the instructions stored in the internal memory 121 .

[0081] The computer can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the microphone 170C, the headphone jack 170B, and the application processor.

[0082] The testing apparatus provided in the embodiments of the present application is various devices that can provide an idempotence testing function for an interface.

[0083] Please refer to Figure 3 , which shows a schematic diagram of the structure of a testing device provided in an embodiment of the present application. Figure 3 As shown, the test device may include one or more processors 240 , a memory 210 , and a communication interface 220 .

[0084] Among them, the memory 210, the communication interface 220 and the processor 240 are coupled. For example, the memory 210, the communication interface 220 and the processor 240 can be coupled together through the bus 230. Among them, the communication interface 220 is used to transmit data with other devices (such as the electronic device 100, and for example, the business server 200-2). Computer program code is stored in the memory 210. The computer program code includes computer instructions, and when the computer instructions are executed by the processor 240, the server executes the relevant method steps in the method embodiment of the present application. Among them, the processor 240 can be a processor or a controller, for example, it can be a central processing unit (CPU), etc.

[0085] In an embodiment of the present application, after the processor 240 receives a request initiated by a call to an interface of the application being tested, a shadow request identical to the request can be automatically generated. The request and the shadow request are used to trigger the execution of the corresponding business. After the business is executed, a corresponding execution result can be generated. Then, the processor 240 can obtain the execution result of the request and the execution result of the shadow request, and automatically compare the execution results. Afterwards, the processor 240 can determine the idempotence test result of the above-mentioned interface based on the comparison result of the execution result of the request and the execution result of the shadow request. In this way, there is no need to manually test the idempotence of the interface. The processor 240 automatically tests the idempotence of the interface, which can greatly improve the test efficiency and accuracy.

[0086] Among them, the structure of the above-mentioned business server is Figure 3 The results of the test setup shown are similar and will not be described in detail here.

[0087] The following embodiments take the test device as a service gateway as an example to introduce the solution of this application.

[0088] Figure 4 The following is a flowchart of a method for testing the idempotence of an interface. Take the electronic device as a computer as an example. Figure 4 As shown, the process includes the following steps: 401. In response to a first operation of a user on a control of a service, the computer calls an interface corresponding to the service to generate a first request, and sends the first request to a service gateway.

[0089] In some embodiments, an application may be installed on a computer, and the application may be configured to be in idempotency test mode. When the application is configured to be in idempotency test mode, the computer may display the main interface of the application after opening the application in response to a user operation. The computer may display the tested interface of the application in response to a user operation to open the tested interface of the application, and the tested interface of the application may include various controls of the application that allow the tested services. In this way, in response to a user operation on a control of a certain service, such as a first operation or a trigger operation, such as a click operation, the computer calls the interface corresponding to the service to generate a request, such as the above-mentioned first request. The first request is used to trigger other devices to perform idempotency tests on the interfaces corresponding to the service, and the first request is also used to trigger other devices to execute the service, see steps 402-408 for details.

[0090] In some embodiments, a browser may be installed in the computer, and the tested application may also be opened in the browser. Specifically, the user may enter the URL of the tested application in the browser and perform an operation to open the URL, and the computer may respond to the opening operation to open the tested application. After the electronic device opens the application, the opening method of the tested interface of the application and the first operation of the user on the control of the business have been described in the previous text and will not be repeated here.

[0091] Taking the above payment request as an example, the computer can send a payment request to the business gateway. Taking the above transfer request as an example, the computer can send a transfer request to the business gateway. Taking the above overtime application information save request as an example, the computer can send the overtime application information save request to the business gateway. Taking the above overtime application request as an example, the computer can send the overtime application application service to the business gateway.

[0092] The first request includes request information of the service. The first request may also include test indication information of the interface corresponding to the service. The first request may be a Hypertext Transfer Protocol (HTTP) request.

[0093] Taking the above-mentioned tested application as a shopping application and the first request as a payment request as an example, the request information of the service carried by the payment request may include information such as the payment amount and the payment method, and the payment method may include information such as bank card payment or other application payment. The test indication information of the interface corresponding to the service may be the test indication information of the payment interface corresponding to the payment service.

[0094] Taking the tested application as a payment application and the first request as a transfer request as an example, the request information of the service carried by the transfer request may include information such as the transfer amount and the account information to be transferred. The test indication information of the interface corresponding to the service may be the test indication information of the transfer interface corresponding to the transfer service.

[0095] Taking the tested application as an enterprise management application and the first request as a request to save overtime application information as an example, the request information of the service carried in the request to save overtime application information may include information such as overtime time period information, the name of the overtime worker, and the content of overtime. The test indication information of the interface corresponding to the service may be the test indication information of the interface for saving overtime application information corresponding to the service for saving overtime application information.

[0096] Taking the application under test as an enterprise management application and the first request as an application request for overtime application as an example, the service request information carried by the application request for overtime application may include information such as overtime time period information, the name of the overtime worker, the content of the overtime work, and the reviewer of the overtime application. The test indication information of the interface corresponding to the service may be the test indication information of the overtime application interface corresponding to the overtime application service.

[0097] 402. When receiving the first request, the service gateway copies the first request to obtain a shadow request, wherein the service request information carried by the shadow request is the same as the service request information carried by the first request.

[0098] After receiving the first request, the service gateway can copy the first request to obtain a shadow request that is identical to the first request. For example, the service request information carried by the shadow request is identical to the service request information carried by the first request. In this way, the service gateway can send multiple identical requests to the service server so that the service server can execute the same request multiple times, which is used to test the idempotence of the interface.

[0099] Taking the above-mentioned tested application as a shopping application and the first request as a payment request as an example, the request information of the service carried by the payment request may include information such as the payment amount and the payment method, and the payment method may include information such as bank card payment or other application payment. In this way, after receiving the payment request, the service gateway can copy the payment request to obtain a corresponding shadow request, such as a shadow payment request, and the request information of the service carried by the shadow payment request is the same as the request information of the service carried by the payment request. That is, the shadow payment request includes information such as the payment amount and the payment method, and the specific values ​​of these information are the same as the specific values ​​in the payment request.

[0100] Since the processing of a request may involve multiple devices (such as a service gateway and a service server) and multiple service modules within a device (such as a service server) (see below), Fig. 9 and Fig.10 ), in order to accurately track and locate the problem, a globally unique identifier is needed to identify the request, which is transmitted as the request is transmitted in multiple devices or multiple business modules in the device. Specifically, the globally unique identifier can be a trace identifier (traceidentity document, traceId). In some embodiments, the business gateway can write the trace identifier into the first request and the shadow request, so that both the first request and the shadow request carry traceId.

[0101] In the embodiment of the present application, traceId can ensure that during the entire request processing process, no matter how many service nodes (such as the service gateway and service server and each service module within the service server) the request passes through, it can be accurately identified and tracked. Moreover, traceId can associate the first execution result of the first request with the second execution result of the shadow request, so that the first execution result and the second execution result can be compared. The first execution result and the second execution result are described in detail in the subsequent step 404.

[0102] 403. The service gateway sends the first request and multiple shadow requests to the service server.

[0103] The shadow request is sent multiple times, such as twice, three times or more times. In this way, the service gateway can test the idempotence of the interface by sending multiple shadow requests to the service server.

[0104] If the shadow request is sent twice, the service gateway tests the idempotence of the interface with a smaller number of transmissions, which reduces the power consumption of the service gateway and service server in testing the idempotence of the interface on the one hand, and improves the efficiency of the service gateway and service server in testing the idempotence of the interface on the other hand.

[0105] In some embodiments, the interval between sending multiple shadow requests may not be limited. For example, taking sending two shadow requests to a service server as an example, the time between sending the shadow requests to the service server twice, that is, the interval between the two sending times, may be any time interval.

[0106] In other embodiments, the interval between sending multiple shadow requests is less than a threshold value, for example, the threshold value may be 2 milliseconds, 3 milliseconds, or other values. For example, take sending two shadow requests to a business server with a threshold of 2 milliseconds as an example. The time between the two shadow requests sent by the business gateway to the business server, that is, the interval between the two sending times, may be less than 2 milliseconds. It is understandable that since the time between the two sending of the shadow requests is close, this can simulate a concurrent call scenario and test the idempotence of the interface in a concurrent scenario.

[0107] 404. When receiving the first request and multiple shadow requests, the business server executes the first request to obtain a first execution result of the first request, and executes the multiple shadow requests to obtain a second execution result.

[0108] The business server executes multiple shadow requests, which can also be understood as the business server executing multiple shadow requests. The purpose of executing multiple shadow requests is to verify whether the interface has idempotency. Specifically, if the second execution result after executing multiple shadow requests is consistent with the first execution result of executing the first request once, the interface is determined to have idempotency. If the second execution result after executing multiple shadow requests is inconsistent with the first execution result of executing the first request once, the interface is determined to have no idempotency.

[0109] In some embodiments, the first execution result includes the state information of the business corresponding to the first request stored in the database of the business server, and the state information of the business is referred to as the first state information. The second execution result includes the state information of the business corresponding to the shadow request stored in the database of the business server, and the state information of the business is referred to as the second state information.

[0110] The first status information includes completion status information of the business corresponding to the first request, and the second status information includes completion status information of the business corresponding to the shadow request, and the completion status information of the business includes whether the business is completed or not completed.

[0111] An important comparison parameter for the idempotence test of the interface is whether the information of the business corresponding to the request in the database is consistent after executing the same request multiple times. In order to compare whether the information of the corresponding business in the database changes after executing the request and the corresponding shadow request, two independent data tables can be set in the database, one data table is the data table corresponding to the original request, such as data table 1, and the other data table is the data table corresponding to the shadow request, such as data table 2. These two independent data tables (such as the above data table 1 and data table 2) are pre-set, that is, they have been pre-set before executing step 401.

[0112] Among them, the data in data table 1 can be updated as the business progresses. For details, please refer to the description in the relevant technology, which will not be repeated here. Before executing the corresponding business (such as the business corresponding to the shadow request), data table 2 does not store data related to the business. In an embodiment of the present application, after receiving the first request and the shadow request, the data in data table 1 can be synchronized to data table 2.

[0113] Exemplarily, before the business server receives the first request and the shadow request, the status of data table 1 and data table 2 can be called the initial state. In the initial state, data table 1 stores the initial state information of the business corresponding to the first request. For example, the initial state information of the business corresponding to the first request is: the completion status information of the business corresponding to the first request is that the business is not completed. In the initial state, data table 2 does not store any business information.

[0114] Continuing to take the above-mentioned tested application as a shopping application and the first request as a payment request as an example, the data table 1 and the data table 2 in the initial state can refer to the following Table 1. For example, Table 1 shows a data table 1 and a data table 2 in an initial state.

[0115] Table 1

[0116] As shown in Table 1, in the initial state, Data Table 1 includes: Order A: Waiting for Payment information, which is used to indicate that the initial state information of the payment service corresponding to the payment request (such as the payment service of Order A) is unfinished. There is no data in Data Table 2, that is, Data Table 2 does not store the information of the payment service of Order A.

[0117] After receiving the first request and the shadow request, the business server can synchronize the initial state information of the business corresponding to the first request to data table 2 in the following manner: For example, the business server can copy the initial state information of the business corresponding to the first request in data table 1 to data table 2. The initial state information of the business corresponding to the first request copied to data table 2 can be called shadow initial state information. Among them, the shadow initial state information is: the completion status information of the business corresponding to the first request (or shadow request) is that the business is not completed. That is, the shadow initial state information is the same as the initial state information.

[0118] Continuing to take the above-mentioned tested application as a shopping application and the first request as a payment request as an example to illustrate the data table 1 and data table 2 after data synchronization. For example, Table 2 shows the information in data table 1 and data table 2 after synchronizing (or copying) the information in data table 1.

[0119] Table 2

[0120] As shown in Table 2, Data Table 1 includes the information: Order A: Waiting for Payment. Data Table 2 also includes the information: Order A: Waiting for Payment, which is used to indicate that the initial status information of the payment service (such as the payment service of Order A) corresponding to the payment request (or shadow payment request) is currently unfinished.

[0121] After completing the synchronization of the data in data table 1 to data table 2, the business server can execute the first request. After the execution of the first request is completed, the business server can also update the state information of the business corresponding to the first request recorded in data table 1, such as the updated state information of the business is the above-mentioned first state information.

[0122] Continuing to take the above-mentioned tested application as a shopping application and the first request as a payment request as an example, after the first request is executed, data table 1 and data table 2 may be as shown in Table 3. For example, Table 3 shows information of data table 1 and data table 2 after the first request is executed.

[0123] Table 3

[0124] As shown in Table 3, after executing the first request, such as a payment request, data table 1 includes information: Order A: Paid, which indicates that the status information of the payment service corresponding to the payment request is that the service is completed. Data table 2 includes information that is not updated, that is, it is still Order A: Waiting for payment.

[0125] After executing the first request, the business server can also execute the shadow request multiple times. If the interface corresponding to the business does not have idempotency, the business server will update the status information of the business corresponding to the shadow request recorded in Data Table 2 once after each shadow request is executed. If the interface corresponding to the business has idempotency, the business server will only update the status information of the business corresponding to the shadow request recorded in Data Table 2 once after the first execution of the shadow request, and the subsequent execution of the shadow request multiple times will not update the business information in Data Table 2. After executing the shadow request multiple times, the status information of the business saved in Data Table 2 is the above-mentioned second status information.

[0126] Continuing to take the above-mentioned tested application as a shopping application, the first request is a payment request, the shadow request is a shadow payment request, and executing two shadow requests as an example. In the case where the payment interface has idempotence, after the two shadow requests are executed, data table 1 and data table 2 may be as shown in Table 4. For example, Table 4 shows information of data table 1 and data table 2 after two shadow requests are executed.

[0127] Table 4

[0128] As shown in Table 4, after executing two shadow requests, such as shadow payment requests, the information included in Data Table 1 is not updated, that is, Order A: Paid is still not available. Data Table 2 includes the information Order A: Paid, which is used to indicate that the status information of the payment service corresponding to the shadow payment request is that the service is completed.

[0129] It should be noted that the above embodiment takes the example of executing the first request first and then executing the shadow request as an example to illustrate the data update process of database 1 and database 2. In some other embodiments, the shadow request may be executed first and then the first request, or the first request and the shadow request may be executed at the same time, and the embodiment of the present application does not make specific limitations here.

[0130] After the first request and the shadow request are executed, the service server can obtain, for example, from data table 1 and data table 2, status information of the services corresponding to the two requests, such as the first status information and the second status information.

[0131] In some embodiments, the first execution result also includes response information, which includes the completion status of the business corresponding to the first request. The second execution result also includes response information, which includes the completion status of the business corresponding to the shadow request. In order to distinguish the response information corresponding to the first request and the response information corresponding to the shadow request, the response information corresponding to the first request can be referred to as the first response information, and the response information corresponding to the shadow request can be referred to as the second response information. After the first request and the shadow request are executed, the business server can also generate response information for the two requests, such as the first response information and the second response information mentioned above, and feed it back to the business gateway.

[0132] It can be understood that the response information can be a Hypertext Transfer Protocol (HTTP) response message. As an example, the HTTP response message can include: a status line, a response header, and a response body. Among them, a blank line can be included after the response header to separate the header (such as including the status line and the response header) and the response body.

[0133] The Status Line includes the HTTP version, status code (such as 200 for success) and status message (such as "OK"). Taking the above payment request as an example, the status code for Order A being paid would be 200.

[0134] Response Headers: Contains metadata about the response, such as content type (Content-Type), content length (Content-Length), business server information (Server), etc.

[0135] Response Body: It is the actual content returned by the business server, which can be HTML pages, pictures, videos, JSON or XML data, etc. Taking the above payment request as an example, the response body content of order A that has been paid includes: payment status: success, payment amount: ***, payment serial number: ***.

[0136] 405. The service gateway obtains the first execution result and the second execution result from the service server.

[0137] As described above, the first execution result may include first state information. The first execution result may also include first response information. Similarly, the second execution result may include second state information. The second execution result may also include second response information.

[0138] It is understandable that when the first request and multiple shadow requests are executed, the service gateway can receive the first response information and the second response information fed back from the service server. After receiving the first response information and the second response information, the service gateway can obtain the first status information and the second status information stored in the data table of the service server from the service server.

[0139] Since the first execution result includes the first status information stored in the database of the business server, and the second execution result includes the second status information stored in the database of the business server, it is convenient for subsequent steps to automatically compare the database data changes caused by the original request and the shadow request to verify whether multiple requests will have additional impact on the database of the business server, that is, to verify whether the corresponding interface has idempotence.

[0140] 406. The service gateway determines whether the interface has idempotence based on the first execution result and the second execution result.

[0141] It is understandable that after the business server executes the first request, it obtains execution result 1. In order to ensure that the business is not executed repeatedly, if the business server determines that the business has been completed based on the information that the business has been completed in execution result 1, it will not execute the business again, and will not change execution result 1. Therefore, if the execution of the second request does not change the execution result after the execution of the first request, it means that the interface corresponding to the business has idempotence.

[0142] After the business server executes the first request, it obtains execution result 1. If the business is executed repeatedly for some reason, the execution result 1 will be changed. Therefore, if the execution result after the first request is changed by executing the second request, it means that the interface corresponding to the business does not have idempotence.

[0143] Based on the above principles, the first execution result after the execution of the first request can be used as reference data and compared with the execution results obtained after executing the shadow request multiple times, such as the second execution result, to determine whether the interface corresponding to the business has idempotency. Take the execution of two shadow requests as an example. If the execution of the second shadow request does not change the execution result after the execution of the first shadow request, the execution result after the execution of the second shadow request will be the same as the execution result 1 in the reference data, indicating that the interface corresponding to the business has idempotency. If the execution of the second shadow request changes the execution result 1 after the execution of the first shadow request, the execution result after the execution of the second shadow request will be different from the execution result 1 in the reference data, indicating that the interface corresponding to the business does not have idempotency.

[0144] Specifically, in some embodiments, the first execution result includes the state information of the business corresponding to the first request stored in the database, such as the first state information, and the response information corresponding to the first request, such as the first response information; the second execution result includes the state information of the business corresponding to the shadow request stored in the database, such as the second state information, and the response information corresponding to the shadow request, such as the second response information. When the business gateway determines that the first state information stored in the database of the business server is the same as the second state information, and the first response information is the same as the second response information, it determines that the interface has idempotence.

[0145] In this way, the business gateway can automatically compare whether the execution results of multiple requests are consistent without manual comparison, which can greatly improve testing efficiency and accuracy.

[0146] Continuing with the above-mentioned tested application as a shopping application, the first request is a payment service, such as a payment request for order A, and the interface is a payment interface as an example to explain how to determine whether the interface has idempotency. If the completion status information of order A in data table 1 is the same as the completion status information of order A in data table 2, and the content of the response information corresponding to the payment request is the same as the content of the response information corresponding to the shadow payment request, then it is determined that the payment interface has idempotency. If the completion status information of order A in data table 1 is different from the completion status information of order A in data table 2 and / or the content of the response information corresponding to the payment request is different from the content of the response information corresponding to the shadow payment request, then it is determined that the payment interface does not have idempotency.

[0147] The first execution result and the second execution result may be different in the following cases: 1. The second state information stored in the data table in the business server is different from the first state information, and the second response information is the same as the first response information.

[0148] 2. The second state information stored in the data table of the business server is different from the first state information, and the second response information is different from the first response information.

[0149] 3. The second state information stored in the data table of the business server is different from the first state information, and the second response information is different from the first response information.

[0150] When the first execution result is different from the second execution result, it is determined that the interface does not have idempotence.

[0151] In some embodiments, comparing the first response information and the second response information may refer to comparing the status code and / or response body information in the status line of the first response information and the status code and / or response body information in the status line of the second response information.

[0152] 407. The business gateway sends a test result of whether the interface has idempotency to the computer.

[0153] If the business gateway determines that the interface has idempotency, the business gateway sends the test result that the interface has idempotency to the computer. If the business gateway determines that the interface does not have idempotency, the business gateway sends the test result that the interface does not have idempotency to the computer.

[0154] 408. Test results of whether the computer output interface has idempotency.

[0155] In some embodiments, the computer may display the test result of whether the interface has idempotency in text form on the application interface. For example, Figure 5 A schematic diagram of a computer interface showing test results of an interface having idempotency is shown. Figure 5 As shown, the computer may display on interface 101: interface idempotency verification is successful, which is used to indicate that the interface corresponding to the tested service has idempotency.

[0156] Another example: Figure 6 A schematic diagram of a computer interface showing a test result of an interface not having idempotency. Figure 6 As shown, the computer can display on the interface 101: The interface idempotency verification failed, which indicates that the interface corresponding to the tested business does not have idempotency. The computer can also display a prompt message on the interface 101: Please query the database for details. The trace identifier in the trace table: 8d4e7b2f. The traceld in the trace table is 8d4e7b2f, which means: during the idempotency test verification process, the traceld of the request generated by calling the tested interface and the shadow request of the request is 8d4e7b2f. Based on the traceld being 8d4e7b2f, the idempotency test results of the interface with the traceld can be queried, and the related execution results can also be queried, such as response information and business status information.

[0157] In some embodiments, the computer may display an idempotency verification list, which includes idempotency test results of multiple business corresponding interfaces of the tested application and search condition options. The search condition options are used to filter idempotency test results of interfaces that meet certain conditions.

[0158] The search condition options may include an idempotency option, a start time and an end time option, and a Traceld / URL option, but are not limited thereto. The idempotency option includes two options: idempotency and non-idempotency. The idempotency option is used to filter the test results of interfaces with idempotency, and the non-idempotency option is used to filter the test results of interfaces without idempotency. The start time and end time option filters the test results of whether the tested interface has idempotency within the time period from the start time to the end time according to the start time and end time entered by the user. The Traceld / URL (Uniform Resource Locator, URL) option is used to filter the idempotency test results of interfaces with Traceld or URL when the user enters Traceld or uniform resource locator.

[0159] After the user selects the search condition to be searched in the idempotence verification list, the user can query the idempotence test results of the interface that meets the search condition selected by the user, which provides a high user experience.

[0160] For example, Figure 7 FIG. 1 shows a schematic diagram of a computer interface that displays an idempotence verification list. Figure 7 As shown, the computer displays interface 102, and interface 102 includes an idempotency verification list. The idempotency verification list includes idempotency options, start time and end time options, Traceld / URL options, search controls, reset controls, and idempotency test results of interfaces that meet the aforementioned setting conditions (for example, whether the idempotency option is set to all). The idempotency test results include Traceld, request URL, request time, and idempotency detailed information.

[0161] The idempotence verification list also includes an operable view details control. In response to the user's operation on the view details control, the computer can expand a details page, which includes the execution result of the request and the execution result of the shadow request. It can be understood that in some embodiments, the user's operation on the detail control can be clicking the view details control, but is not limited thereto.

[0162] For example, Figure 8 A schematic diagram of a detail page is shown. Figure 8 As shown, the computer displays an interface 103, which includes the execution result of the request and the execution result of the shadow request. The execution result includes the response information of the request and the information of the business corresponding to the request stored in the database.

[0163] exist Figure 8In the example, the first response information of the first request and the second response information of the shadow request are the same. The first status indicates the status information of the payment service, that is, the completion information of the payment service, success indicates that the payment has been completed, orderID indicates the identification information of the order table, and the second status indicates the processing status information of the order. The processing status of the order includes at least two states: processed and unprocessed. Completed indicates that the order has been processed.

[0164] It can be understood that a data table is a collection of structured data consisting of rows and columns. In a data table, each row represents a record, and each row includes a field name and a field. The field is the actual data of the field name. Among them, the primary key is one or more fields in the table, and its value can uniquely identify a record in the table.

[0165] Data Table 1 includes the field names and values ​​of the order table (t-order) and the payment table (t-order-payment). The field name of the order table is id, and its value is 12345. The field name of the order table is Order-status, and its value is pending. The field name of the payment table (t-order-payment) is payment-status, and its value is unpaid.

[0166] Among them, id indicates identification information, Order-status indicates order status, pending indicates not yet processed, payment-status indicates payment status, and unpaid indicates unpaid.

[0167] The information in Data Table 2 includes the field names and values ​​of the order table (t-order) and the payment table (t-order-payment). The field name of the order table is id, and the value is 12345. The field name of the order table is Order-status, and the value is completed. The field name of the payment table (t-order-payment) is payment-status, and the value is paid.

[0168] Among them, completed means processed, and paid means paid.

[0169] The example above shows that the interface is not idempotent, because the order status in data table 1 is not processed yet, and the payment status of the order is unpaid, while the order status in data table 2 is processed, and the payment status of the order is paid. The completion status of the payment business in the database is different.

[0170] It can be understood that the above is only an example of the first execution result of the first request and the second execution result of the shadow request, and the forms of the first execution result and the second execution result are not limited thereto.

[0171] In some embodiments, the computer can display the test result of whether the interface has idempotency in text form on the application interface, and can also broadcast the test result of whether the interface has idempotency to the user in voice form.

[0172] The following is a detailed introduction to the structure of a service gateway and service server for implementing interface idempotence testing services. Fig. 9 FIG. 1 shows a schematic diagram of the structure of a service module of a service gateway and a service server provided in an embodiment of the present application. Fig. 9 As shown, the service gateway includes a module 200-11 for copying request, a module 200-12 for comparing response information, and a module 200-13 for comparing service status information.

[0173] The copy request module 200-11 is used to copy the first request to obtain a shadow request when receiving the first request sent by the electronic device 100. The related technology of the shadow request has been described above and will not be repeated here.

[0174] The module 200-12 for comparing response information is used to compare the first response information of the first request fed back by the business server and the second response information of the shadow request to determine whether the two pieces of information are consistent.

[0175] The module 200-13 for comparing the status information of the business is used to compare the first status information of the business corresponding to the first request and the second status information of the business corresponding to the shadow request in the database 200-22 to determine whether the two pieces of information are consistent.

[0176] If the service gateway determines that the above two pieces of information are consistent, it determines that the interface is idempotent.

[0177] The server includes a business module 200 - 21 and a database 200 - 22 .

[0178] Among them, the business module 200-21 is used to execute the first request and the shadow request. The database 200-22 includes a data table 1 and a data table 2, and the data table 1 and the data table 2 are independent data tables. Before the business module 200-21 executes the first request and the shadow request, the business server synchronizes the initial state information of the business corresponding to the first request in the data table 1 to the data table 2. After the business module 200-21 executes the first request and the shadow request, the initial state information of the business in the data table 1 and the data table 2 are updated respectively, and the initial state information of the business in the data table 1 is updated to the first state information, and the initial state information of the business in the data table 2 is updated to the second state information. The first state information and the second state information have been described in the previous text and will not be repeated here.

[0179] The following specifically introduces another structure of a service gateway and service server for implementing interface idempotence testing services. For example, Fig.10 FIG. 1 shows a schematic diagram of the structure of a service module of a service gateway and a service server provided in an embodiment of the present application. Fig.10 As shown, in Fig. 9 Based on the structure of the business gateway in the embodiment, the business gateway also includes a tracking identifier generation module 200-14, which is used to generate a tracking identifier when receiving a first request sent by the electronic device 100, and send the first request and the tracking identifier of the first request to the copy request module 200-11. After the copy request module 200-11 copies the first request to obtain a shadow request, it writes the tracking identifier for the first request and the shadow request identifier. The tracking identifier has been introduced in the previous text and will not be repeated here.

[0180] like Fig.10 As shown, in Fig. 9 Based on the structure of the business server in the example, the business module 200 - 21 includes a filter 200 - 211 , an interceptor 200 - 212 and an information collection module (Context) 200 - 213 .

[0181] Filters 200 - 211 are used to manage the execution and feedback of requests and map the tracking identifiers to the first request and the shadow request to data table 3 .

[0182] Specifically, the filter 200-211 is used to determine whether to continue processing the first request and the shadow request when receiving the first request and the shadow request. For example, if the first request does not comply with certain security rules, the filter 200-211 may refuse to execute the first request. If the shadow request does not comply with certain security rules, the filter 200-211 may refuse to execute the shadow request.

[0183] The filter 200-211 is used to determine whether to feed back the first response information and the second response information to the service gateway when receiving the first response information of the first request and the second response information of the shadow request. For example, if the first response information does not comply with certain security rules, the filter 200-211 may refuse to feed back the first response information to the service gateway. If the shadow response information does not comply with certain security rules, the filter 200-211 may refuse to feed back the shadow response information to the service gateway.

[0184] The information collection modules 200-213 are used to store information that can facilitate sharing and calling of different modules in the business server. For example, the information collection modules 200-213 can store whether the interface of the business corresponding to the first request has been tested for idempotence, and the mapping relationship between the first request, the interface of the business, and the tracking identifier.

[0185] Interceptors 200-212 are used to switch the data table of the current operation (such as query, update, insert, etc.) to the target data table to perform operations on the target data table. For example, the data table of the current operation (such as query, update, insert, etc.) is data table 1. When the preset conditions are met, the target data table becomes data table 2, and data table 1 is switched to data table 2 to perform corresponding operations (such as update, insert, etc.) on data table 2. The preset conditions are: the first request is a shadow first request, and the operation on data table 2 is an update or insert operation. The update operation may refer to the operation of synchronizing the initial status information of the business in data table 1 to data table 2 as mentioned above, or it may refer to the operation of updating the initial status information of the business in data table 1 after executing the first request, and it may refer to the operation of updating the initial status information of the business in data table 2 after executing the first shadow request.

[0186] In the process of executing the first request, the interceptor 200-212 is also used to cache the name of the data table being operated and the unique identifier (Identification, ID) generated by updating the fields in certain (such as 1 or more) records in the data table in the information collection module 200-213. Among them, the ID is used to distinguish different records. Updating the fields in certain records in the data table refers to updating the status information of the business in the previous text. After executing the first request, the interceptor (Interceptor) 200-212 is used to store the name of the data table being operated and the ID generated by updating the fields in certain records in the data table in the data table 3. For example, after executing the first request, the fields in certain records in the data table are updated, and the one or more records constitute the first status information.

[0187] Similarly, after executing the shadow request, the interceptors 200-212 are used to store the name of the operated data table and the ID generated by updating the fields in certain records in the data table in data table 3. After executing the shadow request, the interceptors 200-212 are also used to store the name of the operated data table and the ID generated by updating the fields in certain records in the data table in data table 3. For example, after executing the second shadow request, the fields in certain records in the data table are updated, and the one or more records constitute the second state information.

[0188] In some embodiments, the interceptors 200-212 may be Mybatis interceptors.

[0189] Since the ID of the first state information and the ID of the second state information are stored in data table 3, module 200-13 for comparing the state information of the service can obtain the first state information from data table 1 according to the ID of the first state information, and obtain the second state information from data table 2 according to the ID of the second state information, and then compare whether the first state information and the second state information are equal. The service gateway can obtain the first comparison result of the first response information and the second response information from module 200-12 for comparing the response information, and obtain the second comparison result of the first state information and the second state information from module 200-13 for comparing the state information of the service, and determine whether the interface of the service has idempotence according to the first comparison result and the second comparison result. The technology for determining whether the interface of the service has idempotence according to the first comparison result and the second comparison result has been introduced in the previous text and will not be repeated here.

[0190] In the embodiment of the present application, there is no need to manually test the idempotence of the interface. The business service system 200 can automatically test the idempotence of the interface, which can improve the efficiency and accuracy of the interface idempotence test to a certain extent.

[0191] An embodiment of the present application also provides a computer storage medium, which includes computer instructions. When the computer instructions are executed on the above-mentioned electronic device 100 or a computing device such as a test device, the electronic device 100 or a computing device such as a test device executes the above-mentioned corresponding steps.

[0192] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computing device such as the electronic device 100 or a test device, the computing device such as the electronic device 100 or the test device executes the above corresponding steps.

[0193] It is understandable that the terminal device provided in the embodiment of the present application includes a hardware structure and / or software module corresponding to each function in order to realize the above functions. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiment disclosed herein, the embodiment of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiment of the present application.

[0194] The embodiment of the present application can divide the functional modules of the above-mentioned terminal device according to the above-mentioned method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0195] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0196] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0197] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0198] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0199] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0200] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A method for testing interface idempotence, characterized in that: The method is applied to a testing device, and the method comprises: receiving a first request, where the first request is used to request idempotence of an interface corresponding to a service provided by a test application, and the first request carries request information of the service; generating a shadow request based on the first request, wherein the request information of the service carried by the shadow request is the same as the request information of the service carried by the first request; Obtain a first execution result and a second execution result, wherein the first execution result is obtained by executing the business based on the request information carried by the first request, and the second execution result is obtained by executing the business multiple times based on the request information carried by the shadow request; Determining whether the interface has idempotence based on the first execution result and the second execution result; In which, when the first execution result is the same as the second execution result, the interface has idempotency; when the first execution result is different from the second execution result, the interface does not have idempotency.

2. The method according to claim 1, characterized in that The first execution result includes first status information and first response information of the service after the service is executed based on the first request; the second execution result includes second status information and second response information of the service after the service is executed based on the shadow request; When the first state information is the same as the second state information, and the first response information is the same as the second response information, the first execution result is the same as the second execution result; When the first state information and the second state information are different, and / or the first response information and the second response information are different, the first execution result and the second execution result are different.

3. The method according to claim 1 or 2, characterized in that: The obtaining of the first execution result and the second execution result includes: Sending the first request to the business server, and sending the shadow request multiple times; The first execution result and the second execution result are received from the service server.

4. The method according to claim 3, characterized in that The shadow request is sent twice.

5. The method according to claim 4, characterized in that The time interval between two consecutive sending of the shadow requests is less than a threshold.

6. The method according to claim 1 or 2, characterized in that: The obtaining of the first execution result and the second execution result includes: executing the first request to obtain the first execution result; Execute the shadow request multiple times to obtain the second execution result.

7. The method according to claim 6, characterized in that The shadow request is executed twice.

8. A method for testing interface idempotence, characterized in that: The method is applied to a business server and includes: Receive a first request and multiple shadow requests sent by a test device; the first request is used to request the idempotence of an interface corresponding to a service provided by a test application, the first request carries request information of the service, the shadow request carries request information of the service, and the request information of the service carried by the shadow request is the same as the request information of the service carried by the first request; executing the service based on the request information of the service carried by the first request to obtain a first execution result, and executing the service multiple times based on the request information of the service carried by the multiple shadow requests, A first execution result and a second execution result are sent to the test device; wherein the first execution result and the second execution result are used to determine whether the interface has idempotence.

9. The method according to claim 8, characterized in that The first execution result includes first status information and first response information of the business after the business is executed based on the first request; the second execution result includes second status information and second response information of the business after the business is executed based on the shadow request.

10. The method according to claim 9, characterized in that The first status information is stored in a first data table of the service server, and the second status information is stored in a second data table of the service server.

11. The method according to claim 10, characterized in that Before receiving the first request, the first data table stores initial status information of the service, and the second data table does not include status information of the service; After the receiving the first request and the plurality of shadow requests sent by the test device, the method further comprises: synchronizing the initial state information in the first data table to the second data table; Among them, the first status information is status information after the initial status information of the business stored in the first data table is updated after the first request executes the business; the second status information is status information after the initial status information of the business stored in the second data table is updated after the multiple shadow requests execute the business multiple times.

12. A method for testing interface idempotence, characterized in that: The method is applied to a test system, which includes a test device and a service server, including: The testing device receives a first request, where the first request is used to request to test the idempotence of an interface corresponding to a service provided by an application, and the first request carries request information of the service; The testing device generates a shadow request based on the first request, wherein the request information of the service carried by the shadow request is the same as the request information of the service carried by the first request; The testing device sends the first request to the business server, and sends the shadow request multiple times; The service server executes the service based on the received first request carrying the request information of the service, obtains a first execution result, and executes the service multiple times based on the received multiple shadow requests carrying the request information of the service, The business server sends a first execution result and a second execution result to the testing device; The testing device determines whether the interface has idempotence based on the first execution result and the second execution result; In which, when the first execution result is the same as the second execution result, the interface has idempotency; when the first execution result is different from the second execution result, the interface does not have idempotency.

13. A computing device, characterized in that: The computing device includes at least a memory and one or more processors; the memory is used to store computer instructions, and when the one or more processors execute the computer instructions, the computing device executes the method as described in any one of claims 1 to 7, or the computing device executes the method as described in any one of claims 8-11.

14. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on a computing device, cause the computing device to execute the method according to any one of claims 1 to 7, or cause the computing device to execute the method according to any one of claims 8 to 11.

15. A computer program product, characterized in that When the computer program product is executed on a computing device, the computing device is caused to execute the method according to any one of claims 1 to 7, or the computing device is caused to execute the method according to any one of claims 8 to 11.

Citation Information

Patent Citations

  • Method and apparatus for testing idempotent validity, equipment and readable medium

    CN108874654A

  • Idempotent validity detection method, device and equipment

    CN110380929A

  • Verification method and device

    CN112905492A

  • Pressure testing method and device

    CN113434384A

  • Testing functional correctness and idempotence of software automation scripts

    US20140282433A1