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(); }
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(); }
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(); }
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(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(); }
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(); }