adoroszlai commented on code in PR #9889:
URL: https://github.com/apache/ozone/pull/9889#discussion_r2901655498


##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/upgrade/TestDatanodeUpgradeToContainerIdsTable.java:
##########
@@ -66,12 +68,23 @@ private void initTests() throws Exception {
   }
 
   private void setup() throws Exception {
-    address = SCMTestUtils.getReuseableAddress();
-    conf.setSocketAddr(ScmConfigKeys.OZONE_SCM_NAMES, address);
     conf.set(HddsConfigKeys.OZONE_METADATA_DIRS,
         tempFolder.toString());
   }
 
+  /**
+   * Starts the mock SCM RPC server on an OS-assigned port (port 0) to avoid
+   * the TOCTOU race that causes intermittent BindException when a pre-reserved
+   * port is grabbed by another process between reservation and bind.
+   */
+  private void startScm() throws IOException {
+    scmRpcServer = SCMTestUtils.startScmRpcServer(conf,
+        new ScmTestMock(CLUSTER_ID),
+        new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 10);
+    address = scmRpcServer.getListenerAddress();
+    conf.setSocketAddr(ScmConfigKeys.OZONE_SCM_NAMES, address);
+  }

Review Comment:
   Please reduce duplication by extracting `startScm(OzoneConfiguration)` into 
`SCMTestUtils`.  It should update `conf` and return `scmRpcServer`.  Test can 
set `address`.  `CLUSTER_ID` can also be moved to `SCMTestUtils`, value is the 
same in all tests.



-- 
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]

Reply via email to