diff --git a/p2p/base/basic_async_resolver_factory_unittest.cc b/p2p/base/basic_async_resolver_factory_unittest.cc index ec13601643..6706f50d61 100644 --- a/p2p/base/basic_async_resolver_factory_unittest.cc +++ b/p2p/base/basic_async_resolver_factory_unittest.cc @@ -79,6 +79,11 @@ TEST(WrappingAsyncDnsResolverFactoryTest, WrapOtherResolver) { resolver.reset(); } +#if GTEST_HAS_DEATH_TEST && defined(WEBRTC_LINUX) +// Tests that the prohibition against deleting the resolver from the callback +// is enforced. This is required by the use of sigslot in the wrapped resolver. +// Checking the error message fails on a number of platforms, so run this +// test only on the platforms where it works. void CallResolver(WrappingAsyncDnsResolverFactory& factory) { rtc::SocketAddress address("", 0); std::unique_ptr resolver(factory.Create()); @@ -86,4 +91,27 @@ void CallResolver(WrappingAsyncDnsResolverFactory& factory) { WAIT(!resolver.get(), 10000 /*ms*/); } +TEST(WrappingAsyncDnsResolverFactoryDeathTest, DestroyResolverInCallback) { + // This test requires the main thread to be wrapped. So we defeat the + // workaround in test/test_main_lib.cc by explicitly wrapping the main + // thread here. + auto thread = rtc::Thread::CreateWithSocketServer(); + thread->WrapCurrent(); + // TODO(bugs.webrtc.org/12652): Rewrite as death test in loop style when it + // works. + WrappingAsyncDnsResolverFactory factory( + std::make_unique()); + + // Since EXPECT_DEATH is thread sensitive, and the resolver creates a thread, + // we wrap the whole creation section in EXPECT_DEATH. + RTC_EXPECT_DEATH(CallResolver(factory), + "Check failed: !within_resolve_result_"); + // If we get here, we have to unwrap the thread. + thread->Quit(); + thread->Run(); + thread->UnwrapCurrent(); + thread = nullptr; +} +#endif + } // namespace webrtc