Skip to content

Commit 228d81d

Browse files
committed
fix unstable case
1 parent b4f96da commit 228d81d

3 files changed

Lines changed: 139 additions & 132 deletions

File tree

testcase/src/test/java/stest/tron/wallet/dailybuild/eventquery/EventQuery005.java

Lines changed: 131 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void test01EventQueryForTransactionFreezeBalanceV2() throws InterruptedEx
7373
public void run() {
7474
while (true) {
7575
zmq.ZMQ.Event event = zmq.ZMQ.Event.read(moniter.base());
76+
logger.info("!!!!{} {}", event.event, event.addr);
7677
System.out.println(event.event + " " + event.addr);
7778
}
7879
}
@@ -84,43 +85,50 @@ public void run() {
8485
Boolean sendTransaction = true;
8586
Integer retryTimes = 40;
8687
transactionIdList = new ArrayList<>();
87-
while (retryTimes-- > 0) {
88-
if (sendTransaction) {
89-
String txid = PublicMethed.freezeBalanceV2AndGetTxId(freezeAccount,
90-
maxFeeLimit, 0, freezeAccountKey, blockingStubFull);
88+
ArrayList<byte[]> messageArray = new ArrayList<byte[]>();
89+
Thread readLoopThread = new Thread(
90+
new Runnable() {
91+
public void run() {
92+
while (true) {
93+
byte[] message = req.recv();
94+
messageArray.add(message);
95+
}
96+
}
97+
});
98+
readLoopThread.start();
99+
boolean success = false;
91100

92-
transactionIdList.add(txid);
93-
PublicMethed.waitProduceNextBlock(blockingStubFull);
94-
if (PublicMethed.getTransactionInfoById(txid, blockingStubFull).get().getResultValue()
95-
== 0) {
96-
sendTransaction = false;
97-
}
101+
while (retryTimes-- > 0) {
102+
if(success){
103+
break;
98104
}
99-
byte[] message = req.recv();
100-
101-
102-
if (message != null) {
103-
transactionMessage = new String(message);
104-
logger.info("transaction message:" + transactionMessage);
105-
106-
if (!transactionMessage.equals("transactionTrigger")
107-
&& !transactionMessage.isEmpty()
108-
&& transactionMessage.contains("transactionId")) {
109-
JSONObject data = JSON.parseObject(transactionMessage);
110-
String id = data.getString("transactionId");
111-
logger.info("trxId : " + id);
112-
if (transactionIdList.contains(id)) {
113-
logger.info("find target tx, begin to Assert and abort loop");
114-
Assert.assertEquals(data.getString("contractType"), "FreezeBalanceV2Contract");
115-
Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount));
116-
Assert.assertEquals(data.getString("assetName"), "trx");
117-
Assert.assertEquals(data.getLong("assetAmount"), maxFeeLimit);
118-
break;
105+
String txid = PublicMethed.freezeBalanceV2AndGetTxId(freezeAccount,
106+
maxFeeLimit, 0, freezeAccountKey, blockingStubFull);
107+
transactionIdList.add(txid);
108+
PublicMethed.waitProduceNextBlock(blockingStubFull);
109+
110+
for(byte[] message: messageArray){
111+
if (message != null) {
112+
transactionMessage = new String(message);
113+
logger.info("transaction message:" + transactionMessage);
114+
115+
if (!transactionMessage.equals("transactionTrigger")
116+
&& !transactionMessage.isEmpty()
117+
&& transactionMessage.contains("transactionId")) {
118+
JSONObject data = JSON.parseObject(transactionMessage);
119+
String id = data.getString("transactionId");
120+
logger.info("trxId : " + id);
121+
if (transactionIdList.contains(id)) {
122+
logger.info("find target tx, begin to Assert and abort loop");
123+
Assert.assertEquals(data.getString("contractType"), "FreezeBalanceV2Contract");
124+
Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount));
125+
Assert.assertEquals(data.getString("assetName"), "trx");
126+
Assert.assertEquals(data.getLong("assetAmount"), maxFeeLimit);
127+
success = true;
128+
break;
129+
}
119130
}
120-
121131
}
122-
} else {
123-
sendTransaction = true;
124132
}
125133
}
126134
logger.info("Final transaction message:" + transactionMessage);
@@ -166,47 +174,58 @@ public void run() {
166174
req.setReceiveTimeOut(10000);
167175
String transactionMessage = "";
168176
Boolean sendTransaction = true;
169-
Integer retryTimes = 20;
177+
Integer retryTimes = 40;
170178
transactionIdList = new ArrayList<>();
179+
ArrayList<byte[]> messageArray = new ArrayList<byte[]>();
180+
Thread readLoopThread = new Thread(
181+
new Runnable() {
182+
public void run() {
183+
while (true) {
184+
byte[] message = req.recv();
185+
messageArray.add(message);
186+
}
187+
}
188+
});
189+
readLoopThread.start();
190+
boolean success = false;
191+
171192
Long unfreezeAmount = 10000000L;
172193
while (retryTimes-- > 0) {
173-
if (sendTransaction) {
174-
String txid = PublicMethed.unFreezeBalanceV2AndGetTxId(freezeAccount,
175-
freezeAccountKey, unfreezeAmount, 0, blockingStubFull);
176-
177-
transactionIdList.add(txid);
178-
PublicMethed.waitProduceNextBlock(blockingStubFull);
179-
if (PublicMethed.getTransactionInfoById(txid, blockingStubFull).get().getResultValue()
180-
== 0) {
181-
sendTransaction = false;
182-
}
194+
if (success){
195+
break;
183196
}
184-
byte[] message = req.recv();
185-
186-
187-
if (message != null) {
188-
transactionMessage = new String(message);
189-
logger.info("transaction message:" + transactionMessage);
190-
191-
if (!transactionMessage.equals("transactionTrigger")
192-
&& !transactionMessage.isEmpty()
193-
&& transactionMessage.contains("transactionId")) {
194-
JSONObject data = JSON.parseObject(transactionMessage);
195-
String id = data.getString("transactionId");
196-
if(transactionIdList.contains(id)) {
197-
logger.info("find target tx, begin to Assert and abort loop");
198-
logger.info("trxId : " + data.getString("transactionId"));
199-
Assert.assertEquals(data.getString("contractType"), "UnfreezeBalanceV2Contract");
200-
Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount));
201-
Assert.assertEquals(data.getString("assetName"), "trx");
202-
Assert.assertEquals(data.getLong("assetAmount"), unfreezeAmount);
203-
break;
197+
String txid = PublicMethed.unFreezeBalanceV2AndGetTxId(freezeAccount,
198+
freezeAccountKey, unfreezeAmount, 0, blockingStubFull);
199+
200+
transactionIdList.add(txid);
201+
PublicMethed.waitProduceNextBlock(blockingStubFull);
202+
203+
204+
for(byte[] message: messageArray){
205+
if (message != null) {
206+
transactionMessage = new String(message);
207+
logger.info("transaction message:" + transactionMessage);
208+
209+
if (!transactionMessage.equals("transactionTrigger")
210+
&& !transactionMessage.isEmpty()
211+
&& transactionMessage.contains("transactionId")) {
212+
JSONObject data = JSON.parseObject(transactionMessage);
213+
String id = data.getString("transactionId");
214+
if(transactionIdList.contains(id)) {
215+
logger.info("find target tx, begin to Assert and abort loop");
216+
logger.info("trxId : " + data.getString("transactionId"));
217+
Assert.assertEquals(data.getString("contractType"), "UnfreezeBalanceV2Contract");
218+
Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount));
219+
Assert.assertEquals(data.getString("assetName"), "trx");
220+
Assert.assertEquals(data.getLong("assetAmount"), unfreezeAmount);
221+
success = true;
222+
break;
223+
}
204224
}
205-
206225
}
207-
} else {
208-
sendTransaction = true;
209226
}
227+
228+
210229
}
211230
logger.info("Final transaction message:" + transactionMessage);
212231
logger.info("retryTimes: " + retryTimes);
@@ -239,11 +258,12 @@ public void test03EventQueryForTransactionDelegateResource() throws InterruptedE
239258
PublicMethed.freezeBalanceV2AndGetTxId(freezeAccount,
240259
maxFeeLimit, 0, freezeAccountKey, blockingStubFull);
241260
PublicMethed.waitProduceNextBlock(blockingStubFull);
261+
ZMQ.Context context = ZMQ.context(1);
262+
ZMQ.Socket req = context.socket(ZMQ.SUB);
242263

243264
List<String> transactionIdList = new ArrayList<>();
244265

245-
ZMQ.Context context = ZMQ.context(1);
246-
ZMQ.Socket req = context.socket(ZMQ.SUB);
266+
247267

248268
req.subscribe("transactionTrigger");
249269
final ZMQ.Socket moniter = context.socket(ZMQ.PAIR);
@@ -264,45 +284,54 @@ public void run() {
264284
Boolean sendTransaction = true;
265285
Integer retryTimes = 20;
266286
transactionIdList = new ArrayList<>();
287+
ArrayList<byte[]> messageArray = new ArrayList<byte[]>();
288+
Thread readLoopThread = new Thread(
289+
new Runnable() {
290+
public void run() {
291+
while (true) {
292+
byte[] message = req.recv();
293+
messageArray.add(message);
294+
}
295+
}
296+
});
297+
readLoopThread.start();
298+
boolean success = false;
299+
267300
Long delegateAmount = 10000000L;
268301
while (retryTimes-- > 0) {
269-
if (sendTransaction) {
270-
String txid = PublicMethed.delegateResourceV2AndGetTxId(freezeAccount,
271-
delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull);
272-
273-
transactionIdList.add(txid);
274-
PublicMethed.waitProduceNextBlock(blockingStubFull);
275-
if (PublicMethed.getTransactionInfoById(txid, blockingStubFull).get().getResultValue()
276-
== 0) {
277-
sendTransaction = false;
278-
}
302+
if(success) {
303+
break;
279304
}
280-
byte[] message = req.recv();
281-
282-
283-
if (message != null) {
284-
transactionMessage = new String(message);
285-
logger.info("transaction message:" + transactionMessage);
305+
String txid = PublicMethed.delegateResourceV2AndGetTxId(freezeAccount,
306+
delegateAmount, 0, receiverAddress, freezeAccountKey, blockingStubFull);
307+
308+
transactionIdList.add(txid);
309+
PublicMethed.waitProduceNextBlock(blockingStubFull);
310+
311+
for(byte[] message: messageArray) {
312+
if (message != null) {
313+
transactionMessage = new String(message);
314+
logger.info("transaction message:" + transactionMessage);
315+
316+
if (!transactionMessage.equals("transactionTrigger")
317+
&& !transactionMessage.isEmpty()
318+
&& transactionMessage.contains("transactionId")) {
319+
JSONObject data = JSON.parseObject(transactionMessage);
320+
String id = data.getString("transactionId");
321+
if (transactionIdList.contains(id)) {
322+
logger.info("find target tx, begin to Assert and abort loop");
323+
logger.info("trxId : " + id);
324+
Assert.assertEquals(data.getString("contractType"), "DelegateResourceContract");
325+
Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount));
326+
Assert.assertEquals(data.getString("toAddress"), Base58.encode58Check(receiverAddress));
327+
Assert.assertEquals(data.getString("assetName"), "trx");
328+
Assert.assertEquals(data.getLong("assetAmount"), delegateAmount);
329+
success = true;
330+
break;
331+
}
286332

287-
if (!transactionMessage.equals("transactionTrigger")
288-
&& !transactionMessage.isEmpty()
289-
&& transactionMessage.contains("transactionId")) {
290-
JSONObject data = JSON.parseObject(transactionMessage);
291-
String id = data.getString("transactionId");
292-
if (transactionIdList.contains(id)) {
293-
logger.info("find target tx, begin to Assert and abort loop");
294-
logger.info("trxId : " + id);
295-
Assert.assertEquals(data.getString("contractType"), "DelegateResourceContract");
296-
Assert.assertEquals(data.getString("fromAddress"), Base58.encode58Check(freezeAccount));
297-
Assert.assertEquals(data.getString("toAddress"), Base58.encode58Check(receiverAddress));
298-
Assert.assertEquals(data.getString("assetName"), "trx");
299-
Assert.assertEquals(data.getLong("assetAmount"), delegateAmount);
300-
break;
301333
}
302-
303334
}
304-
} else {
305-
sendTransaction = true;
306335
}
307336
}
308337
logger.info("Final transaction message:" + transactionMessage);

testcase/src/test/java/stest/tron/wallet/dailybuild/jsonrpc/Accounts001.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,7 @@ public void test54JsonRpcApiTestForEthGetBlockByNumber() throws Exception {
15141514

15151515
@Test(enabled = false, description = "Json rpc api of eth_getBlockTransactionCountByNumber params are finalized ")
15161516
public void test55JsonRpcApiTestForEthGetBlockTransactionCountByNum() {
1517-
// response = HttpMethed.getNowBlockFromSolidity(httpsolidityNode);
1518-
response = HttpMethed.getNowBlockFromSolidity(":50094");
1517+
response = HttpMethed.getNowBlockFromSolidity(httpsolidityNode);
15191518
responseContent = HttpMethed.parseResponseContent(response);
15201519
if (!responseContent.containsKey("transactions")){
15211520
return;
@@ -1525,7 +1524,7 @@ public void test55JsonRpcApiTestForEthGetBlockTransactionCountByNum() {
15251524
JsonArray params = new JsonArray();
15261525
params.add("finalized");
15271526
JsonObject requestBody = getJsonRpcBody("eth_getBlockTransactionCountByNumber", params);
1528-
response = getJsonRpc(":50645", requestBody);
1527+
response = getJsonRpc(jsonRpcNode, requestBody);
15291528
responseContent = HttpMethed.parseResponseContent(response);
15301529
String transactionNum = responseContent.getString("result").substring(2);
15311530
int transactionNum2 = Integer.parseInt(transactionNum, 16);
@@ -1537,7 +1536,7 @@ public void test55JsonRpcApiTestForEthGetBlockTransactionCountByNum() {
15371536

15381537
@Test(enabled = false, description = "Json rpc api of eth_getTransactionByBlockNumberAndIndex params are finalized")
15391538
public void test56JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() throws Exception {
1540-
response = HttpMethed.getNowBlockFromSolidity(":50094");
1539+
response = HttpMethed.getNowBlockFromSolidity(httpsolidityNode);
15411540
responseContent = HttpMethed.parseResponseContent(response);
15421541
if (!responseContent.containsKey("transactions")) {
15431542
return;
@@ -1548,7 +1547,7 @@ public void test56JsonRpcApiTestForEthGetTransactionByBlockNumberAndIndex() thro
15481547
params.add("finalized");
15491548
params.add("0x0");
15501549
JsonObject requestBody = getJsonRpcBody("eth_getTransactionByBlockNumberAndIndex", params);
1551-
response = getJsonRpc(":50645", requestBody);
1550+
response = getJsonRpc(jsonRpcNode, requestBody);
15521551
responseContent = HttpMethed.parseResponseContent(response);
15531552
String trans2 = responseContent.getJSONObject("result").toJSONString();
15541553
System.out.println(responseContent.toJSONString());
Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
33
<suite name="Daily Build">
4-
<listeners>
5-
<listener class-name="stest.tron.wallet.common.client.utils.DailyBuildReport"></listener>
6-
</listeners>
7-
<test name="Parallel Case" parallel = "classes" thread-count = "8">
8-
<packages>
9-
<package name="stest.tron.wallet.dailybuild.*">
10-
<exclude name="stest.tron.wallet.dailybuild.multisign"></exclude>
11-
<exclude name="stest.tron.wallet.dailybuild.http"></exclude>
12-
<exclude name="stest.tron.wallet.dailybuild.separateExecution"></exclude>
13-
<exclude name="stest.tron.wallet.dailybuild.jsonrpc"></exclude>
14-
<exclude name="stest.tron.wallet.dailybuild.eventquery"></exclude>
15-
<exclude name="stest.tron.wallet.dailybuild.zentrc20token"></exclude>
16-
<exclude name="stest.tron.wallet.dailybuild.ratelimit"></exclude>
17-
</package>
18-
</packages>
19-
</test>
20-
<test name="Serial Case" parallel = "classes" thread-count = "1" preserve-order="true">
21-
<packages>
22-
<package name="stest.tron.wallet.dailybuild.ratelimit.*"></package>
23-
<package name="stest.tron.wallet.dailybuild.http.*"></package>
24-
<package name="stest.tron.wallet.dailybuild.jsonrpc"></package>
25-
<package name="stest.tron.wallet.dailybuild.zentrc20token"></package>
26-
<package name="stest.tron.wallet.dailybuild.eventquery"></package>
27-
<package name="stest.tron.wallet.dailybuild.separateExecution.*"></package>
28-
</packages>
4+
5+
<test name="Parallel Case" parallel = "classes" thread-count = "1">
6+
<classes><class name="stest.tron.wallet.dailybuild.eventquery.EventQuery005"></class></classes>
297
</test>
8+
309
</suite>

0 commit comments

Comments
 (0)