Commit 22ffed16 authored by Nick Tchervenski's avatar Nick Tchervenski Committed by Viswanath Sivakumar

add a UT for Wangle::Future for circular dependency

Summary:
Making sure Wangle can handle circular dependencies.
There was an actual code issue in September that cause a crash in Atlas
Adserver due to this. The issue has been since fixed and Adserver's code
has been changed to avoid such circular dependency. We're adding a unit
test for this case.

Unit test is added as per our conversation on the Wangle group: https://www.facebook.com/groups/715931878455430/permalink/770180369697247/

Test Plan:
Add the same test on a code base from Sep 20th, observe that it fails:
https://phabricator.fb.com/P19352007

Run the unit test on latest code base - it succeeds

Reviewed By: hans@fb.com

Subscribers: atlas2-eng@, fugalh, folly-diffs@, leizhao, mchughj, kit, mpechuk

FB internal diff: D1761006

Tasks: 5384229

Signature: t1:1761006:1420238204:74ffb3fe8b88a25a23ade8e0990e69d405ea7f1e
parent f8f6e199
......@@ -1178,3 +1178,27 @@ TEST(Future, t5506504) {
waitWithSemaphore(fn());
}
// Test of handling of a circular dependency. It's never recommended
// to have one because of possible memory leaks. Here we test that
// we can handle freeing of the Future while it is running.
TEST(Future, CircularDependencySharedPtrSelfReset) {
Promise<int64_t> promise;
auto ptr = std::make_shared<Future<int64_t>>(promise.getFuture());
ptr->then(
[ptr] (folly::wangle::Try<int64_t>&& uid) mutable {
EXPECT_EQ(1, ptr.use_count());
// Leaving no references to ourselves.
ptr.reset();
EXPECT_EQ(0, ptr.use_count());
}
);
EXPECT_EQ(2, ptr.use_count());
ptr.reset();
promise.fulfil([]{return 1l;});
}
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