Delete unused features of AsyncInvoke.

Also eliminates its dependency on callback.h.

BUG=None

Review-Url: https://codereview.webrtc.org/2871403003
Cr-Commit-Position: refs/heads/master@{#18163}
This commit is contained in:
nisse
2017-05-16 05:51:29 -07:00
committed by Commit bot
parent 1d7392a45c
commit c4a3173db0
4 changed files with 0 additions and 324 deletions

View File

@ -421,13 +421,6 @@ class AsyncInvokeTest : public testing::Test {
EXPECT_EQ(expected_thread_, Thread::Current());
int_value_ = value;
}
void AsyncInvokeIntCallback(AsyncInvoker* invoker, Thread* thread) {
expected_thread_ = thread;
invoker->AsyncInvoke(RTC_FROM_HERE, RTC_FROM_HERE, thread, FunctorC(),
&AsyncInvokeTest::IntCallback,
static_cast<AsyncInvokeTest*>(this));
invoke_started_.Set();
}
void SetExpectedThreadForIntCallback(Thread* thread) {
expected_thread_ = thread;
}
@ -436,11 +429,9 @@ class AsyncInvokeTest : public testing::Test {
enum { kWaitTimeout = 1000 };
AsyncInvokeTest()
: int_value_(0),
invoke_started_(true, false),
expected_thread_(nullptr) {}
int int_value_;
Event invoke_started_;
Thread* expected_thread_;
};
@ -455,71 +446,6 @@ TEST_F(AsyncInvokeTest, FireAndForget) {
EXPECT_TRUE_WAIT(called.get(), kWaitTimeout);
}
TEST_F(AsyncInvokeTest, WithCallback) {
AsyncInvoker invoker;
// Create and start the thread.
Thread thread;
thread.Start();
// Try calling functor.
SetExpectedThreadForIntCallback(Thread::Current());
invoker.AsyncInvoke(RTC_FROM_HERE, RTC_FROM_HERE, &thread, FunctorA(),
&AsyncInvokeTest::IntCallback,
static_cast<AsyncInvokeTest*>(this));
EXPECT_EQ_WAIT(42, int_value_, kWaitTimeout);
}
TEST_F(AsyncInvokeTest, CancelInvoker) {
// Create and start the thread.
Thread thread;
thread.Start();
// Try destroying invoker during call.
{
AsyncInvoker invoker;
invoker.AsyncInvoke(RTC_FROM_HERE, RTC_FROM_HERE, &thread, FunctorC(),
&AsyncInvokeTest::IntCallback,
static_cast<AsyncInvokeTest*>(this));
}
// With invoker gone, callback should be cancelled.
Thread::Current()->ProcessMessages(kWaitTimeout);
EXPECT_EQ(0, int_value_);
}
TEST_F(AsyncInvokeTest, CancelCallingThread) {
AsyncInvoker invoker;
{ // Create and start the thread.
Thread thread;
thread.Start();
// Try calling functor.
thread.Invoke<void>(
RTC_FROM_HERE,
Bind(&AsyncInvokeTest::AsyncInvokeIntCallback,
static_cast<AsyncInvokeTest*>(this), &invoker, Thread::Current()));
// Wait for the call to begin.
ASSERT_TRUE(invoke_started_.Wait(kWaitTimeout));
}
// Calling thread is gone. Return message shouldn't happen.
Thread::Current()->ProcessMessages(kWaitTimeout);
EXPECT_EQ(0, int_value_);
}
TEST_F(AsyncInvokeTest, KillInvokerBeforeExecute) {
Thread thread;
thread.Start();
{
AsyncInvoker invoker;
// Try calling functor.
thread.Invoke<void>(
RTC_FROM_HERE,
Bind(&AsyncInvokeTest::AsyncInvokeIntCallback,
static_cast<AsyncInvokeTest*>(this), &invoker, Thread::Current()));
// Wait for the call to begin.
ASSERT_TRUE(invoke_started_.Wait(kWaitTimeout));
}
// Invoker is destroyed. Function should not execute.
Thread::Current()->ProcessMessages(kWaitTimeout);
EXPECT_EQ(0, int_value_);
}
TEST_F(AsyncInvokeTest, KillInvokerDuringExecute) {
// Use these events to get in a state where the functor is in the middle of
// executing, and then to wait for it to finish, ensuring the "EXPECT_FALSE"
@ -599,13 +525,6 @@ class GuardedAsyncInvokeTest : public testing::Test {
EXPECT_EQ(expected_thread_, Thread::Current());
int_value_ = value;
}
void AsyncInvokeIntCallback(GuardedAsyncInvoker* invoker, Thread* thread) {
expected_thread_ = thread;
invoker->AsyncInvoke(RTC_FROM_HERE, RTC_FROM_HERE, FunctorC(),
&GuardedAsyncInvokeTest::IntCallback,
static_cast<GuardedAsyncInvokeTest*>(this));
invoke_started_.Set();
}
void SetExpectedThreadForIntCallback(Thread* thread) {
expected_thread_ = thread;
}
@ -614,11 +533,9 @@ class GuardedAsyncInvokeTest : public testing::Test {
const static int kWaitTimeout = 1000;
GuardedAsyncInvokeTest()
: int_value_(0),
invoke_started_(true, false),
expected_thread_(nullptr) {}
int int_value_;
Event invoke_started_;
Thread* expected_thread_;
};
@ -648,26 +565,6 @@ TEST_F(GuardedAsyncInvokeTest, KillThreadFireAndForget) {
EXPECT_FALSE(called.get());
}
// Test that we can call AsyncInvoke with callback after the thread died.
TEST_F(GuardedAsyncInvokeTest, KillThreadWithCallback) {
// Create and start the thread.
std::unique_ptr<Thread> thread(new Thread());
thread->Start();
std::unique_ptr<GuardedAsyncInvoker> invoker;
// Create the invoker on |thread|.
thread->Invoke<void>(RTC_FROM_HERE, CreateInvoker(&invoker));
// Kill |thread|.
thread = nullptr;
// Try calling functor.
EXPECT_FALSE(
invoker->AsyncInvoke(RTC_FROM_HERE, RTC_FROM_HERE, FunctorC(),
&GuardedAsyncInvokeTest::IntCallback,
static_cast<GuardedAsyncInvokeTest*>(this)));
// With thread gone, callback should be cancelled.
Thread::Current()->ProcessMessages(kWaitTimeout);
EXPECT_EQ(0, int_value_);
}
// The remaining tests check that GuardedAsyncInvoker behaves as AsyncInvoker
// when Thread is still alive.
TEST_F(GuardedAsyncInvokeTest, FireAndForget) {
@ -678,67 +575,6 @@ TEST_F(GuardedAsyncInvokeTest, FireAndForget) {
EXPECT_TRUE_WAIT(called.get(), kWaitTimeout);
}
TEST_F(GuardedAsyncInvokeTest, WithCallback) {
GuardedAsyncInvoker invoker;
// Try calling functor.
SetExpectedThreadForIntCallback(Thread::Current());
EXPECT_TRUE(invoker.AsyncInvoke(RTC_FROM_HERE, RTC_FROM_HERE, FunctorA(),
&GuardedAsyncInvokeTest::IntCallback,
static_cast<GuardedAsyncInvokeTest*>(this)));
EXPECT_EQ_WAIT(42, int_value_, kWaitTimeout);
}
TEST_F(GuardedAsyncInvokeTest, CancelInvoker) {
// Try destroying invoker during call.
{
GuardedAsyncInvoker invoker;
EXPECT_TRUE(
invoker.AsyncInvoke(RTC_FROM_HERE, RTC_FROM_HERE, FunctorC(),
&GuardedAsyncInvokeTest::IntCallback,
static_cast<GuardedAsyncInvokeTest*>(this)));
}
// With invoker gone, callback should be cancelled.
Thread::Current()->ProcessMessages(kWaitTimeout);
EXPECT_EQ(0, int_value_);
}
TEST_F(GuardedAsyncInvokeTest, CancelCallingThread) {
GuardedAsyncInvoker invoker;
// Try destroying calling thread during call.
{
Thread thread;
thread.Start();
// Try calling functor.
thread.Invoke<void>(RTC_FROM_HERE,
Bind(&GuardedAsyncInvokeTest::AsyncInvokeIntCallback,
static_cast<GuardedAsyncInvokeTest*>(this),
&invoker, Thread::Current()));
// Wait for the call to begin.
ASSERT_TRUE(invoke_started_.Wait(kWaitTimeout));
}
// Calling thread is gone. Return message shouldn't happen.
Thread::Current()->ProcessMessages(kWaitTimeout);
EXPECT_EQ(0, int_value_);
}
TEST_F(GuardedAsyncInvokeTest, KillInvokerBeforeExecute) {
Thread thread;
thread.Start();
{
GuardedAsyncInvoker invoker;
// Try calling functor.
thread.Invoke<void>(RTC_FROM_HERE,
Bind(&GuardedAsyncInvokeTest::AsyncInvokeIntCallback,
static_cast<GuardedAsyncInvokeTest*>(this),
&invoker, Thread::Current()));
// Wait for the call to begin.
ASSERT_TRUE(invoke_started_.Wait(kWaitTimeout));
}
// Invoker is destroyed. Function should not execute.
Thread::Current()->ProcessMessages(kWaitTimeout);
EXPECT_EQ(0, int_value_);
}
TEST_F(GuardedAsyncInvokeTest, Flush) {
GuardedAsyncInvoker invoker;
AtomicBool flag1;