ganeshmurthy commented on code in PR #1567:
URL: https://github.com/apache/qpid-dispatch/pull/1567#discussion_r885650797
##########
tests/system_test.py:
##########
@@ -765,6 +772,46 @@ def setup(self):
os.makedirs(self.directory)
os.chdir(self.directory)
+ def _next_port(self) -> int:
+ """Reads and increments value stored in self.port_file, under an
exclusive file lock.
+
+ When a lock cannot be acquired immediately, fcntl.lockf blocks.
+
+ Failure possibilities:
+ File locks may not work correctly on network filesystems. We still
should be no worse off than we were.
+
+ This method always unlocks the lock file, so it should not ever
deadlock other tests running in parallel.
+ Even if that happened, the lock is unlocked by the OS when the
file is closed, which happens automatically
+ when the process that opened and locked it ends.
+
+ Invalid content in the self.port_file will break this method.
Manual intervention is then required.
+ """
+ try:
+ fcntl.flock(self.port_file, fcntl.LOCK_EX)
+
+ # read old value
Review Comment:
Minor suggestion -
Does `next_port = port + 1` need to be done if the file is empty.
```
# read old value
self.port_file.seek(0, os.SEEK_END)
if self.port_file.tell() != 0:
# file is not empty, read the old port and increment it to
get next possible available port.
self.port_file.seek(0)
port = int(self.port_file.read())
next_port = port + 1
else:
# file is empty, so just start with a randint between 20000
and 30000
port = random.randint(self.port_range[0], self.port_range[1])
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]