jiridanek commented on code in PR #1567:
URL: https://github.com/apache/qpid-dispatch/pull/1567#discussion_r885686638
##########
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:
In the beginning (no file), I return the result of random.randint and then
store port + 1 to file. Next time, I read number from file (to return) and
store number + 1 back to file and so on.
If I did not do port + 1 the first time, then I'd return the same port twice.
--
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]