[&]() noexcept { value = expected; }
);
- observer->scheduleTimeout(std::chrono::milliseconds(100));
- observer->cancelTimeout();
+ std::weak_ptr<RequestContext> rctx_weak_ptr;
+
+ {
+ RequestContextScopeGuard rctx_guard;
+ rctx_weak_ptr = RequestContext::saveContext();
+ observer->scheduleTimeout(std::chrono::milliseconds(100));
+ observer->cancelTimeout();
+ }
+
+ // Ensure that RequestContext created for the scope has been released and
+ // deleted.
+ EXPECT_EQ(rctx_weak_ptr.expired(), true);
manager.loop();
int value = 0;
int const expected = 10;
EventBase manager;
+ std::unique_ptr<AsyncTimeout> observer;
+ std::weak_ptr<RequestContext> rctx_weak_ptr;
- auto observer = AsyncTimeout::schedule(
- std::chrono::milliseconds(100),
- manager,
- [&]() noexcept { value = expected; }
- );
+ {
+ RequestContextScopeGuard rctx_guard;
+ rctx_weak_ptr = RequestContext::saveContext();
+
+ observer = AsyncTimeout::schedule(
+ std::chrono::milliseconds(100), manager, [&]() noexcept {
+ value = expected;
+ });
+
+ observer->cancelTimeout();
+ }
- observer->cancelTimeout();
+ // Ensure that RequestContext created for the scope has been released and
+ // deleted.
+ EXPECT_EQ(rctx_weak_ptr.expired(), true);
manager.loop();