Remove flaky StringAtom test.

The test assumed that it was the only thing that initialized StringAtom
objects during testing, but this is no longer true now that StringAtom
are used all over the place, and allocated by other tests, which affect
the global StringAtom set.

Fix the issue by storing the input StringAtom pointers in place
before iterating over the set.

Change-Id: I65d56ad8933cf5984ef1b738a6c4d082c577acdd
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/7680
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
diff --git a/src/gn/string_atom_unittest.cc b/src/gn/string_atom_unittest.cc
index 2dcc993..ba151e3 100644
--- a/src/gn/string_atom_unittest.cc
+++ b/src/gn/string_atom_unittest.cc
@@ -6,6 +6,8 @@
 
 #include "util/test/test.h"
 
+#include <algorithm>
+#include <array>
 #include <set>
 #include <string>
 #include <vector>
@@ -78,8 +80,20 @@
   auto bar_ret = set.insert(std::string_view("bar"));
   auto zoo_ret = set.insert(std::string_view("zoo"));
 
+  auto atom_to_ptr = [](const StringAtom& atom) -> const std::string* {
+    return &atom.str();
+  };
+
+  EXPECT_TRUE(foo_ret.second);
+  EXPECT_TRUE(bar_ret.second);
+  EXPECT_TRUE(zoo_ret.second);
+
+  const std::string* foo_ptr = atom_to_ptr(*foo_ret.first);
+  const std::string* bar_ptr = atom_to_ptr(*bar_ret.first);
+  const std::string* zoo_ptr = atom_to_ptr(*zoo_ret.first);
+
   StringAtom foo_key("foo");
-  EXPECT_EQ(*foo_ret.first, foo_key);
+  EXPECT_EQ(foo_ptr, atom_to_ptr(foo_key));
 
   auto foo_it = set.find(foo_key);
   EXPECT_NE(foo_it, set.end());
@@ -89,16 +103,26 @@
   EXPECT_EQ(set.find(std::string_view("zoo")), zoo_ret.first);
 
   // Fast sets are ordered according to the key pointer.
-  // Because of the underlying bump allocator, addresses
-  // for the first three inserts are in increasing order.
+  // Even though a bump allocator is used to allocate AtomString
+  // strings, there is no guarantee that the global StringAtom
+  // set was not already populated by a different test previously,
+  // which means the pointers value need to be sorted before
+  // iterating over the set for comparison.
+  std::array<const std::string*, 3> ptrs = {
+      foo_ptr,
+      bar_ptr,
+      zoo_ptr,
+  };
+  std::sort(ptrs.begin(), ptrs.end());
+
   auto it = set.begin();
-  EXPECT_EQ(it, foo_ret.first);
+  EXPECT_EQ(atom_to_ptr(*it), ptrs[0]);
   ++it;
 
-  EXPECT_EQ(it, bar_ret.first);
+  EXPECT_EQ(atom_to_ptr(*it), ptrs[1]);
   ++it;
 
-  EXPECT_EQ(it, zoo_ret.first);
+  EXPECT_EQ(atom_to_ptr(*it), ptrs[2]);
   ++it;
 
   EXPECT_EQ(it, set.end());