Commit 628af5dd authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix Json.SortKeys test when F14NodeMap may randomize

Summary: [Folly] Fix `Json.SortKeys` test when `F14NodeMap` may randomize table iteration order.

Reviewed By: shixiao

Differential Revision: D17903465

fbshipit-source-id: 00f1a8c441af3e11815a4312f6dc810ec9455a5e
parent 3b62632c
...@@ -749,6 +749,28 @@ TEST(Json, SortKeys) { ...@@ -749,6 +749,28 @@ TEST(Json, SortKeys) {
nullptr)); nullptr));
// clang-format on // clang-format on
// dynamic object uses F14NodeMap which may randomize the table iteration
// order; consequently, we must force the table iteration order to be
// different from sorted order so that we can deterministically test sorting
// below
auto get_top_keys = [&] {
std::vector<std::string> top_keys;
for (auto const& key : value.keys()) {
top_keys.push_back(key.asString());
}
return top_keys;
};
std::vector<std::string> sorted_top_keys = get_top_keys();
std::sort(sorted_top_keys.begin(), sorted_top_keys.end());
while (get_top_keys() == sorted_top_keys) {
for (size_t i = 0; i < 64; ++i) {
value.insert(folly::to<std::string>("fake-", i), i);
}
for (size_t i = 0; i < 64; ++i) {
value.erase(folly::to<std::string>("fake-", i));
}
}
std::string sorted_keys = std::string sorted_keys =
R"({"a":[{"a":"b","c":"d"},12.5,"Yo Dawg",["heh"],null],)" R"({"a":[{"a":"b","c":"d"},12.5,"Yo Dawg",["heh"],null],)"
R"("another":32.2,"foo":"bar","junk":12})"; R"("another":32.2,"foo":"bar","junk":12})";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment