trunks: Fix the timeout resulted in build fail
This would fix the test failure when the builder was too slow.
BUG=chromium:1084897
TEST=FEATURES=test P2_TEST_FILTER=TrunksDBusProxyTest.* emerge-${BOARD}
trunks
Change-Id: Ib47794818756f099608f51a75b5533414f7ce904
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2303153
Tested-by: joe Chou <yich@google.com>
Commit-Queue: joe Chou <yich@google.com>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
diff --git a/trunks/trunks_dbus_proxy.h b/trunks/trunks_dbus_proxy.h
index b5c270c..7565c68 100644
--- a/trunks/trunks_dbus_proxy.h
+++ b/trunks/trunks_dbus_proxy.h
@@ -45,6 +45,13 @@
void set_init_attempt_delay(base::TimeDelta init_attempt_delay) {
init_attempt_delay_ = init_attempt_delay;
}
+ base::PlatformThreadId origin_thread_id_for_testing() {
+ return origin_thread_id_;
+ }
+ void set_origin_thread_id_for_testing(
+ base::PlatformThreadId testing_thread_id) {
+ origin_thread_id_ = testing_thread_id;
+ }
private:
friend class TrunksDBusProxyTest;
diff --git a/trunks/trunks_dbus_proxy_test.cc b/trunks/trunks_dbus_proxy_test.cc
index 8474a43..2d93bb3 100644
--- a/trunks/trunks_dbus_proxy_test.cc
+++ b/trunks/trunks_dbus_proxy_test.cc
@@ -236,21 +236,14 @@
// Attempting to send from a wrong thread should return TRUNKS_RC_IPC_ERROR
// without sending the command.
EXPECT_TRUE(proxy_.Init());
+ // xor 1 would change the thread id without overflow.
+ base::PlatformThreadId fake_id = proxy_.origin_thread_id_for_testing() ^ 1;
+ proxy_.set_origin_thread_id_for_testing(fake_id);
set_next_response("response");
- base::Thread other_thread("trunks_dbus_proxy_test other thread");
- ASSERT_TRUE(other_thread.Start());
- base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
- base::WaitableEvent::InitialState::NOT_SIGNALED);
- auto thread_task = [](TrunksDBusProxy* proxy, base::WaitableEvent* event) {
- auto callback = [](const std::string& response) {
- EXPECT_EQ(CreateErrorResponse(TRUNKS_RC_IPC_ERROR), response);
- };
- proxy->SendCommand("command", base::Bind(callback));
- event->Signal();
+ auto callback = [](const std::string& response) {
+ EXPECT_EQ(CreateErrorResponse(TRUNKS_RC_IPC_ERROR), response);
};
- other_thread.task_runner()->PostTask(
- FROM_HERE, base::Bind(thread_task, &proxy_, &event));
- EXPECT_TRUE(event.TimedWait(base::TimeDelta::FromMilliseconds(100)));
+ proxy_.SendCommand("command", base::Bind(callback));
EXPECT_EQ("", last_command());
}
@@ -258,19 +251,12 @@
// Attempting to send from a wrong thread should return TRUNKS_RC_IPC_ERROR
// without sending the command.
EXPECT_TRUE(proxy_.Init());
+ // xor 1 would change the thread id without overflow.
+ base::PlatformThreadId fake_id = proxy_.origin_thread_id_for_testing() ^ 1;
+ proxy_.set_origin_thread_id_for_testing(fake_id);
set_next_response("response");
- base::Thread other_thread("trunks_dbus_proxy_test other thread");
- ASSERT_TRUE(other_thread.Start());
- base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
- base::WaitableEvent::InitialState::NOT_SIGNALED);
- auto thread_task = [](TrunksDBusProxy* proxy, base::WaitableEvent* event) {
- EXPECT_EQ(CreateErrorResponse(TRUNKS_RC_IPC_ERROR),
- proxy->SendCommandAndWait("command"));
- event->Signal();
- };
- other_thread.task_runner()->PostTask(
- FROM_HERE, base::Bind(thread_task, &proxy_, &event));
- EXPECT_TRUE(event.TimedWait(base::TimeDelta::FromMilliseconds(100)));
+ EXPECT_EQ(CreateErrorResponse(TRUNKS_RC_IPC_ERROR),
+ proxy_.SendCommandAndWait("command"));
EXPECT_EQ("", last_command());
}