A port management method, apparatus, storage medium, and device
By allocating specific port ranges for browser testing tools in a central database and using process signature codes to identify tool types, dynamically allocating ports and managing their lifecycles, the inefficiency and conflict issues in port allocation for browser testing tools are resolved, achieving efficient and stable port resource management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHONGQING JINKANG NEW ENERGY VEHICLE CO LTD
- Filing Date
- 2026-03-02
- Publication Date
- 2026-05-26
AI Technical Summary
Existing browser testing tools rely on manual intervention for port allocation, which leads to inefficiency and a high risk of port conflicts.
By allocating specific port ranges for each browser testing tool in the resource pool of the central database and recording port status, the tool type of the testing process is automatically identified using browser process signature codes, thereby dynamically allocating available ports. The port lifecycle is managed by combining heartbeat detection and zombie process detection algorithms.
It achieves efficient and automated port resource management, improves allocation efficiency, prevents port conflicts, and ensures the stability and reliability of the test environment.
Smart Images

Figure CN122086783A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software testing technology, and more specifically, to a port management method, apparatus, storage medium, and device. Background Technology
[0002] Browser automation testing is an indispensable part of modern web development, especially suitable for projects requiring high-frequency regression testing or cross-platform verification. Existing browser testing tools, such as Selenium (a browser automation testing framework, an open-source tool for web application testing) and Playwright (an end-to-end testing tool open-sourced by Microsoft for web application testing), occupy specific ports during runtime to simulate browser operations. However, in related technologies, port allocation for browser testing tools generally relies on manual intervention, which can easily lead to inefficient port allocation and conflicts between different browser testing tools. Summary of the Invention
[0003] The purpose of this application is to provide a port management method, apparatus, storage medium, and device, which aims to solve the problems in the related art regarding port allocation methods for browser testing tools, which easily lead to low port allocation efficiency and conflicts in port usage between different browser testing tools.
[0004] In a first aspect, this application provides a port management method, comprising: when a test request from a test process is received, identifying the target browser test tool corresponding to the test process; obtaining an available port corresponding to the target browser test tool from a resource pool in a central database; the resource pool includes multiple port ranges and records the port status of each port; the multiple port ranges are set for multiple browser test tools, and different browser test tools correspond to different port ranges; returning the port number of the available port to the test process, and updating the port status of the available port.
[0005] In the above implementation, a port range is set for each browser testing tool, with different browser testing tools corresponding to different port ranges. The port status of all ports is recorded in a resource pool in a central database. When a test request is received from a testing process, the target browser testing tool corresponding to that process is identified. Based on the identified target browser testing tool, an available port is obtained from the resource pool, and the port number of that available port is returned to the testing process so that it can use that port to start a browser instance. Simultaneously, the port status of that available port is updated. This achieves efficient and automated port resource management, improves port allocation efficiency, and effectively prevents port conflicts.
[0006] Furthermore, in some examples, identifying the target browser testing tool corresponding to the test process includes: extracting the browser process signature from the test request; and identifying the target browser testing tool corresponding to the test process based on the browser process signature.
[0007] In the above implementation process, a specific method for identifying target browser testing tools is provided, namely, automatically identifying browser testing tools by analyzing browser process signature codes.
[0008] Furthermore, in some examples, obtaining an available port corresponding to the target browser testing tool from the resource pool of the central database includes: determining the port range corresponding to the target browser testing tool according to a pre-built mapping table; the mapping table records the port range corresponding to each browser testing tool; querying the port status of each port in the port range from the resource pool of the central database, and determining an available port from the port range based on the query result.
[0009] In the above implementation process, a mapping table is pre-built to record the correspondence between browser testing tools and port ranges. When a test request is received, the port is allocated according to the mapping table. In this way, by building a standardized mapping system, port conflicts are effectively prevented and it is ensured that the testing processes of different browsers do not interfere with each other.
[0010] Furthermore, in some examples, the port status includes an idle state and an occupied state; determining an available port from the port range based on the query result includes: obtaining the first port in the port range whose port status is idle, and determining the port as an available port; updating the port status of the available port includes: updating the port status of the available port to an occupied state.
[0011] In the above implementation process, in response to test requests, the system allocates the first available port in the port range corresponding to the target browser's testing tool and updates the port status of that port to "occupied." This improves the reliability of port management.
[0012] Furthermore, in some examples, the method also includes: recording the process ID of the test process when updating the port status of the available port; periodically checking whether the available port has failed based on the process ID; and reclaiming the available port to the resource pool when the available port is detected to have failed.
[0013] In the above implementation process, when allocating ports, the process ID of the requesting port is recorded. Then, based on the recorded process ID, the port is periodically checked for invalidity. When the port is determined to be invalid, it is reclaimed. This reduces port resource waste and improves the stability and reliability of the test environment.
[0014] Furthermore, in some examples, the step of periodically detecting whether the available port is invalid based on the process ID includes: when the scheduled task runs, querying the operating system to see if the test process exists based on the process ID; the scheduled task runs automatically once every target time; if the test process has terminated and the difference between the current time and the last used timestamp of the available port is greater than a preset duration, determining that the available port is invalid.
[0015] In the above implementation process, a dual protection mechanism combining heartbeat detection and zombie process detection algorithm is adopted to manage the life cycle of the port, effectively preventing active resources from being wrongly reclaimed and zombie processes from occupying resources.
[0016] Furthermore, in some examples, reclaiming the available port to the resource pool includes: updating the port status of the available port to an idle state and deleting the process information of the available port.
[0017] In the above implementation process, when any port is determined to be invalid, the port status of that port is reset to idle state and the related process information is deleted. In this way, the reclaimed port resources can be immediately allocated to new test tasks, forming an efficient loop.
[0018] Secondly, this application provides a port management device, comprising: an identification module, configured to identify the target browser testing tool corresponding to the testing process when a test request is received from the testing process; an acquisition module, configured to acquire an available port corresponding to the target browser testing tool from a resource pool in a central database; the resource pool includes multiple port ranges and records the port status of each port; the multiple port ranges are set for multiple browser testing tools, and different browser testing tools correspond to different port ranges; and a return module, configured to return the port number of the available port to the testing process and update the port status of the available port.
[0019] Thirdly, this application provides an electronic device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the method described in any of the first aspects.
[0020] Fourthly, this application provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method described in any of the first aspects.
[0021] Fifthly, this application provides a computer program product that, when run on a computer, causes the computer to perform the method described in any of the first aspects.
[0022] Other features and advantages disclosed in this application will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the above-described technology disclosed in this application.
[0023] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0024] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 A flowchart illustrating a port management method provided in an embodiment of this application; Figure 2 A schematic diagram illustrating the architecture of a browser port dynamic allocation and lifecycle management system for multi-engine automated testing, provided in an embodiment of this application; Figure 3 A schematic diagram illustrating the port allocation logic executed by a browser port dynamic allocation and lifecycle management system for multi-engine automated testing, provided in an embodiment of this application; Figure 4 A block diagram of a port management device provided in an embodiment of this application; Figure 5 This is a structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0026] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0027] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0028] Browser automation testing is a testing method that uses programming or tools to simulate user actions in a browser to verify the functionality, performance, or compatibility of web pages. Browser testing tools, such as Selenium (a browser automation testing framework, an open-source tool for web application testing) and Playwright (an end-to-end testing tool open-sourced by Microsoft for web application testing), are the execution engines for browser automation testing. They simulate user interactions with the browser through programming interfaces, thereby transforming abstract automation testing requirements into executable code. Typically, browser testing tools occupy a specific port during runtime for browser simulation operations; this specific port serves as the communication channel between the browser testing tool and the browser instance. However, in related technologies, port allocation for browser testing tools generally relies on manual intervention, which can easily lead to inefficient port allocation and conflicts between different browser testing tools using different ports.
[0029] To address the aforementioned issues, this application provides a port management scheme. Each browser testing tool is assigned a port range, with different browser testing tools corresponding to different port ranges. The port status of all ports is recorded in a resource pool of a central database. When a test request is received from a testing process, the system identifies the corresponding browser testing tool, retrieves an available port from the resource pool, returns the port number of that available port to the testing process, and updates the port status of that available port. This dynamic port allocation improves port allocation efficiency and effectively avoids port conflicts.
[0030] The embodiments of this application will be described below: like Figure 1 As shown, Figure 1 This is a flowchart illustrating a port management method provided in an embodiment of this application. The method can be applied to a server. This server can be responsible for running backend services of web applications, providing APIs (Application Programming Interfaces), and storing test data in browser automated testing.
[0031] The method includes: Step 101: When a test request is received from a test process, identify the target browser test tool corresponding to the test process; The test process mentioned in this step can refer to the process launched when automated test code written using browser testing tools such as Selenium or Playwright is executed. When a new test process starts and needs a port, it sends a test request to the server. At this time, the server identifies the browser testing tool corresponding to the test process and allocates an appropriate port for it.
[0032] In some embodiments, identifying the target browser testing tool corresponding to the test process mentioned in this step may include: extracting the browser process signature from the test request; and identifying the target browser testing tool corresponding to the test process based on the browser process signature. That is, the test request sent by the test process carries the browser process signature, which can be used to represent the name of the browser testing tool corresponding to the test process. Therefore, when the server receives a test request, it can automatically identify the browser testing tool by analyzing the browser process signature.
[0033] Step 102: Obtain an available port corresponding to the target browser testing tool from the resource pool of the central database; the resource pool includes multiple port ranges and records the port status of each port; the multiple port ranges are set for multiple browser testing tools, and different browser testing tools correspond to different port ranges; In this embodiment, a continuous range of port numbers is pre-assigned to each browser testing tool, such as 8000-8999 for Selenium and 9000-9999 for Playwright. These port ranges do not overlap. Furthermore, a central database records the status of all ports, forming a resource pool. After identifying the browser testing tool corresponding to the testing process, the server scans the resource pool in the central database and allocates an available port corresponding to that browser testing tool. This effectively prevents port conflicts. The central database mentioned in this step can be a Redis (Remote Dictionary Server) database.
[0034] In some embodiments, obtaining an available port corresponding to the target browser testing tool from the resource pool of the central database mentioned in this step may include: determining the port range corresponding to the target browser testing tool according to a pre-built mapping table; the mapping table recording the port range corresponding to each browser testing tool; querying the port status of each port in the port range from the resource pool of the central database, and determining an available port from the port range based on the query result. That is, the server can record the correspondence between browser testing tools and port ranges to form a mapping table. Using the previous example, when the identified browser testing tool is Selenium, the server queries the resource pool of Redis for the port status of all ports from port number 8000 to 8999, and determines an available port from these ports based on the queried port status. In this way, by constructing a standardized mapping system, port conflicts are effectively prevented, ensuring that different browser testing processes do not interfere with each other.
[0035] Step 103: Return the port number of the available port to the test process and update the port status of the available port.
[0036] In this embodiment, after determining the available port to be allocated to the test process, the server returns the port number of the available port to the test process so that the test process can start a browser instance based on the port number. At the same time, the server immediately updates the port status of the available port to prevent the available port from being incorrectly allocated when other test processes request the port in the future, thereby effectively preventing port conflicts.
[0037] In some embodiments, the port status mentioned in this step may include an idle status and an occupied status. Correspondingly, determining an available port from the port range based on the query result mentioned earlier may include: obtaining the first port in the port range with an idle status and determining that port as an available port. Updating the port status of the available port mentioned in this step may include: updating the port status of the available port to an occupied status. That is, port status includes both "idle" and "occupied." During resource pool initialization, the port status of all ports can be initialized to "idle." The server responds to the test request, allocates the first port in the port range corresponding to the target browser testing tool with an "idle" status, and updates the port status of that port to "occupied." This improves the reliability of port management. Of course, in other embodiments, port status can be set differently according to the needs of specific scenarios. For example, in some scenarios, in addition to "idle" and "occupied," port status may also include other subdivided states such as "unavailable," indicating that the current port is faulty.
[0038] In traditional testing environments, port reclamation is often delayed, leading to wasted port resources. Therefore, some embodiments may include: recording the process ID of the testing process when updating the port status of the available ports; periodically checking whether the available ports are invalid based on the process ID; and reclaiming the available ports to the resource pool when invalidation is detected. In other words, when allocating ports, the process ID (PID) of the requesting port is recorded. Then, based on the recorded PID, the port is periodically checked for invalidation, and when invalidation is determined, the port is reclaimed. This reduces port resource waste and improves the stability and reliability of the testing environment.
[0039] Furthermore, in some embodiments, the aforementioned method of periodically detecting whether the available port is invalid based on the process ID may include: when a scheduled task runs, querying the operating system to see if the test process exists based on the process ID; the scheduled task runs automatically every target time; if the test process has terminated and the difference between the current time and the last used timestamp of the available port is greater than a preset duration, the available port is determined to be invalid. In other words, a dual-protection mechanism combining a heartbeat detection mechanism and a zombie process detection algorithm can be used for port lifecycle management. In implementation, an independent scheduled task is started, which runs automatically every target time, such as 30 seconds. When the scheduled task runs, the server queries the operating system to see if the process exists based on the recorded process ID, and simultaneously checks whether the difference between the current time and the last used timestamp of the port is greater than a preset duration. If the process is still running or the time difference is not greater than the preset duration, the port is determined to be an active resource; if the process has terminated and the time difference is greater than the preset duration, the port is determined to be a zombie resource, and port reclamation is performed. This achieves efficient resource management and effectively prevents active resources from being incorrectly reclaimed and zombie processes from occupying resources.
[0040] Furthermore, in some embodiments, the aforementioned reclaiming of the available ports to the resource pool may include: updating the port status of the available ports to an idle state and deleting the process information of the available ports. That is, when any port is determined to be invalid, its port status is reset to "idle," and the associated process information is deleted. This allows the reclaimed port resources to be immediately allocated to new test tasks, forming an efficient cycle.
[0041] In this embodiment, a port range is set for each browser testing tool, with different browser testing tools corresponding to different port ranges. The port status of all ports is recorded in a resource pool of a central database. When a test request is received from a testing process, the target browser testing tool corresponding to that process is identified. Based on the identified target browser testing tool, an available port is obtained from the resource pool, and the port number of that available port is returned to the testing process so that it can use that port to start a browser instance. Simultaneously, the port status of the available port is updated. This achieves efficient and automated port resource management, improves port allocation efficiency, and effectively prevents port conflicts.
[0042] To provide a more detailed explanation of the solution in this application, a specific embodiment is described below: This embodiment provides a browser port dynamic allocation and lifecycle management system for multi-engine automated testing. The system architecture is as follows: Figure 2 As shown, its core system module 20 includes a port allocation module 21, a browser identification module 22, a mapping management module 23, and a lifecycle management module 24. This system interacts with external components, including a testing process 25 and a Redis database 26. The Redis database 26 stores the port ranges set by the system for different browser testing tools, such as 8000-8999 for Selenium and 9000-9999 for Playwright. The Redis database 26 records the port status in real time.
[0043] The port allocation logic executed by this system is as follows: Figure 3 As shown, it includes: S301, Receive the test request sent by test process 25; S302. Analyze the browser process signature code; specifically, when the test process 25 starts and needs a port, it sends a test request to the system, and the system analyzes the browser process signature code through the browser identification module 22. S303. Determine whether the browser testing tool is identified. If yes, execute S305; otherwise, execute S304. S304, determined to be an unknown browser type, returns an error, and then ends the process; S305. Query the mapping table to obtain the corresponding port range; Specifically, after the browser identification module 22 analyzes the browser process feature code, it submits a mapping request to the mapping management module 23. The mapping management module 23 identifies the corresponding browser testing tool based on the browser process feature code. When the browser testing tool is successfully identified, the corresponding port range is obtained according to the mapping table that records the correspondence between the browser testing tool and the port range. S306. Scan the port range to find free ports. Specifically, after the mapping management module 23 obtains the port range, it requests port resources. At this time, the port allocation module 21 scans the resource pool in the Redis database 26 to obtain the port status of each port in the port range in order to find out if there are any free ports. S307. Has a free port been found? If yes, proceed to S309; otherwise, proceed to S308. S308, returns an error indicating no available port, then ends the process; S309. Lock and allocate the port, update the port status, and record the process ID and timestamp; S310. The port number of the port is returned to the test process 25, and then the process ends. Specifically, the port allocation module 21 returns the port number of the first free port found to the test process 25 so that the test process 25 can start the browser instance according to the port number.
[0044] The system also implements lifecycle management of port resources based on the lifecycle management module 24. The implementation logic of the lifecycle management module 24 includes: starting an independent scheduled task that runs automatically every 30 seconds. When the scheduled task runs, it scans all port records in the Redis database 26 whose port status is "occupied". For each port record, it performs two checks: one is a liveness check, which queries the operating system to see if the process still exists based on the process ID in the record; the other is a timeout check, which checks if the difference between the current time and the port's last used timestamp exceeds 30 seconds. If so, the timestamp is determined to have expired. If the process has terminated and the timestamp has expired, the port is determined to be a zombie resource. At this time, the port status is reset to "idle" and the relevant process information is deleted to reclaim the port. If the process is still running or the timestamp has not expired, the port is determined to be an active resource, and the process is skipped. The scheduled task then ends and waits for the next trigger, forming a closed-loop management.
[0045] This embodiment has at least the following advantages: First, it effectively supports the collaborative work of heterogeneous browser engines, reduces the test case conflict rate, and ensures that the testing processes of different browsers do not interfere with each other; Second, it adopts a dual protection mechanism combining a heartbeat detection mechanism and a zombie process detection algorithm to achieve two-level resource management of active release and passive recycling, effectively shortening the zombie process recycling response time, reducing abnormal test interruptions, and solving the problem of port resource waste, making the test environment more stable and reliable; Third, the design that supports dynamic registration of new browser types gives the system good scalability and can flexibly adapt to the testing needs of new simulated browsers that may emerge in the future.
[0046] Corresponding to the embodiments of the aforementioned methods, this application also provides embodiments of a port management device and a terminal thereof: like Figure 4 As shown, Figure 4 This is a block diagram of a port management device provided in an embodiment of this application. The device includes: The identification module 41 is used to identify the target browser testing tool corresponding to the testing process when a test request is received from the testing process. The acquisition module 42 is used to acquire an available port corresponding to the target browser testing tool from the resource pool of the central database; the resource pool includes multiple port ranges and records the port status of each port; the multiple port ranges are set for multiple browser testing tools, and different browser testing tools correspond to different port ranges; The return module 43 is used to return the port number of the available port to the test process and update the port status of the available port.
[0047] The specific implementation process of the functions and roles of each module in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0048] This application also provides an electronic device, please refer to [link to application]. Figure 5 , Figure 5 This is a structural block diagram of an electronic device provided in an embodiment of this application. The electronic device may include a processor 510, a communication interface 520, a memory 530, and at least one communication bus 540. The communication bus 540 is used to enable direct communication between these components. In this embodiment, the communication interface 520 of the electronic device is used for signaling or data communication with other node devices. The processor 510 may be an integrated circuit chip with signal processing capabilities.
[0049] The processor 510 described above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor, or the processor 510 can be any conventional processor.
[0050] The memory 530 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc. The memory 530 stores computer-readable instructions. When these computer-readable instructions are executed by the processor 510, the electronic device can perform the aforementioned operations. Figure 1 The various steps involved in the method implementation examples.
[0051] Alternatively, the electronic device may also include a storage controller and an input / output unit.
[0052] The memory 530, storage controller, processor 510, peripheral interface, and input / output unit are electrically connected directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses 540. The processor 510 is used to execute executable modules stored in the memory 530, such as software function modules or computer programs included in electronic devices.
[0053] The input / output unit is used to provide users with the ability to create tasks and to set optional start periods or preset execution times for those tasks, thereby enabling user-server interaction. The input / output unit may be, but is not limited to, a mouse and keyboard.
[0054] Understandable. Figure 5 The structure shown is for illustrative purposes only; the electronic device may also include components that are more advanced than those shown. Figure 5 The more or fewer components shown, or having the same Figure 5 The different configurations shown. Figure 5 The components shown can be implemented using hardware, software, or a combination thereof.
[0055] This application also provides a storage medium storing instructions. When the instructions are run on a computer, the computer program is executed by a processor to implement the method described in the method embodiment. To avoid repetition, the method will not be described again here.
[0056] This application also provides a computer program product that, when run on a computer, causes the computer to perform the method described in the method embodiment.
[0057] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0058] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0059] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0060] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0061] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0062] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A port management method, characterized in that, include: When a test request is received from a test process, the target browser test tool corresponding to the test process is identified; Obtain an available port corresponding to the target browser testing tool from the resource pool of the central database; the resource pool includes multiple port ranges and records the port status of each port; the multiple port ranges are set for multiple browser testing tools, and different browser testing tools correspond to different port ranges; The port number of the available port is returned to the test process, and the port status of the available port is updated.
2. The method according to claim 1, characterized in that, The target browser testing tool for identifying the testing process includes: Extract the browser process signature from the test request; The target browser testing tool corresponding to the test process is identified based on the browser process signature.
3. The method according to claim 1, characterized in that, Obtaining an available port corresponding to the target browser testing tool from the resource pool of the central database includes: Based on a pre-built mapping table, the port range corresponding to the target browser testing tool is determined; the mapping table records the port range corresponding to each browser testing tool. The system queries the resource pool of the central database to determine the port status of each port in the specified port range, and then determines an available port from the specified port range based on the query results.
4. The method according to claim 3, characterized in that, The port status includes idle status and occupied status; The step of determining an available port from the port range based on the query results includes: Obtain the first port in the port range that is in an idle state, and determine that port as an available port; Updating the port status of the available ports includes: Update the port status of the available port to occupied.
5. The method according to claim 1, characterized in that, Also includes: When updating the port status of the available ports, record the process ID of the test process; Based on the process ID, periodically check whether the available port has become invalid; When the available port is detected to be invalid, the available port is reclaimed to the resource pool.
6. The method according to claim 5, characterized in that, The step of periodically checking whether the available port is invalid based on the process ID includes: When the scheduled task runs, it queries the operating system to see if the test process exists based on the process ID; the scheduled task runs automatically once every target time. If the test process has terminated and the difference between the current time and the last used timestamp of the available port is greater than a preset duration, the available port is determined to be invalid.
7. The method according to claim 5, characterized in that, The step of reclaiming the available ports to the resource pool includes: Update the port status of the available port to idle and delete the process information of the available port.
8. A port management device, characterized in that, include: The identification module is used to identify the target browser testing tool corresponding to the testing process when a test request is received from the testing process. The acquisition module is used to acquire an available port corresponding to the target browser testing tool from the resource pool of the central database; the resource pool includes multiple port ranges and records the port status of each port; the multiple port ranges are set for multiple browser testing tools, and different browser testing tools correspond to different port ranges; The return module is used to return the port number of the available port to the test process and update the port status of the available port.
9. A computer-readable storage medium, characterized in that, It stores a computer program thereon, which, when executed by a processor, implements the method as described in any one of claims 1 to 7.
10. An electronic device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method as described in any one of claims 1 to 7.