Example #1
0
TEST_F(FSEventsTests, test_fsevents_event_action) {
  // Assume event type is registered.
  StartEventLoop();

  // Simulate registering an event subscriber.
  auto sub = std::make_shared<TestFSEventsEventSubscriber>();
  auto status = sub->init();

  auto sc = sub->GetSubscription(real_test_path, 0);
  EventFactory::registerEventSubscriber(sub);

  sub->subscribe(&TestFSEventsEventSubscriber::Callback, sc);
  event_pub_->configure();

  CreateEvents();
  sub->WaitForEvents(kMaxEventLatency, 1);

  // Make sure the fsevents action was expected.
  ASSERT_TRUE(sub->actions_.size() > 0);
  bool has_created = false;
  bool has_unknown = false;
  {
    WriteLock lock(sub->mutex_);
    for (const auto& action : sub->actions_) {
      // Expect either a created event or attributes modified event.
      if (action == "CREATED" || action == "ATTRIBUTES_MODIFIED") {
        has_created = true;
      } else if (action == "UNKNOWN" || action == "") {
        // Allow an undetermined but existing FSevent on our target to pass.
        has_unknown = true;
      }
    }
  }
  EXPECT_TRUE(has_created || has_unknown);

  CreateEvents();
  sub->WaitForEvents(kMaxEventLatency, 2);
  bool has_updated = false;
  {
    WriteLock lock(sub->mutex_);
    // We may have triggered several updated events.
    for (const auto& action : sub->actions_) {
      if (action == "UPDATED") {
        has_updated = true;
      }
    }
  }
  EXPECT_TRUE(has_updated);

  EndEventLoop();
}
Example #2
0
TEST_F(INotifyTests, test_inotify_optimization) {
  // Assume event type is registered.
  StartEventLoop();
  fs::create_directory(real_test_dir);

  // Adding a descriptor to a directory will monitor files within.
  SubscriptionAction(real_test_dir);
  EXPECT_TRUE(event_pub_->isPathMonitored(real_test_dir_path));

  // Adding a subscription to a file within a monitored directory is fine
  // but this will NOT cause an additional INotify watch.
  SubscriptionAction(real_test_dir_path);
  EXPECT_EQ(event_pub_->numDescriptors(), 1U);
  StopEventLoop();
}
Example #3
0
TEST_F(INotifyTests, test_inotify_fire_event) {
  // Assume event type is registered.
  StartEventLoop();
  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  sub->init();

  // Create a subscriptioning context, note the added Event to the symbol
  auto sc = sub->GetSubscription(kRealTestPath, 0);
  sub->subscribe(&TestINotifyEventSubscriber::SimpleCallback, sc, nullptr);

  TriggerEvent(kRealTestPath);
  sub->WaitForEvents(kMaxEventLatency);

  // Make sure our expected event fired (aka subscription callback was called).
  EXPECT_TRUE(sub->count() > 0);
  StopEventLoop();
}
Example #4
0
TEST_F(INotifyTests, test_inotify_event_action) {
  // Assume event type is registered.
  StartEventLoop();
  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  sub->init();

  auto sc = sub->GetSubscription(kRealTestPath, 0);
  sub->subscribe(&TestINotifyEventSubscriber::Callback, sc, nullptr);

  TriggerEvent(kRealTestPath);
  sub->WaitForEvents(kMaxEventLatency, 4);

  // Make sure the inotify action was expected.
  EXPECT_EQ(sub->actions().size(), 4);
  EXPECT_EQ(sub->actions()[0], "UPDATED");
  EXPECT_EQ(sub->actions()[1], "OPENED");
  EXPECT_EQ(sub->actions()[2], "UPDATED");
  EXPECT_EQ(sub->actions()[3], "UPDATED");
  StopEventLoop();
}
Example #5
0
TEST_F(FSEventsTests, test_fsevents_fire_event) {
  // Assume event type is registered.
  StartEventLoop();

  // Simulate registering an event subscriber.
  auto sub = std::make_shared<TestFSEventsEventSubscriber>();
  auto status = sub->init();

  // Create a subscriptioning context, note the added Event to the symbol
  auto sc = sub->GetSubscription(0);
  sub->subscribe(&TestFSEventsEventSubscriber::SimpleCallback, sc, nullptr);
  CreateEvents();

  // This time wait for the callback.
  sub->WaitForEvents(kMaxEventLatency, 1);

  // Make sure our expected event fired (aka subscription callback was called).
  EXPECT_TRUE(sub->callback_count_ > 0);
  EndEventLoop();
}
Example #6
0
TEST_F(INotifyTests, test_inotify_event_action) {
  // Assume event type is registered.
  StartEventLoop();
  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  EventFactory::registerEventSubscriber(sub);

  auto sc = sub->GetSubscription(real_test_path, 0);
  sub->subscribe(&TestINotifyEventSubscriber::Callback, sc, nullptr);

  TriggerEvent(real_test_path);
  sub->WaitForEvents(kMaxEventLatency, 3);

  // Make sure the inotify action was expected.
  EXPECT_GT(sub->actions().size(), 0U);
  if (sub->actions().size() >= 2) {
    EXPECT_EQ(sub->actions()[0], "UPDATED");
    EXPECT_EQ(sub->actions()[1], "UPDATED");
  }
  StopEventLoop();
}
TEST_F(FSEventsTests, test_fsevents_event_action) {
  // Assume event type is registered.
  StartEventLoop();

  // Simulate registering an event subscriber.
  auto sub = std::make_shared<TestFSEventsEventSubscriber>();
  auto status = sub->init();

  auto sc = sub->GetSubscription(0);
  EventFactory::registerEventSubscriber(sub);
  sub->subscribe(&TestFSEventsEventSubscriber::Callback, sc, nullptr);
  CreateEvents();
  sub->WaitForEvents(kMaxEventLatency);

  // Make sure the fsevents action was expected.
  EXPECT_TRUE(sub->actions_.size() > 0);
  if (sub->actions_.size() > 1) {
    EXPECT_EQ(sub->actions_[0], "UPDATED");
  }
  EndEventLoop();
}
Example #8
0
TEST_F(INotifyTests, test_inotify_recursion) {
  StartEventLoop();

  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  sub->init();

  boost::filesystem::create_directory(kRealTestDir);
  boost::filesystem::create_directory(kRealTestSubDir);

  // Subscribe to the directory inode
  auto mc = sub->createSubscriptionContext();
  mc->path = kRealTestDir;
  mc->recursive = true;
  sub->subscribe(&TestINotifyEventSubscriber::Callback, mc, nullptr);

  // Trigger on a subdirectory's file.
  TriggerEvent(kRealTestSubDirPath);

  sub->WaitForEvents(kMaxEventLatency, 1);
  EXPECT_TRUE(sub->count() > 0);
  StopEventLoop();
}
Example #9
0
TEST_F(INotifyTests, test_inotify_directory_watch) {
  StartEventLoop();

  auto sub = std::make_shared<TestINotifyEventSubscriber>();
  EventFactory::registerEventSubscriber(sub);

  fs::create_directory(real_test_dir);
  fs::create_directory(real_test_sub_dir);

  // Subscribe to the directory inode
  auto mc = sub->createSubscriptionContext();
  mc->path = real_test_dir;
  mc->recursive = true;
  sub->subscribe(&TestINotifyEventSubscriber::Callback, mc, nullptr);

  // Trigger on a subdirectory's file.
  TriggerEvent(real_test_sub_dir_path);

  sub->WaitForEvents(kMaxEventLatency, 1);
  EXPECT_TRUE(sub->count() > 0);
  StopEventLoop();
}