You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2018/08/07 07:33:33 UTC

[incubator-servicecomb-saga] branch master updated: Try to fix the test error of PackIT in CI

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git


The following commit(s) were added to refs/heads/master by this push:
     new de0e14c  Try to fix the test error of PackIT in CI
de0e14c is described below

commit de0e14c0ac78c19c5b24ea3b5d6e6e2480c5d6cb
Author: Willem Jiang <ji...@huawei.com>
AuthorDate: Tue Aug 7 15:33:16 2018 +0800

    Try to fix the test error of PackIT in CI
---
 .../saga/integration/pack/tests/PackIT.java        | 40 ++++++++++++++--------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/integration-tests/pack-tests/src/test/java/org/apache/servicecomb/saga/integration/pack/tests/PackIT.java b/integration-tests/pack-tests/src/test/java/org/apache/servicecomb/saga/integration/pack/tests/PackIT.java
index d6106ef..2bc8e54 100644
--- a/integration-tests/pack-tests/src/test/java/org/apache/servicecomb/saga/integration/pack/tests/PackIT.java
+++ b/integration-tests/pack-tests/src/test/java/org/apache/servicecomb/saga/integration/pack/tests/PackIT.java
@@ -171,24 +171,36 @@ public class PackIT {
     assertThat(txAbortedEvent.serviceName(), is(serviceName));
     assertThat(txAbortedEvent.instanceId(), is(txStartedEvent2.instanceId()));
 
+    // The TxAbortedEvent and TxCompensatedEvent could arrive in different order 
+    TxEvent event = events.get(5);
+    checkedLastTwoEvents(globalTxId, txStartedEvent1, event);
 
-    assertThat(events.get(5).type(), is("TxAbortedEvent"));
-    txAbortedEvent = events.get(5);
-    System.out.println(txAbortedEvent);
-    assertThat(txAbortedEvent.localTxId(), is(globalTxId));
-    assertThat(txAbortedEvent.globalTxId(), is(globalTxId));
-    assertThat(txAbortedEvent.parentTxId(), is(nullValue()));
-    
-    TxEvent txCompensatedEvent1 = events.get(6);
-    assertThat(txCompensatedEvent1.type(), is("TxCompensatedEvent"));
-    assertThat(txCompensatedEvent1.localTxId(), is(txStartedEvent1.localTxId()));
-    assertThat(txCompensatedEvent1.parentTxId(), is(globalTxId));
-    assertThat(txCompensatedEvent1.serviceName(), is(serviceName));
-    assertThat(txCompensatedEvent1.instanceId(), is(txStartedEvent1.instanceId()));
+    event = events.get(6);
+    checkedLastTwoEvents(globalTxId, txStartedEvent1, event);
 
+    assertThat(compensatedMessages, contains("Goodbye, " + TRESPASSER));
+  }
 
+  private void checkedLastTwoEvents(String globalTxId, TxEvent txStartedEvent1, TxEvent event) {
+    if ("TxAbortedEvent".equals(event.type())) {
+      // check the globalTx
+      checkGloableTransactionEvent(event, globalTxId);
+    } else {
+      checkCompensatedTransactionEvent(event, txStartedEvent1, globalTxId);
+    }
+  }
 
-    assertThat(compensatedMessages, contains("Goodbye, " + TRESPASSER));
+  private void checkCompensatedTransactionEvent(TxEvent txCompensatedEvent, TxEvent txStartedEvent, String globalTxId) {
+    assertThat(txCompensatedEvent.localTxId(), is(txStartedEvent.localTxId()));
+    assertThat(txCompensatedEvent.parentTxId(), is(globalTxId));
+    assertThat(txCompensatedEvent.serviceName(), is(serviceName));
+    assertThat(txCompensatedEvent.instanceId(), is(txStartedEvent.instanceId()));
+  }
+
+  private void checkGloableTransactionEvent(TxEvent txAbortedEvent, String globalTxId) {
+    assertThat(txAbortedEvent.localTxId(), is(globalTxId));
+    assertThat(txAbortedEvent.globalTxId(), is(globalTxId));
+    assertThat(txAbortedEvent.parentTxId(), is(nullValue()));
   }
 
   @Test(timeout = 5000)