Use std::map for computing json object hash#11875
Merged
ggreenway merged 5 commits intoenvoyproxy:masterfrom Jul 8, 2020
greenhouse-org:fix-json-hash
Merged
Use std::map for computing json object hash#11875ggreenway merged 5 commits intoenvoyproxy:masterfrom greenhouse-org:fix-json-hash
ggreenway merged 5 commits intoenvoyproxy:masterfrom
greenhouse-org:fix-json-hash
Conversation
- Reviewing all unordered_map, we discovered this test was flawed, because it assumed ordering of map elements. This is true of libc++ and msvc, but not consistant with one another, and not true absl::node_hash_map at all, resulting in test failing 50% of the time. - Reviewing the RFC, the hash comparison itself did not follow json. - Note this could be updated with the equivilant absl collection type if and when all std::map's are refactored. Co-authored-by: Sunjay Bhatia <sunjayb@vmware.com> Co-authored-by: William A Rowe Jr <wrowe@vmware.com> Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com> Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
Rekick for test/integration/http2_integration_test flake on master Signed-off-by: William A Rowe Jr <wrowe@vmware.com>
ggreenway
previously approved these changes
Jul 6, 2020
| ObjectSharedPtr json2 = Factory::loadFromString("{\"value2\": -12.3, \"value1\": 10.5}"); | ||
| ObjectSharedPtr json3 = Factory::loadFromString(" { \"value2\": -12.3, \"value1\": 10.5} "); | ||
| EXPECT_NE(json1->hash(), json2->hash()); | ||
| EXPECT_EQ(json1->hash(), json2->hash()); |
Contributor
There was a problem hiding this comment.
Should these tests be stricter and verify that the hash has a specific value?
Member
There was a problem hiding this comment.
We could to make it v strict, though changing the underlying container/hash algorithm changes could make this test brittle and require repeated changes
Contributor
There was a problem hiding this comment.
Agreed.
possible nit: there are no remaining EXPECT_NE for the hash function. It may make sense to add something like:
ObjectSharedPtr json4 = Factory::loadFromString("{"value1": 10.5}");
EXPECT_EQ(json1->hash(), json4->hash());
Member
There was a problem hiding this comment.
good point! will add that test assertion
Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
Also add comments clarifying test cases Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
ggreenway
approved these changes
Jul 8, 2020
scheler
pushed a commit
to scheler/envoy
that referenced
this pull request
Aug 4, 2020
- Reviewing all unordered_map, we discovered this test was flawed, because it assumed ordering of map elements. This is true of libc++ and msvc, but not consistant with one another, and not true absl::node_hash_map at all, resulting in test failing 50% of the time. - Reviewing the RFC, the hash comparison itself did not follow json. - Note this could be updated with the equivilant absl collection type if and when all std::map's are refactored. Co-authored-by: Sunjay Bhatia <sunjayb@vmware.com> Co-authored-by: William A Rowe Jr <wrowe@vmware.com> Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com> Signed-off-by: William A Rowe Jr <wrowe@vmware.com> Signed-off-by: scheler <santosh.cheler@appdynamics.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Commit Message: Use std::map for computing json object hash
Additional Description:
Reviewing all unordered_map, we discovered this test was flawed,
because it assumed ordering of unordered map elements. This is true
of libc++ and msvc, but not consistent with one another, and not
true absl::node_hash_map at all, resulting in test failing 50%
of the time when converted to absl.
Reviewing the RFC, the hash comparison itself did not follow json
which insists they are compared without respect to order.
Note this could be updated with the equivalent absl collection type,
if and when all std::map's are refactored, but was out of scope to
addressing std::unordered_map.
Co-authored-by: Sunjay Bhatia sunjayb@vmware.com
Co-authored-by: William A Rowe Jr wrowe@vmware.com
Signed-off-by: Sunjay Bhatia sunjayb@vmware.com
Signed-off-by: William A Rowe Jr wrowe@vmware.com
For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md
Risk Level: low
Testing: local, windows & linux docker containers
Docs Changes: n/a
Release Notes: n/a