Skip to content

Commit

Permalink
add more PendingCollection tests
Browse files Browse the repository at this point in the history
Summary: As summary says. Cover a couple more PendingCollection edge cases.

Reviewed By: genevievehelsel

Differential Revision: D28296001

fbshipit-source-id: e51c46bbe541c4bc9f5fcb20aa69736f5fba3188
  • Loading branch information
chadaustin authored and facebook-github-bot committed May 8, 2021
1 parent aedc82f commit bc342ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion root/crawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void InMemoryView::crawler(
logf(DBG, "in crawler calling process_path on {}\n", full_path);

int newFlags = 0;
if (recursive || !(file && file->exists)) {
if (recursive || !file || !file->exists) {
newFlags |= W_PENDING_RECURSIVE;
}

Expand Down
42 changes: 39 additions & 3 deletions tests/PendingCollectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ class NaivePendingCollection {
const w_string& path,
std::chrono::system_clock::time_point now,
int flags) {
for (std::shared_ptr<watchman_pending_fs> p = head_; p; p = p->next) {
if (w_string_startswith(path, p->path) &&
watchman::is_path_prefix(path, p->path)) {
if (p->flags & W_PENDING_RECURSIVE) {
return;
}
}
}

for (std::shared_ptr<watchman_pending_fs> p = head_; p; p = p->next) {
if (p->path == path) {
// consolidateItem
Expand Down Expand Up @@ -185,7 +194,7 @@ class NaivePendingCollection {
std::shared_ptr<watchman_pending_fs> head_;
};

using PCTypes = ::testing::Types<NaivePendingCollection, PendingChanges>;
using PCTypes = ::testing::Types<PendingChanges, NaivePendingCollection>;

} // namespace

Expand Down Expand Up @@ -236,9 +245,36 @@ TYPED_TEST(PendingCollectionFixture, same_item_consolidates) {
}

TYPED_TEST(PendingCollectionFixture, prune_obsoleted_children) {
int flags = 0;
this->coll.add(w_string{"foo/bar"}, this->now, flags);
this->coll.add(w_string{"foo/bar"}, this->now, 0);
this->coll.add(w_string{"foo"}, this->now, W_PENDING_RECURSIVE);

auto item = this->coll.stealItems();
ASSERT_NE(nullptr, item);
EXPECT_EQ(nullptr, item->next);
EXPECT_EQ(w_string{"foo"}, item->path);
EXPECT_EQ(W_PENDING_RECURSIVE, item->flags);
}

TYPED_TEST(
PendingCollectionFixture,
recursive_parents_prevent_children_from_being_added) {
this->coll.add(w_string{"foo"}, this->now, W_PENDING_RECURSIVE);
this->coll.add(w_string{"foo/bar"}, this->now, 0);

auto item = this->coll.stealItems();
ASSERT_NE(nullptr, item);
EXPECT_EQ(nullptr, item->next);
EXPECT_EQ(w_string{"foo"}, item->path);
EXPECT_EQ(W_PENDING_RECURSIVE, item->flags);
}

TYPED_TEST(
PendingCollectionFixture,
mixed_addition_is_cleared_by_recursive_parents) {
this->coll.add(w_string{"foo/bar"}, this->now, 0);
this->coll.add(w_string{"foo/bar/baz"}, this->now, 0);
this->coll.add(w_string{"foo"}, this->now, W_PENDING_RECURSIVE);
this->coll.add(w_string{"foo/bar/baz/qux"}, this->now, 0);

auto item = this->coll.stealItems();
ASSERT_NE(nullptr, item);
Expand Down

0 comments on commit bc342ab

Please sign in to comment.