Skip to content

Commit

Permalink
Preserve values during root-counting tests
Browse files Browse the repository at this point in the history
Summary:
A couple tests measure how the number of active roots changes after executing a lamba. To more accurately measure this, any newly created values should be preserved until the measurement is made, rather than destroying them in the same lambda that created them.

The previous structure produced the correct test result, but depended on knowledge of when these roots would(n't) be garbage collected. This change removes that dependency (as the collection rules will change later in this stack).

Reviewed By: neildhar

Differential Revision: D41294068

fbshipit-source-id: af141825d365e617ea9b046d282916cdf762908d
  • Loading branch information
Matt Blagden authored and facebook-github-bot committed Dec 5, 2022
1 parent 803cb51 commit b4c0f0f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions unittests/API/APITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,23 @@ TEST(HermesRuntimeDeathTest, ValueTest) {

TEST_F(HermesRuntimeTest, DontGrowWhenMoveObjectOutOfValue) {
Value val = Object(*rt);
// Keep the object alive during measurement.
std::unique_ptr<Object> obj;
auto rootsDelta = HermesTestHelper::calculateRootsListChange(*rt, [&]() {
Object obj = std::move(val).getObject(*rt);
(void)obj;
obj = std::make_unique<Object>(std::move(val).getObject(*rt));
});
EXPECT_EQ(rootsDelta, 0);
}

TEST_F(HermesRuntimeTest, DontGrowWhenCloneObject) {
Value val = Object(*rt);
constexpr int kCloneCount = 1000;
// Keep the objects alive during measurement.
std::vector<Object> objects;
objects.reserve(kCloneCount);
auto rootsDelta = HermesTestHelper::calculateRootsListChange(*rt, [&]() {
for (int i = 0; i < 1000; i++) {
Object obj = val.getObject(*rt);
(void)obj;
for (size_t i = 0; i < kCloneCount; i++) {
objects.push_back(val.getObject(*rt));
}
});
EXPECT_EQ(rootsDelta, 0);
Expand Down

0 comments on commit b4c0f0f

Please sign in to comment.