Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In this embodiment of the present application, the real service interaction may refer to: a real user or a plurality of real users interact with the service server in a period of time.
In the related art, when a service test is performed, simulation of a single scene is simple, and when a composite scene needs to be simulated, statistical analysis needs to be performed on historical service data to obtain each service and the proportion of each scene of each service, which is difficult to perform, and even if the proportion is determined, each service request for the service test is difficult to generate and send according to the process of real service interaction, so that the problems mentioned in the background art can be caused.
In order to solve the above problems, in the embodiment of the present application, various complex statistical analyses may be bypassed, and the real service interaction process may be restored directly according to the service log of the real service interaction, so that both a single scene and a composite scene may be simulated truly, and further, a service test may be performed to obtain a test result with better practicability. It should be noted that the scheme of the application is applicable to performance tests such as pressure tests and load tests, and is also applicable to functional tests. The following specifically describes the embodiments of the present application.
Fig. 1 is a process of a service testing method provided in an embodiment of the present application, where an execution subject of the process may be a general terminal or server, or may be a terminal or server dedicated to testing. The terminal includes but is not limited to: personal computers, cell phones, tablet computers, smart watches, vehicle-mounted mobile stations, and the like; the server includes but is not limited to: personal computers, mid-and large-sized computers, computer clusters, and the like. The execution body does not constitute a limitation of the present application.
The process in fig. 1 may specifically include the following steps:
s101: and acquiring a test template generated according to a service log generated by real service interaction, wherein the test template reflects service information and interaction process information corresponding to the real service interaction.
The real service interaction may be performed in any time period, and may be participated by any number of users, which is not limited in this embodiment of the present application. In practical application, a time period matched with the test requirement can be determined according to the test requirement, and then a test template generated according to a service log generated by real service interaction in the matched time period is obtained for subsequent steps.
For example, assume that a service is to be stressed according to test requirements. Historical traffic data statistics show that 8 to 9 pm is the peak period of the traffic, during which the number of users interacting with the traffic server for the traffic is the largest. It can be considered that, in practical applications, the time period when the pressure of the traffic server is the maximum is the peak time period, and therefore, the peak time period can be determined as the time period matching the test requirement.
In the embodiment of the present application, the method for generating the service log according to the real service interaction is not limited. Generally, a service server records corresponding service logs aiming at service interaction processes with users, and the service logs can be directly used for implementing the scheme of the application, so that the implementation cost of the scheme of the application can be reduced; of course, the format of the service log may also be specially predefined for the scheme of the present application, so that the service log at least includes the information field required by the scheme of the present application, which may improve the efficiency of subsequently parsing the service log.
In the embodiment of the present application, information related to the service interaction process, such as a service type, a service parameter, a service interaction time, and the like, may be recorded in the service log, where the service parameter includes, but is not limited to, a server identifier, a service request number, a user identifier, a parameter for recording a service resource, and the like.
Further, according to the service log, the real service interaction process can be restored. The restored real service interaction process can be represented in a format by using the test template generated in step S101. The restored real service interaction process mainly comprises the following two parts of information:
and the first part is that the real service interacts with the corresponding service information. The service information may reflect information of a service itself related to the real service interaction, and may be a service type, a service parameter, a dynamic service parameter generated after the service parameter is converted, and the like.
And the second part is interactive process information corresponding to real service interaction. The real service interaction may involve at least one message of the service request and/or a corresponding response message, and the interaction procedure information may reflect a logical order and a transceiving time order between the messages involved in the real service interaction.
S102: and generating a service test task according to the test template and the preset test data.
In an embodiment of the present application, the predetermined test data may include template assignment data and/or test requirement data.
The template assigned data can be used for filling a test template, and the test template can be used as an executable task after filling; further, the test requirement data may be used to indicate a particular manner of execution of the executable task, such as when execution begins, by several task executors, a number of concurrent executions of the executable task, and so forth.
S103: and executing the service test task to obtain a service test result.
In the embodiment of the present application, the executing of the service test task may specifically be: and simulating one or more users according to the service test task, and sending a specified service request to the service server at a specified time. The number of users and the number of service requests are determined by service testing tasks, and the service requests may be independent from each other or have a dependency relationship.
The service test task can be executed in a single thread or in multiple threads. Furthermore, when the multi-thread execution is performed, the single-machine multi-thread execution can be performed, the multi-machine multi-thread execution can also be performed, and the service test tasks can be distributed to the threads to be executed according to a preset distribution mode.
In this embodiment of the application, the service test result may be a service processing result returned by the service server in the process of executing the service test task, or may be an analysis result obtained after analyzing the service processing result.
By the method, the service test task is generated based on the real service interaction, so that the obtained test result can reflect the service function or performance of the service server during the real service interaction by executing the service test task, and the practicability is better.
The steps in fig. 1 are further described for ease of understanding.
In the embodiment of the present application, the test template may be generated in advance, or may be generated in real time when step S101 is executed. The device for generating the test template may be an execution subject of the steps in fig. 1, or may be other devices, such as a service server or a user terminal.
For step S101, a test template may be generated according to a service log generated by real service interaction, as follows: acquiring a service log generated according to real service interaction, wherein the service log comprises one or more log records; and generating a test template by analyzing each log record and converting parameters, wherein the test template reflects service information and interaction process information corresponding to the real service interaction.
In this embodiment of the present application, each log record may correspond to a service request sent by a certain user, and the log record may record related information of the service request, where the related information may include: service type, service parameter and service interaction time; the service interaction time may refer to a time for sending a service request, or may refer to a time for writing the log record after the service server receives the service request.
Some of the traffic parameters may be transformed during the generation of the test template. These parameters may be parameters having an association relationship with the real user, such as user identification, or parameters for identifying the real service request, such as service request number, current time, service interaction time, and so on. The reasons why the conversion is required are: if these parameters are used directly in the test template without conversion, the data of the real user may be disturbed.
According to the above analysis, generating a test template by analyzing each log record and performing parameter conversion may specifically include: analyzing each log record to obtain each log record comprising a service type, a service parameter and service interaction time; converting the appointed parameters in the obtained business parameters into dynamic business parameters, and taking the obtained business types, the parameters which are not converted in the business parameters and the converted dynamic business parameters as business information corresponding to the real business interaction; converting the obtained service interaction time into relative time, and taking the relative time and the corresponding relation between the relative time and the service information as interaction process information corresponding to the real service interaction; and generating a test template according to the service information and the interaction process information corresponding to the real service interaction.
Each dynamic service parameter can be assigned in real time (that is, a real user is replaced by a virtual user) when a service test task is generated, and in such a way, the virtual user can be used for simulating and replacing the real user according to the interaction between the real user and the service server to interact with the service server. The above parameter conversion will be described below by way of example.
For example, assuming that the service parameter includes a user identifier named "user a", the user identifier may be converted into a dynamic service parameter "$ user _ no", and it should be noted that "$ user _ no" is only one example of the name of the dynamic service parameter. In practical application, the name of the dynamic service parameter is not the same as the user identifier of any real user.
Similarly, the service request number contained in the service parameter may be converted into a dynamic service parameter "$ unique _ no", the current time may be converted into a dynamic service parameter "$ current _ time", and so on. Of course, "$ unique _ no", "$ current _ time" are also name examples of dynamic traffic parameters.
Besides the service parameters, the service interaction time can be converted into relative time, so that the service request generated by simulating each relative time can be executed according to the time sequence of each relative time. By way of example and illustration.
For example, assume that the first log record contains a business interaction time of 10:00:00.000 (the year, month, and day portion of the time is omitted here and not shown). It can be converted into a relative time of 0 millisecond (ms), and further, the service interaction time included in other log records can be converted into a relative time (i.e. a time length different from the relative time of the first log record) by taking the relative time of the first log record as a reference. Assuming that another log record contains a transaction interaction time of 10:00:02.000, this can translate to a relative time of 2000 ms.
According to the above method, according to each log record, a set of specific data corresponding to the log record may be generated, and the set of specific data may include: the log records the service type and service parameters, the dynamic service parameters obtained by conversion and the relative time obtained by conversion. The test template can be generated by correspondingly organizing each group of specific data generated according to each log record according to the sequence of each log record.
In this embodiment of the present application, for step S102, the predetermined test data may include template assignment data and test requirement data; generating a service test task according to the test template and the predetermined test parameters, which may specifically include: assigning values to the dynamic service parameters in the test template according to the template assignment parameters; and generating a service test task according to the test demand data and the assigned test template. The template assigned data and the test requirement data will be described below.
After the test template is obtained, a real service interaction process can be simulated by carrying out data assignment filling on the test template, and the part of data used for filling the test template can be template assignment data.
For example, for a dynamic service parameter "$ user _ no", a virtual user identifier may be generated as template assignment data, and the "$ user _ no" may be assigned. Specifically, "$ user _ no" in the test template may be replaced with a virtual user id. Of course, there may be a plurality of virtual user identifiers, and for each user identifier of a real user, a virtual user identifier may be generated for replacement.
In the embodiments of the present application, the mode of generating template assigned value data is not limited. In practical applications, the template assignment data may be generated by using a random number generator or a random character string generator, or may be generated according to other rules.
The test requirement data may then be used to specify the relevant requirements at the time of the subsequent test. In general, the relevant requirements may be: the time for starting the service test, the test type (which may be a pressure test, a load test, etc.) to which the service test to be performed belongs, the adjustment of the test template or the filled test template according to the test type to which the service test belongs (if the test type belongs to the pressure test or the load test, during the service test, the traffic corresponding to the simulated service interaction process may be amplified by several times, for example, the traffic may be copied to generate a plurality of copies, so that the service server may be requested to process in parallel), the requirements for the test environment (for example, the test script language type, the operating system of the test equipment, etc.), and so on.
In this embodiment of the application, for step S102, executing the service test task to obtain a service test result may specifically include: aiming at the relative time contained in the service test task, generating a corresponding service request according to the service type, the service parameter and the assigned dynamic service parameter corresponding to the relative time; sending the generated service request to a service server according to the test requirement data and the relative time contained in the service test task, and obtaining a service processing result returned by the service server in response to the service request; and determining a service test result according to the service processing result.
For service logs generated from real service interactions, each log record may correspond to a service request sent by a real user. Correspondingly, the service test task generated based on the service log also includes data of each service request for generating service test by simulating each service request sent by a real user, that is, the assigned specific data of each group. Further, the service requests for the service test corresponding to the relative times can be sent to the service server according to the sequence of the relative times included in the service test task. Therefore, the process of executing the service test task is the reduction and simulation of the real service interaction process, and therefore, the obtained service test result can be considered to reflect the function and performance of the service server in the real service interaction.
In the embodiment of the application, the real service interaction may involve a plurality of real users, and the service testing task may also involve a plurality of virtual users. The interaction between each real user and the service server is independent, so that each real user can send a service request to the service server in parallel.
Therefore, when the business test task is executed, the business test task can be split or copied and distributed to one or more task executors to be executed together. Each task executor can execute the service test task in a single thread or in multiple threads, and each thread can be respectively responsible for generating and sending a service request for one virtual user.
According to the above description, for step S103, executing the service test task may specifically include: and distributing the service test task to one or more task executors according to a preset distribution mode, so that the task executors execute the service test task according to the relative time contained in the service test task. The sub-formula is not limited in the embodiment of the application, and the sub-formula can be distributed according to the corresponding relationship between the virtual users and the counties and cities, and can also be distributed evenly, and the like.
In practical applications, in order to improve the testing efficiency, the part of the task of distributing the service test task may be performed by a special scheduling module or scheduling device.
In the embodiment of the application, the task executors can keep time synchronization with each other when executing the tasks, so that the service requests can be sent to the service server according to the sending sequence under the real service interaction.
Specifically, the task executor may calculate a difference between the current time and the time for starting the service test, which is specified by the test requirement data, for the task assigned to the task executor, and may start to execute the task when the difference is not less than the relative time corresponding to the task. The task assigned to the task executor may be a part of the service test task in step S102, or may be a copy of the service test task, and the latter case is generally applicable to a stress test or a load test, and in the latter case, when performing a service test, the stress applied to the service server may be greater than the stress applied to the service server in the real service interaction.
Further, in practical applications, there may be cases where: the generation of one service request needs to be dependent on the response result of another service request. For this case, the solution of the present application is equally applicable.
Specifically, the template assigned data may be generated according to a response result of the another service request, a new service test task may be generated and executed, and a service request depending on a response result of the another service request may be generated and sent to the service server in a process of executing the new service test task. It can be seen that in this case, in the process of executing step S103, step S102 may also be executed again.
Based on the above description of the steps in fig. 1, the embodiment of the present application further provides a structure diagram of a system that can be used to implement the solution of the present application in practical applications, as shown in fig. 2.
The system in fig. 2 mainly comprises: the device comprises a service generating device, a test template generating device and a service test task executing device. The arrow direction indicates the flow direction of the scheme of the present application, and the cylinder indicates the data generated in the flow. The implementation flow of the scheme of the present application by using the system is shown in fig. 3, and may specifically include the following steps:
s301: the service log generating device generates a service log according to real service interaction between the service server (or a corresponding application client, omitted below) and a real user.
It should be noted that, in practical applications, the service log may also be directly generated by the service server, and in this case, the service log generating device may be only used to obtain the service log.
S302: the test template generating device acquires the service log from the service log generating device (specifically executed by the service log acquiring module), and generates a test template by analyzing the service log (specifically executed by the service log analyzing module) and performing conversion (specifically executed by the service log converting module);
s303: the test execution device acquires the test template from the test template generation device, acquires template assigned data and test requirement data, generates a service test task according to the template assigned data and the test requirement data, and dispatches and distributes the generated service test task to the task executor to execute through the scheduling module;
s304: the task executors (N is total, N is not less than 1) execute the tasks, generate and send corresponding service requests to the service server, and obtain service processing results returned by the service server;
s305: and the test execution device determines a test result according to the service processing result.
It should be noted that fig. 2 is only an example of a structure diagram of a system that can be used to implement the solution of the present application, and the structure of the system that can be used to implement the solution of the present application is not limited in the embodiment of the present application.
Based on the same idea, the service testing method provided in the embodiment of the present application further provides a corresponding service testing apparatus, as shown in fig. 4.
Fig. 4 is a schematic structural diagram of a service testing apparatus provided in an embodiment of the present application, which specifically includes:
an obtaining module 401, configured to obtain a test template generated according to a service log generated by real service interaction, where the test template reflects service information and interaction process information corresponding to the real service interaction;
a generating module 402, configured to generate a service test task according to the test template and predetermined test data;
the testing module 403 is configured to execute the service testing task and obtain a service testing result.
By the device, the service test task is generated based on the real service interaction, so that the obtained test result can reflect the service function or performance of the service server during the real service interaction by executing the service test task, and the practicability is better.
The device further comprises:
a template module 404, configured to generate a test template according to a service log generated by real service interaction;
the template module 404 is specifically configured to: acquiring a service log generated according to real service interaction, wherein the service log comprises one or more log records; and generating a test template by analyzing each log record and converting parameters, wherein the test template reflects service information and interaction process information corresponding to the real service interaction.
The template module 404 is specifically configured to: analyzing each log record to obtain each log record comprising a service type, a service parameter and service interaction time; converting the appointed parameters in the obtained business parameters into dynamic business parameters, and taking the obtained business types, the parameters which are not converted in the business parameters and the converted dynamic business parameters as business information corresponding to the real business interaction; converting the obtained service interaction time into relative time, and taking the relative time and the corresponding relation between the relative time and the service information as interaction process information corresponding to the real service interaction; and generating a test template according to the service information and the interaction process information corresponding to the real service interaction.
The preset test data comprises template assigned data and test requirement data;
the generating module 402 is specifically configured to: assigning values to the dynamic service parameters in the test template according to the template assignment parameters; and generating a service test task according to the test demand data and the assigned test template.
The test module 403 is specifically configured to: aiming at the relative time contained in the service test task, generating a corresponding service request according to the service type, the service parameter and the assigned dynamic service parameter corresponding to the relative time; sending the generated service request to a service server according to the test requirement data and the relative time contained in the service test task, and obtaining a service processing result returned by the service server in response to the service request; and determining a service test result according to the service processing result.
The test module 403 is specifically configured to: and distributing the service test task to one or more task executors according to a preset distribution mode, so that the task executors execute the service test task according to the relative time contained in the service test task.
The specific device shown in fig. 4 may be located on a terminal or a server.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.