Skip to content

Commit

Permalink
Cherry pick PR #2172: Fix incorrect usage of std::remove_if (#2187)
Browse files Browse the repository at this point in the history
Refer to the original PR: youtube/cobalt#2172

b/319037247

Co-authored-by: Garo Bournoutian <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and gbournou committed Jan 9, 2024
1 parent acf9983 commit 0bf9bea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion starboard/loader_app/drain_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ void Rank(const char* dir, char* app_key, size_t len) {

std::vector<std::string> filenames = FindAllWithPrefix(dir, kDrainFilePrefix);

std::remove_if(filenames.begin(), filenames.end(), IsExpired);
filenames.erase(std::remove_if(filenames.begin(), filenames.end(), IsExpired),
filenames.end());

if (filenames.empty())
return;
Expand Down
23 changes: 23 additions & 0 deletions starboard/loader_app/drain_file_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ TEST_F(DrainFileTest, SunnyDayRankCorrectlyRanksFiles) {
EXPECT_TRUE(SbFileDelete(later_and_greatest.path().c_str()));
}

// Ranking drain files should ignore expired files.
TEST_F(DrainFileTest, SunnyDayRankCorrectlyIgnoresExpired) {
const SbTime timestamp = SbTimeGetNow();

ScopedDrainFile early_and_expired(GetTempDir(), "a",
timestamp - kDrainFileMaximumAge);
ScopedDrainFile later_and_least(GetTempDir(), "c", timestamp);
ScopedDrainFile later_and_greatest(GetTempDir(), "b",
timestamp + kDrainFileAgeUnit);

std::vector<char> result(kSbFileMaxName);

EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "c"));
EXPECT_TRUE(SbFileDelete(later_and_least.path().c_str()));

EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "b"));
EXPECT_TRUE(SbFileDelete(later_and_greatest.path().c_str()));

// Even though "a" is still there Rank should find nothing since it's expired.
EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), ""));
EXPECT_TRUE(SbFileDelete(early_and_expired.path().c_str()));
}

// All files in the directory should be cleared except for drain files with an
// app key matching the provided app key.
TEST_F(DrainFileTest, SunnyDayPrepareDirectory) {
Expand Down

0 comments on commit 0bf9bea

Please sign in to comment.