-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flaky test fields iteration order #4095
Merged
nobodyiam
merged 4 commits into
apolloconfig:master
from
yyfMichaelYan:flakyTestFieldsIterationOrder
Nov 26, 2021
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f80148d
Fix flaky test testAssembleLongPollRefreshUrlWithMultipleNamespaces.
yyfMichaelYan 5826436
Fix flaky test testAssembleLongPollRefreshUrl.
yyfMichaelYan b6d985e
Update assertions in testAssembleLongPollRefreshUrl and testAssembleL…
yyfMichaelYan 21e1312
Merge branch 'master' into flakyTestFieldsIterationOrder
nobodyiam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,7 +510,10 @@ public void testAssembleLongPollRefreshUrl() throws Exception { | |
assertTrue(longPollRefreshUrl.contains("cluster=someCluster%2B+%26.-_someSign")); | ||
assertTrue(longPollRefreshUrl.contains( | ||
"notifications=%5B%7B%22namespaceName%22%3A%22" + someNamespace | ||
+ "%22%2C%22notificationId%22%3A" + 1 + "%7D%5D")); | ||
+ "%22%2C%22notificationId%22%3A" + 1 + "%7D%5D") | ||
|| longPollRefreshUrl.contains( | ||
"notifications=%5B%7B%22notificationId%22%3A" + 1 | ||
+ "%2C%22namespaceName%22%3A%22" + someNamespace + "%22%7D%5D")); | ||
} | ||
|
||
@Test | ||
|
@@ -532,11 +535,19 @@ public void testAssembleLongPollRefreshUrlWithMultipleNamespaces() throws Except | |
assertTrue(longPollRefreshUrl.contains(someServerUrl + "/notifications/v2?")); | ||
assertTrue(longPollRefreshUrl.contains("appId=" + someAppId)); | ||
assertTrue(longPollRefreshUrl.contains("cluster=someCluster%2B+%26.-_someSign")); | ||
String someNamespaceEntry = "%22namespaceName%22%3A%22" + someNamespace + "%22"; | ||
String someNotificationIdEntry = "%22notificationId%22%3A" + someNotificationId; | ||
String anotherNamespaceEntry = "%22namespaceName%22%3A%22" + anotherNamespace + "%22"; | ||
String anotherNotificationIdEntry = "%22notificationId%22%3A" + anotherNotificationId; | ||
assertTrue( | ||
longPollRefreshUrl.contains("notifications=%5B%7B%22namespaceName%22%3A%22" + someNamespace | ||
+ "%22%2C%22notificationId%22%3A" + someNotificationId | ||
+ "%7D%2C%7B%22namespaceName%22%3A%22" + anotherNamespace | ||
+ "%22%2C%22notificationId%22%3A" + anotherNotificationId + "%7D%5D")); | ||
longPollRefreshUrl.contains("notifications=%5B%7B" + someNamespaceEntry + "%2C" + someNotificationIdEntry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it make things easy if we make the |
||
+ "%7D%2C%7B" + anotherNamespaceEntry + "%2C" + anotherNotificationIdEntry + "%7D%5D") | ||
|| longPollRefreshUrl.contains("notifications=%5B%7B" + someNotificationIdEntry + "%2C" + someNamespaceEntry | ||
+ "%7D%2C%7B" + anotherNotificationIdEntry + "%2C" + anotherNamespaceEntry + "%7D%5D") | ||
|| longPollRefreshUrl.contains("notifications=%5B%7B" + someNotificationIdEntry + "%2C" + someNamespaceEntry | ||
+ "%7D%2C%7B" + anotherNamespaceEntry + "%2C" + anotherNotificationIdEntry + "%7D%5D") | ||
|| longPollRefreshUrl.contains("notifications=%5B%7B" + someNamespaceEntry + "%2C" + someNotificationIdEntry | ||
+ "%7D%2C%7B" + anotherNotificationIdEntry + "%2C" + anotherNamespaceEntry + "%7D%5D")); | ||
} | ||
|
||
public static class MockConfigUtil extends ConfigUtil { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it make things easy if we make the
notificationsMap
treemap?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not work by changing the implementation of
notificationsMap
toTreeMap
. The iteration order ofImmutableMap
is deterministic, which is why in the assertion oftestAssembleLongPollRefreshUrlWithMultipleNamespaces
,someName
always comes beforeanotherName
. In other words, these two flaky tests are not caused by the iteration order of entries of the map. However, for eithersomeName
andanotherName
, the order of the two fields,namespace
andnotificationId
, is non-deterministic. This is why all 4 possible combinations are covered in theassertTrue
intestAssembleLongPollRefreshUrlWithMultipleNamespaces
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got your point, it's not the map but the gson.toJson that might make the fields in different order.
I checked the
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory#getBoundFields
method, and it seems the order is determined by thejava.lang.Class#getDeclaredFields
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your information! Yes. I also went through all implementations of the
write
method which is hidden in thetoJson
method. I agree that the order may be determined byjava.lang.Class#getDeclaredFields
. However, since it's built in some package not maintained by this repository, I feel that it's better to change the assertion in our tests rather than modify the code ofjava.lang.Class#getDeclaredFields
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that the order might change in different execution environments. But the current changes to test all combinations of the URLs look quite complicated, which is not easy to maintain, e.g. if someone needs to add more namespaces to
testAssembleLongPollRefreshUrlWithMultipleNamespaces
.Is there some way to make the assertions simpler while still could works when the order of fields is changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I just updated both assertions. The assertions now will check that every field is converted to string, but it doesn't check the order of the fields. The assertions are now less strict than before, because some characters between neighboring fields are not checked, such as
{
,}
, and,
, but they look very simple and I think it's okay if we don't check those characters.