Add death test for WrappingAsyncResolver
Bug: webrtc:12598 Change-Id: Iff70cc2c53da5098514853eb6034874ee2e10b2c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214961 Reviewed-by: Markus Handell <handellm@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33704}
This commit is contained in:
committed by
Commit Bot
parent
a168bb9032
commit
e082984fee
@ -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<AsyncDnsResolverInterface> 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<BasicAsyncResolverFactory>());
|
||||
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user