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