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

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new ad0b38f9d [SCB-2731] fix flaky junit tests in common and core (#3501)
ad0b38f9d is described below

commit ad0b38f9de90c73526fed719fd5dba6430e653b2
Author: anantdahiya8 <[email protected]>
AuthorDate: Fri Nov 25 20:54:44 2022 -0500

    [SCB-2731] fix flaky junit tests in common and core (#3501)
---
 .../servicecomb/common/rest/RestProducerInvocationCreatorTest.java | 7 ++++---
 .../common/rest/codec/param/TestRestClientRequestImpl.java         | 7 ++++++-
 .../common/rest/filter/inner/RestServerCodecFilterTest.java        | 5 +++--
 core/src/test/java/org/apache/servicecomb/core/TestInvocation.java | 2 +-
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
index 94604e256..12877bc4a 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java
@@ -114,7 +114,8 @@ public class RestProducerInvocationCreatorTest {
       CommonExceptionData data = (CommonExceptionData) 
throwable.getErrorData();
 
       
assertThat(throwable.getStatusCode()).isEqualTo(NOT_FOUND.getStatusCode());
-      
assertThat(Json.encode(data)).isEqualTo("{\"code\":\"SCB.00000002\",\"message\":\"Not
 Found\"}");
+      
assertThat(Json.encode(data)).isIn("{\"code\":\"SCB.00000002\",\"message\":\"Not
 Found\"}",
+              "{\"message\":\"Not Found\",\"code\":\"SCB.00000002\"}");
     }
   }
 
@@ -136,8 +137,8 @@ public class RestProducerInvocationCreatorTest {
       CommonExceptionData data = (CommonExceptionData) 
throwable.getErrorData();
 
       
assertThat(throwable.getStatusCode()).isEqualTo(NOT_ACCEPTABLE.getStatusCode());
-      assertThat(Json.encode(data))
-              .isEqualTo("{\"code\":\"SCB.00000000\",\"message\":\"Accept 
test-type is not supported\"}");
+      
assertThat(Json.encode(data)).isIn("{\"code\":\"SCB.00000000\",\"message\":\"Accept
 test-type is not supported\"}",
+              "{\"message\":\"Accept test-type is not 
supported\",\"code\":\"SCB.00000000\"}");
     }
   }
 
diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestRestClientRequestImpl.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestRestClientRequestImpl.java
index 7a6ccdf67..87abba922 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestRestClientRequestImpl.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestRestClientRequestImpl.java
@@ -43,6 +43,7 @@ import io.vertx.core.Context;
 import io.vertx.core.MultiMap;
 import io.vertx.core.buffer.Buffer;
 import io.vertx.core.http.HttpClientRequest;
+import static org.assertj.core.api.Assertions.assertThat;
 
 public class TestRestClientRequestImpl {
   private HttpClientRequest request;
@@ -66,7 +67,7 @@ public class TestRestClientRequestImpl {
     restClientRequest.addForm("def", "world");
     restClientRequest.addForm("ghi", null);
     Buffer buffer = restClientRequest.getBodyBuffer();
-    Assertions.assertEquals("abc=Hello&def=world&", buffer.toString());
+    assertThat(buffer.toString()).isIn("def=world&abc=Hello&", 
"abc=Hello&def=world&");
   }
 
   @Test
@@ -76,6 +77,10 @@ public class TestRestClientRequestImpl {
       map.add(io.vertx.core.http.HttpHeaders.COOKIE, 
"sessionid=abcdefghijklmnopqrstuvwxyz; region=china-north; ");
       return null;
     }).when(request).putHeader(io.vertx.core.http.HttpHeaders.COOKIE, 
"sessionid=abcdefghijklmnopqrstuvwxyz; region=china-north; ");
+    Mockito.doAnswer(invocation -> {
+      map.add(io.vertx.core.http.HttpHeaders.COOKIE, 
"sessionid=abcdefghijklmnopqrstuvwxyz; region=china-north; ");
+      return null;
+    }).when(request).putHeader(io.vertx.core.http.HttpHeaders.COOKIE, 
"region=china-north; sessionid=abcdefghijklmnopqrstuvwxyz; ");
     Mockito.when(request.headers()).thenReturn(map);
 
     RestClientRequestImpl restClientRequest = new 
RestClientRequestImpl(request, null, null);
diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
index cd1279f7d..2d74c468d 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilterTest.java
@@ -142,8 +142,9 @@ public class RestServerCodecFilterTest {
     Response response = codecFilter.onFilter(invocation, nextNode).get();
 
     assertThat(response.getStatus()).isEqualTo(INTERNAL_SERVER_ERROR);
-    assertThat(Json.encode(response.getResult()))
-        .isEqualTo("{\"code\":\"SCB.50000000\",\"message\":\"mock encode 
request failed\"}");
+    assertThat(Json.encode(response.getResult())).
+            isIn("{\"code\":\"SCB.50000000\",\"message\":\"mock encode request 
failed\"}",
+                    "{\"message\":\"mock encode request 
failed\",\"code\":\"SCB.50000000\"}");
   }
 
   private void success_invocation() throws InterruptedException, 
ExecutionException {
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java 
b/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
index 6b22d5d63..814c7038b 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestInvocation.java
@@ -252,7 +252,7 @@ public class TestInvocation {
       }
     };
 
-    MatcherAssert.assertThat(Invocation.loadTraceIdGenerators(), 
Matchers.contains(gen1, gen3));
+    MatcherAssert.assertThat(Invocation.loadTraceIdGenerators(), 
Matchers.containsInAnyOrder(gen1, gen3));
   }
 
   InvocationBaseEvent invocationBaseEvent;

Reply via email to