[chromium]MessageLoopProxyTest单元测试中的一个隐蔽问题
代码如下
MessageLoop* task_run_on = NULL; MessageLoop* task_deleted_on = NULL; int task_delete_order = -1; MessageLoop* reply_run_on = NULL; MessageLoop* reply_deleted_on = NULL; int reply_delete_order = -1; scoped_refptr task_recoder = new LoopRecorder(&task_run_on, &task_deleted_on, &task_delete_order); scoped_refptr reply_recoder = new LoopRecorder(&reply_run_on, &reply_deleted_on, &reply_delete_order); ASSERT_TRUE(task_thread_.message_loop_proxy()->PostTaskAndReply( FROM_HERE, Bind(&RecordLoop, task_recoder), Bind(&RecordLoopAndQuit, reply_recoder))); // Die if base::Bind doesn't retain a reference to the recorders. task_recoder = NULL; reply_recoder = NULL; ASSERT_FALSE(task_deleted_on); ASSERT_FALSE(reply_deleted_on); //--- 这里将是比较关键的一个问题 begin --- UnblockTaskThread(); current_loop_->Run(); //--- 这里将是比较关键的一个问题 end --- EXPECT_EQ(task_thread_.message_loop(), task_run_on); EXPECT_EQ(current_loop_.get(), task_deleted_on); EXPECT_EQ(current_loop_.get(), reply_run_on); EXPECT_EQ(current_loop_.get(), reply_deleted_on); EXPECT_LT(task_delete_order, reply_delete_order);