Example #1
0
TEST_F(EventBaseThreadTest, self_move) {
  EventBaseThread ebt0;
  auto ebt = std::move(ebt0);

  EXPECT_NE(nullptr, ebt.getEventBase());

  Baton<> done;
  ebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
  ASSERT_TRUE(done.try_wait_for(seconds(1)));
}
Example #2
0
TEST_F(EventBaseThreadTest, example) {
  EventBaseThread ebt(true, nullptr, "monkey");

  Baton<> done;
  ebt.getEventBase()->runInEventBaseThread([&] {
    EXPECT_EQ(getCurrentThreadName().value(), "monkey");
    done.post();
  });
  ASSERT_TRUE(done.try_wait_for(seconds(1)));
}
Example #3
0
TEST_F(FilePollerTest, TestUpdateFile) {
  createFile();
  Baton<> baton;
  bool updated = false;
  FilePoller poller(milliseconds(1));
  poller.addFileToTrack(tmpFile, [&]() {
    updated = true;
    baton.post();
  });
  updateModifiedTime(tmpFile);
  ASSERT_TRUE(baton.try_wait_for(seconds(5)));
  ASSERT_TRUE(updated);
}
Example #4
0
TEST_F(FilePollerTest, TestDeleteFile) {
  Baton<> baton;
  bool updated = false;
  createFile();
  FilePoller poller(milliseconds(1));
  poller.addFileToTrack(tmpFile, [&]() {
    updated = true;
    baton.post();
  });
  PCHECK(remove(tmpFile.c_str()) == 0);
  ASSERT_FALSE(baton.try_wait_for(seconds(1)));
  ASSERT_FALSE(updated);
}
Example #5
0
TEST_F(EventBaseThreadTest, move) {
  auto ebt0 = EventBaseThread();
  auto ebt1 = std::move(ebt0);
  auto ebt2 = std::move(ebt1);

  EXPECT_EQ(nullptr, ebt0.getEventBase());
  EXPECT_EQ(nullptr, ebt1.getEventBase());
  EXPECT_NE(nullptr, ebt2.getEventBase());

  Baton<> done;
  ebt2.getEventBase()->runInEventBaseThread([&] { done.post(); });
  ASSERT_TRUE(done.try_wait_for(seconds(1)));
}
Example #6
0
TEST_F(EventBaseThreadTest, start_stop) {
  EventBaseThread ebt(false);

  for (size_t i = 0; i < 4; ++i) {
    EXPECT_EQ(nullptr, ebt.getEventBase());
    ebt.start();
    EXPECT_NE(nullptr, ebt.getEventBase());

    Baton<> done;
    ebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
    ASSERT_TRUE(done.try_wait_for(seconds(1)));

    EXPECT_NE(nullptr, ebt.getEventBase());
    ebt.stop();
    EXPECT_EQ(nullptr, ebt.getEventBase());
  }
}