Skip to content

Commit

Permalink
Tests for forEachDeltaForwards pt3: early exit
Browse files Browse the repository at this point in the history
Summary:
# Context

 forEachDelta is a function that allows users to call a callback on each delta recorded in EdenFS Journal starting from the current delta towards a specified point.

The existing implementation has some issues, such as not being able to cancel iteration based on the current conditions(eg. too many results), and needing to reverse the results at the end for desired order.

# This Diff
This diff adds tests for  forEachDeltaForwards

This test case covers the following cases:
1) When a callback returns false, forEachDelta will stop iteration at the current point.

# Discussion

Reviewed By: jdelliot

Differential Revision: D68468618

fbshipit-source-id: c05fff1879cac0e55fd5be5109f30c42ecdea0e0
  • Loading branch information
Chris Dinh authored and facebook-github-bot committed Jan 23, 2025
1 parent fcfc300 commit 9834fef
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions eden/fs/journal/test/JournalTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,75 @@ TEST_F(JournalDeltaTest, for_each_delta_forwards_no_results) {
EXPECT_FALSE(truncated);
checkExpect();
}

/*
* Tests that when the fileChange callback returns false, iteration stops
*/
TEST_F(JournalDeltaTest, for_each_delta_forwards_early_exit_file) {
// We're using a custom expect values so the input to setupGeneric doesn't
// matter
setupGeneric(0u);

// We expect to stop when sequenceID == 7, so only the first entry is
// populated
expectedFileChangeSequences = {6};
expectedFileChangeNames = {"foo3"_relpath};
expectedFileChangeDtypes = {dtype_t::Regular};
expectedHashUpdateSequences = {};
expectedHashUpdateHashes = {};

bool truncated = journal.forEachDeltaForwards(
6u,
[&](const FileChangeJournalDelta& current) -> bool {
if (current.sequenceID == 7) {
return false;
}
fileChangeSequences.push_back(current.sequenceID);
fileChangeNames.push_back(current.path1);
fileChangeDtypes.push_back(current.type);
return true;
},
[&](const RootUpdateJournalDelta& current) -> bool {
hashUpdateSequences.push_back(current.sequenceID);
hashUpdateHashes.push_back(current.fromHash);
return true;
});
EXPECT_FALSE(truncated);
checkExpect();
}

/*
* Tests that when the hashUpdate callback returns false, iteration stops
*/
TEST_F(JournalDeltaTest, for_each_delta_forwards_early_exit_hash) {
// We're using a custom expect values so the input to setupGeneric doesn't
// matter
setupGeneric(0u);

// We expect to stop when sequenceID == 9, so only the first entry is
// populated in hashUpdate
expectedFileChangeSequences = {6, 7};
expectedFileChangeNames = {"foo3"_relpath, "foo4"_relpath};
expectedFileChangeDtypes = {dtype_t::Regular, dtype_t::Regular};
expectedHashUpdateSequences = {8};
expectedHashUpdateHashes = {hash1};

bool truncated = journal.forEachDeltaForwards(
6u,
[&](const FileChangeJournalDelta& current) -> bool {
fileChangeSequences.push_back(current.sequenceID);
fileChangeNames.push_back(current.path1);
fileChangeDtypes.push_back(current.type);
return true;
},
[&](const RootUpdateJournalDelta& current) -> bool {
if (current.sequenceID == 9) {
return false;
}
hashUpdateSequences.push_back(current.sequenceID);
hashUpdateHashes.push_back(current.fromHash);
return true;
});
EXPECT_FALSE(truncated);
checkExpect();
}

0 comments on commit 9834fef

Please sign in to comment.