You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/08/25 01:19:34 UTC

[GitHub] [rocketmq] mxsm commented on a diff in pull request #4882: [ISSUE #4873]Optimize controller module test cases execution time

mxsm commented on code in PR #4882:
URL: https://github.com/apache/rocketmq/pull/4882#discussion_r954418044


##########
controller/src/test/java/org/apache/rocketmq/controller/impl/controller/ControllerManagerTest.java:
##########
@@ -166,17 +171,16 @@ public void testSomeApi() throws Exception {
                 e.printStackTrace();
             }
         }, 0, 2000L, TimeUnit.MILLISECONDS);
-
-
-        // Wait until the master is expired.
-        Thread.sleep(6000);
+        Boolean flag = await().atMost(Duration.ofSeconds(5)).until(() -> {
+            final GetReplicaInfoRequestHeader requestHeader = new GetReplicaInfoRequestHeader("broker1");
+            final RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CONTROLLER_GET_REPLICA_INFO, requestHeader);
+            final RemotingCommand response = this.remotingClient1.invokeSync(leaderAddr, request, 3000);
+            final GetReplicaInfoResponseHeader responseHeader = (GetReplicaInfoResponseHeader) response.decodeCommandCustomHeader(GetReplicaInfoResponseHeader.class);
+            return StringUtils.equals(responseHeader.getMasterAddress(), "127.0.0.1:8001");
+        }, item -> item);
 
         // The new master should be broker2.
-        final GetReplicaInfoRequestHeader requestHeader = new GetReplicaInfoRequestHeader("broker1");
-        final RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CONTROLLER_GET_REPLICA_INFO, requestHeader);
-        final RemotingCommand response = this.remotingClient1.invokeSync(leaderAddr, request, 3000);
-        final GetReplicaInfoResponseHeader responseHeader = (GetReplicaInfoResponseHeader) response.decodeCommandCustomHeader(GetReplicaInfoResponseHeader.class);
-        assertEquals(responseHeader.getMasterAddress(), "127.0.0.1:8001");
+        assertTrue(flag);

Review Comment:
   > These two lines can be combined into one line
   
   OK I will do



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org