JosiahWI commented on code in PR #12291:
URL: https://github.com/apache/trafficserver/pull/12291#discussion_r2173269715


##########
tests/gold_tests/autest-site/ports.py:
##########
@@ -30,6 +31,72 @@
 g_ports = None  # ports we can use
 
 
+class AsyncPortQueue(OrderedSetQueue):
+
+    def __init__(self):
+        super().__init__()
+        self._listening_ports = _get_listening_ports()
+
+    async def select_available(self, amount, dmin, dmax):
+        rmin = dmin - 2000
+        rmax = 65536 - dmax
+
+        port_tasks = []
+        await asyncio.gather(*port_tasks)
+        if rmax > amount:
+            # Fill in ports, starting above the upper OS-usable port range.
+            port = dmax + 1
+            while port < 65536 and self.qsize() < amount:
+                port_tasks.append(self._check_port(port))
+                port += 1
+        if rmin > amount and self.qsize() < amount:
+            port = 2001
+            # Fill in more ports, starting at 2001, well above well known 
ports,
+            # and going up until the minimum port range used by the OS.
+            while port < dmin and self.qsize() < amount:
+                port_tasks.append(self._check_port(port))
+                port += 1
+
+        await asyncio.gather(*port_tasks)

Review Comment:
   I have timed this patch. (The test failed because the plugin it needed 
wasn't compiled.)
   
   ```
   Total of 1 test
     Unknown: 0
     Exception: 1
     Failed: 0
     Warning: 0
     Skipped: 0
     Passed: 0
   
   real    2m20.733s
   user    0m3.494s
   sys     0m1.416s
   ```
   
   It's fast enough that working on an AuTest is possible if you have a lot of 
patience.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to