summaryrefslogtreecommitdiff
path: root/common/subprocess_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'common/subprocess_unittest.cc')
-rw-r--r--common/subprocess_unittest.cc34
1 files changed, 19 insertions, 15 deletions
diff --git a/common/subprocess_unittest.cc b/common/subprocess_unittest.cc
index 8dbaa0b2..19b24f45 100644
--- a/common/subprocess_unittest.cc
+++ b/common/subprocess_unittest.cc
@@ -45,6 +45,7 @@
using base::TimeDelta;
using brillo::MessageLoop;
using std::string;
+using std::unique_ptr;
using std::vector;
namespace {
@@ -73,6 +74,7 @@ class SubprocessTest : public ::testing::Test {
brillo::BaseMessageLoop loop_{&base_loop_};
brillo::AsynchronousSignalHandler async_signal_handler_;
Subprocess subprocess_;
+ unique_ptr<base::FileDescriptorWatcher::Controller> watcher_;
};
namespace {
@@ -256,21 +258,23 @@ TEST_F(SubprocessTest, CancelTest) {
int fifo_fd = HANDLE_EINTR(open(fifo_path.c_str(), O_RDONLY));
EXPECT_GE(fifo_fd, 0);
- loop_.WatchFileDescriptor(FROM_HERE,
- fifo_fd,
- MessageLoop::WatchMode::kWatchRead,
- false,
- base::Bind(
- [](int fifo_fd, uint32_t tag) {
- char c;
- EXPECT_EQ(1,
- HANDLE_EINTR(read(fifo_fd, &c, 1)));
- EXPECT_EQ('X', c);
- LOG(INFO) << "Killing tag " << tag;
- Subprocess::Get().KillExec(tag);
- },
- fifo_fd,
- tag));
+ watcher_ = base::FileDescriptorWatcher::WatchReadable(
+ fifo_fd,
+ base::Bind(
+ [](unique_ptr<base::FileDescriptorWatcher::Controller>* watcher,
+ int fifo_fd,
+ uint32_t tag) {
+ char c;
+ EXPECT_EQ(1, HANDLE_EINTR(read(fifo_fd, &c, 1)));
+ EXPECT_EQ('X', c);
+ LOG(INFO) << "Killing tag " << tag;
+ Subprocess::Get().KillExec(tag);
+ *watcher = nullptr;
+ },
+ // watcher_ is no longer used outside the clousure.
+ base::Unretained(&watcher_),
+ fifo_fd,
+ tag));
// This test would leak a callback that runs when the child process exits
// unless we wait for it to run.