From f8d10db363a5a8ab9d0ba6df76f44f8bde66f89c Mon Sep 17 00:00:00 2001 From: Abyss <45425302+wangxye@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:16:08 +0800 Subject: [PATCH] fix: add await conditions for trans grpc test (#21) Signed-off-by: wangxye --- .../broker/server/TransactionMessageTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/java/e2e/src/test/java/org/apache/rocketmq/broker/server/TransactionMessageTest.java b/java/e2e/src/test/java/org/apache/rocketmq/broker/server/TransactionMessageTest.java index dbc8704..a90361f 100644 --- a/java/e2e/src/test/java/org/apache/rocketmq/broker/server/TransactionMessageTest.java +++ b/java/e2e/src/test/java/org/apache/rocketmq/broker/server/TransactionMessageTest.java @@ -40,6 +40,7 @@ import org.apache.rocketmq.util.RandomUtils; import org.apache.rocketmq.util.TestUtils; import org.apache.rocketmq.util.VerifyUtils; +import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -139,8 +140,11 @@ public void testTrans_SendCheckerCommit_PushConsume() { producer.sendTrans(message, null); } //Wait for the callback to execute commit - TestUtils.waitForSeconds(60); + TestUtils.waitForSeconds(30); Assertions.assertEquals(SEND_NUM, producer.getEnqueueMessages().getDataSize(), "send message failed"); + Awaitility.await().atMost(Duration.ofSeconds(180)).until(() -> { + return pushConsumer.getListener().getDequeueMessages().getDataSize() == SEND_NUM; + }); VerifyUtils.verifyNormalMessage(producer.getEnqueueMessages(), pushConsumer.getListener().getDequeueMessages()); } @@ -195,14 +199,15 @@ public TransactionResolution check(MessageView messageView) { Message message = MessageFactory.buildMessage(topic, tag, String.valueOf(i)); producer.sendTrans(message, null); } - await().atMost(120, SECONDS).until(new Callable() { + //Wait for the rollback and execute commit/rollback + TestUtils.waitForSeconds(60); + //Wait for the callback to execute commit + await().atMost(180, SECONDS).until(new Callable() { @Override public Boolean call() { return rollbackMsgNum.get() == commitMsgNum.get() && commitMsgNum.get() == SEND_NUM / 2; } }); - //Wait for the rollback and execute commit/rollback - TestUtils.waitForSeconds(60); Assertions.assertEquals(SEND_NUM, producer.getEnqueueMessages().getDataSize(), "send message failed"); Assertions.assertEquals(5, pushConsumer.getListener().getDequeueMessages().getDataSize()); }