You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/12/08 23:02:13 UTC

[GitHub] [camel] bmk15897 opened a new pull request, #8875: Fix Flaky Tests Caused by JSON permutations

bmk15897 opened a new pull request, #8875:
URL: https://github.com/apache/camel/pull/8875

   ### Description
   Flaky Tests found using [NonDex](https://github.com/TestingResearchIllinois/NonDex) by running the commands -
   `
   mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.apache.camel.component.gson.GsonFieldNamePolicyTest#testMarshalPojo
   `
   
   `
   mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.apache.camel.component.gson.GsonMarshalExclusionTest#testMarshalAndUnmarshalPojoWithAnotherExclusion
   `
   
   `
   mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.apache.camel.component.gson.GsonMarshalExclusionTest#testMarshalAndUnmarshalPojoWithExclusion
   `
   
   `
   mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.apache.camel.component.gson.SpringGsonFieldNamePolicyTest#testMarshalPojo
   `
   The logged failures were-
   ```
   [ERROR] org.apache.camel.component.gson.GsonFieldNamePolicyTest.testMarshalPojo
   [ERROR]   Run 1: GsonFieldNamePolicyTest.testMarshalPojo:49 expected: <{"id":123,"first_name":"Donald","last_name":"Duck"}> but was: <{"first_name":"Donald","last_name":"Duck","id":123}>
   [ERROR]   Run 2: GsonFieldNamePolicyTest.testMarshalPojo:49 expected: <{"id":123,"first_name":"Donald","last_name":"Duck"}> but was: <{"last_name":"Duck","first_name":"Donald","id":123}>
   [ERROR]   Run 3: GsonFieldNamePolicyTest.testMarshalPojo:49 expected: <{"id":123,"first_name":"Donald","last_name":"Duck"}> but was: <{"id":123,"last_name":"Duck","first_name":"Donald"}>
   ```
   ```
   [ERROR] [WARNING] Flakes: 
   [WARNING] org.apache.camel.component.gson.GsonMarshalExclusionTest.testMarshalAndUnmarshalPojoWithAnotherExclusion
   [ERROR]   Run 1: GsonMarshalExclusionTest.testMarshalAndUnmarshalPojoWithAnotherExclusion:65 expected: <{"height":190,"weight":70}> but was: <{"weight":70,"height":190}>
   [INFO]   Run 2: PASS
   ```
   ```
   [WARNING] Flakes: 
   [WARNING] org.apache.camel.component.gson.GsonMarshalExclusionTest.testMarshalAndUnmarshalPojoWithExclusion
   [ERROR]   Run 1: GsonMarshalExclusionTest.testMarshalAndUnmarshalPojoWithExclusion:46 expected: <{"age":30,"height":190}> but was: <{"height":190,"age":30}>
   [INFO]   Run 2: PASS
   ```
   ```
   [ERROR] org.apache.camel.component.gson.SpringGsonFieldNamePolicyTest.testMarshalPojo
   [ERROR]   Run 1: SpringGsonFieldNamePolicyTest.testMarshalPojo:54 expected: <{"id":123,"first_name":"Donald","last_name":"Duck"}> but was: <{"last_name":"Duck","id":123,"first_name":"Donald"}>
   [ERROR]   Run 2: SpringGsonFieldNamePolicyTest.testMarshalPojo:54 expected: <{"id":123,"first_name":"Donald","last_name":"Duck"}> but was: <{"id":123,"last_name":"Duck","first_name":"Donald"}>
   [ERROR]   Run 3: SpringGsonFieldNamePolicyTest.testMarshalPojo:54 expected: <{"id":123,"first_name":"Donald","last_name":"Duck"}> but was: <{"id":123,"last_name":"Duck","first_name":"Donald"}>
   ```
   ### Investigation
   The tests  fail with a comparison error while comparing an expected JSON String and the result from the value returned by the funtion template.requestBody(...). The function of the that converts given Pojo Object to String does not guarantee the order of the fields in the Pojos. This makes the test outcome non-deterministic, and the test fails whenever the function returns a mismatch in order of the elements in the JSON String. To fix this, the expected and actual keys should be checked in a more deterministic way so that the assertions do not fail.
   
   ### Fix
   Expected and actual arrays can be compared without making assumptions about the order of the keys in these JSON Strings. Instead of using assertEquals for the complete JSON String, using contains for every subpart of the expected String makes the test more deterministic and ensures that the flakiness from the test is removed.
   
   The PR does not introduce a breaking change.


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] bmk15897 commented on a diff in pull request #8875: Fix Flaky Tests Caused by JSON permutations

Posted by GitBox <gi...@apache.org>.
bmk15897 commented on code in PR #8875:
URL: https://github.com/apache/camel/pull/8875#discussion_r1044109002


##########
components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java:
##########
@@ -43,7 +44,9 @@ public void testMarshalAndUnmarshalPojoWithExclusion() throws Exception {
 
         Object marshalled = template.requestBody("direct:inPojoExcludeWeight", in);
         String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled);
-        assertEquals("{\"age\":30,\"height\":190}", marshalledAsString);
+        assertTrue(marshalledAsString.contains("\"height\":190"));
+        assertTrue(marshalledAsString.contains("\"age\":30"));
+		assertFalse(marshalledAsString.contains("\"weight\":70"));

Review Comment:
   Okay, Doing that!



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] davsclaus commented on a diff in pull request #8875: Fix Flaky Tests Caused by JSON permutations

Posted by GitBox <gi...@apache.org>.
davsclaus commented on code in PR #8875:
URL: https://github.com/apache/camel/pull/8875#discussion_r1044103999


##########
components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java:
##########
@@ -43,7 +44,9 @@ public void testMarshalAndUnmarshalPojoWithExclusion() throws Exception {
 
         Object marshalled = template.requestBody("direct:inPojoExcludeWeight", in);
         String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled);
-        assertEquals("{\"age\":30,\"height\":190}", marshalledAsString);
+        assertTrue(marshalledAsString.contains("\"height\":190"));
+        assertTrue(marshalledAsString.contains("\"age\":30"));
+		assertFalse(marshalledAsString.contains("\"weight\":70"));

Review Comment:
   just run mvn install -P format to reformat



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] davsclaus merged pull request #8875: Fix Flaky Tests Caused by JSON permutations

Posted by GitBox <gi...@apache.org>.
davsclaus merged PR #8875:
URL: https://github.com/apache/camel/pull/8875


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #8875: Fix Flaky Tests Caused by JSON permutations

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #8875:
URL: https://github.com/apache/camel/pull/8875#issuecomment-1343893330

   ### Components tested:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 1 | 1 | 1 | 0 |


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] zhfeng commented on a diff in pull request #8875: Fix Flaky Tests Caused by JSON permutations

Posted by GitBox <gi...@apache.org>.
zhfeng commented on code in PR #8875:
URL: https://github.com/apache/camel/pull/8875#discussion_r1044100153


##########
components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java:
##########
@@ -43,7 +44,9 @@ public void testMarshalAndUnmarshalPojoWithExclusion() throws Exception {
 
         Object marshalled = template.requestBody("direct:inPojoExcludeWeight", in);
         String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled);
-        assertEquals("{\"age\":30,\"height\":190}", marshalledAsString);
+        assertTrue(marshalledAsString.contains("\"height\":190"));
+        assertTrue(marshalledAsString.contains("\"age\":30"));
+		assertFalse(marshalledAsString.contains("\"weight\":70"));

Review Comment:
   This line needs to indent.



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] davsclaus commented on a diff in pull request #8875: Fix Flaky Tests Caused by JSON permutations

Posted by GitBox <gi...@apache.org>.
davsclaus commented on code in PR #8875:
URL: https://github.com/apache/camel/pull/8875#discussion_r1044103999


##########
components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java:
##########
@@ -43,7 +44,9 @@ public void testMarshalAndUnmarshalPojoWithExclusion() throws Exception {
 
         Object marshalled = template.requestBody("direct:inPojoExcludeWeight", in);
         String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled);
-        assertEquals("{\"age\":30,\"height\":190}", marshalledAsString);
+        assertTrue(marshalledAsString.contains("\"height\":190"));
+        assertTrue(marshalledAsString.contains("\"age\":30"));
+		assertFalse(marshalledAsString.contains("\"weight\":70"));

Review Comment:
   just run 
   
       mvn install -P format
   
   to reformat



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #8875: Fix Flaky Tests Caused by JSON permutations

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #8875:
URL: https://github.com/apache/camel/pull/8875#issuecomment-1343919404

   ### Components tested:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 1 | 1 | 0 | 1 |


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #8875: Fix Flaky Tests Caused by JSON permutations

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #8875:
URL: https://github.com/apache/camel/pull/8875#issuecomment-1343482819

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :warning: Please note that the changes on this PR may be **tested automatically**. 
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
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: commits-unsubscribe@camel.apache.org

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