Skip to content

Commit

Permalink
ChangesSinceV2 ignore tests pt1
Browse files Browse the repository at this point in the history
Summary:
# Context

We are introducing EdenFS notifications to support scalable and ergonomic file system notifications for EdenFS mounts.

# This Diff
This diff is pt1 of tests covering include/exclude functionality.

# Technical Details
This test covers the following cases
folder is excluded
nested folder is excluded
nested folder with same name as a higher level excluded folder is not excluded
folder that is not excluded is included if included folder is not on

# Discussion Points

Reviewed By: jdelliot

Differential Revision: D66845109

fbshipit-source-id: 6fe214917b2a24821b56ea26dfc5100d393fccfe
  • Loading branch information
Chris Dinh authored and facebook-github-bot committed Dec 7, 2024
1 parent 5491081 commit cc55cec
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions eden/integration/changes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys
import time
import unittest
from typing import Optional
from typing import List, Optional

from facebook.eden.ttypes import (
Added,
Expand Down Expand Up @@ -46,7 +46,7 @@ def getLargeChangeSafe(


def buildSmallChange(
changeType: SmallChangeNotification,
changeType: int,
fileType: Dtype,
path: Optional[bytes] = None,
from_path: Optional[bytes] = None,
Expand Down Expand Up @@ -129,10 +129,15 @@ def check_changes(self, changes, expected_changes) -> bool:
print(changes)
return False

def getChangesSinceV2(self, position) -> ChangesSinceV2Result:
def getChangesSinceV2(
self, position, included_roots=None, excluded_roots=None
) -> ChangesSinceV2Result:
return self.client.changesSinceV2(
ChangesSinceV2Params(
mountPoint=self.mount_path_bytes, fromPosition=position
mountPoint=self.mount_path_bytes,
fromPosition=position,
includedRoots=included_roots,
excludedRoots=excluded_roots,
)
)

Expand All @@ -153,6 +158,27 @@ def setup_test_rename_file(self) -> ChangesSinceV2Result:
def repo_rmdir(self, path) -> None:
self.rmdir(path)

def add_file_expect(
self, path, contents, mode=None, add=True
) -> List[ChangeNotification]:
self.repo_write_file(path, contents, mode, add)
return [
buildSmallChange(
SmallChangeNotification.ADDED, Dtype.REGULAR, path=path.encode()
),
buildSmallChange(
SmallChangeNotification.MODIFIED, Dtype.REGULAR, path=path.encode()
),
]

def add_folder_expect(self, path) -> List[ChangeNotification]:
self.mkdir(path)
return [
buildSmallChange(
SmallChangeNotification.ADDED, Dtype.DIR, path=path.encode()
),
]


class WindowsTestBase(ChangesTestBase):
SYNC_MAX: int = 1
Expand Down Expand Up @@ -192,6 +218,16 @@ def repo_rmdir(self, path) -> None:
super().rmdir(path)
self.syncProjFS(position)

def add_file_expect(
self, path, contents, mode=None, add=True
) -> List[ChangeNotification]:
self.repo_write_file(path, contents, mode, add)
return [
buildSmallChange(
SmallChangeNotification.ADDED, Dtype.REGULAR, path=path.encode()
),
]


if sys.platform == "win32":
testBase = WindowsTestBase
Expand All @@ -215,6 +251,30 @@ def test_wrong_mount_generation(self):
LostChangesReason.EDENFS_REMOUNTED,
)

def test_exclude_directory(self):
expected_changes = []
oldPosition = self.client.getCurrentJournalPosition(self.mount_path_bytes)
self.add_folder_expect("ignored_dir")
self.add_folder_expect("ignored_dir2/nested_ignored_dir")
expected_changes += self.add_folder_expect("want_dir")
# same name in subdir should not be ignored
expected_changes += self.add_folder_expect("want_dir/ignored_dir")
self.add_file_expect("ignored_dir/test_file", "contents", add=False)
expected_changes += self.add_file_expect(
"want_dir/test_file", "contents", add=False
)
self.add_file_expect(
"ignored_dir2/nested_ignored_dir/test_file", "contents", add=False
)
expected_changes += self.add_file_expect(
"want_dir/ignored_dir/test_file", "contents", add=False
)
changes = self.getChangesSinceV2(
oldPosition,
excluded_roots=["ignored_dir", "ignored_dir2/nested_ignored_dir"],
)
self.assertTrue(self.check_changes(changes.changes, expected_changes))

def test_modify_file(self):
self.repo_write_file("test_file", "", add=False)
position = self.client.getCurrentJournalPosition(self.mount_path_bytes)
Expand Down

0 comments on commit cc55cec

Please sign in to comment.