From 8eedf13a82a5e209bd5860f654bf0132b49c0be1 Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Thu, 25 Oct 2012 21:55:06 -0700 Subject: [PATCH] Fix unit test failure caused by delaying deleting obsolete files. Summary: A previous commit 4c107587ed47af84633f8c61f65516a504d6cd98 introduced the idea that some version updates might not delete obsolete files. This means that if a unit test blindly counts the number of files in the db directory it might not represent the true state of the database. Use GetLiveFiles() insteads to count the number of live files in the database. Test Plan: make check Reviewers: heyongqiang, MarkCallaghan Reviewed By: MarkCallaghan Differential Revision: https://reviews.facebook.net/D6207 --- db/db_test.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/db/db_test.cc b/db/db_test.cc index 03ca9a796..daea3aaaf 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -385,6 +385,13 @@ class DBTest { return static_cast(files.size()); } + int CountLiveFiles() { + std::vector files; + uint64_t manifest_file_size; + db_->GetLiveFiles(files, &manifest_file_size); + return files.size(); + } + uint64_t Size(const Slice& start, const Slice& limit) { Range r(start, limit); uint64_t size; @@ -1631,12 +1638,12 @@ TEST(DBTest, NonWritableFileSystem) TEST(DBTest, FilesDeletedAfterCompaction) { ASSERT_OK(Put("foo", "v2")); Compact("a", "z"); - const int num_files = CountFiles(); + const int num_files = CountLiveFiles(); for (int i = 0; i < 10; i++) { ASSERT_OK(Put("foo", "v2")); Compact("a", "z"); } - ASSERT_EQ(CountFiles(), num_files); + ASSERT_EQ(CountLiveFiles(), num_files); } TEST(DBTest, BloomFilter) {