From 69750eaac5f4762479a41f9f87f258e4ca7cca2b Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Mon, 3 Jul 2023 16:19:45 +0200 Subject: [PATCH] Fix the regression test checking block manager boundaries --- include/dwarfs/filesystem_v2.h | 3 +++ include/dwarfs/inode_reader_v2.h | 3 +++ src/dwarfs/filesystem_v2.cpp | 1 + src/dwarfs/inode_reader_v2.cpp | 1 + test/dwarfs.cpp | 11 ++++++----- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/dwarfs/filesystem_v2.h b/include/dwarfs/filesystem_v2.h index 7c6facd7..17701812 100644 --- a/include/dwarfs/filesystem_v2.h +++ b/include/dwarfs/filesystem_v2.h @@ -166,6 +166,8 @@ class filesystem_v2 { return impl_->set_cache_tidy_config(cfg); } + size_t num_blocks() const { return impl_->num_blocks(); } + class impl { public: virtual ~impl() = default; @@ -203,6 +205,7 @@ class filesystem_v2 { virtual std::optional> header() const = 0; virtual void set_num_workers(size_t num) = 0; virtual void set_cache_tidy_config(cache_tidy_config const& cfg) = 0; + virtual size_t num_blocks() const = 0; }; private: diff --git a/include/dwarfs/inode_reader_v2.h b/include/dwarfs/inode_reader_v2.h index 12891aaa..07a77254 100644 --- a/include/dwarfs/inode_reader_v2.h +++ b/include/dwarfs/inode_reader_v2.h @@ -75,6 +75,8 @@ class inode_reader_v2 { impl_->set_cache_tidy_config(cfg); } + size_t num_blocks() const { return impl_->num_blocks(); } + class impl { public: virtual ~impl() = default; @@ -90,6 +92,7 @@ class inode_reader_v2 { chunk_range chunks) const = 0; virtual void set_num_workers(size_t num) = 0; virtual void set_cache_tidy_config(cache_tidy_config const& cfg) = 0; + virtual size_t num_blocks() const = 0; }; private: diff --git a/src/dwarfs/filesystem_v2.cpp b/src/dwarfs/filesystem_v2.cpp index 0ee28e49..bf11a17a 100644 --- a/src/dwarfs/filesystem_v2.cpp +++ b/src/dwarfs/filesystem_v2.cpp @@ -355,6 +355,7 @@ class filesystem_ final : public filesystem_v2::impl { void set_cache_tidy_config(cache_tidy_config const& cfg) override { ir_.set_cache_tidy_config(cfg); } + size_t num_blocks() const override { return ir_.num_blocks(); } private: filesystem_info const& get_info() const; diff --git a/src/dwarfs/inode_reader_v2.cpp b/src/dwarfs/inode_reader_v2.cpp index c5ca6d5b..ef93ee05 100644 --- a/src/dwarfs/inode_reader_v2.cpp +++ b/src/dwarfs/inode_reader_v2.cpp @@ -126,6 +126,7 @@ class inode_reader_ final : public inode_reader_v2::impl { void set_cache_tidy_config(cache_tidy_config const& cfg) override { cache_.set_tidy_config(cfg); } + size_t num_blocks() const override { return cache_.block_count(); } private: folly::Expected>, int> diff --git a/test/dwarfs.cpp b/test/dwarfs.cpp index 5176b009..f51e85b3 100644 --- a/test/dwarfs.cpp +++ b/test/dwarfs.cpp @@ -636,7 +636,7 @@ TEST(block_manager, regression_block_boundary) { stream_logger lgr(logss); // TODO: mock lgr.set_policy(); - std::vector fs_sizes; + std::vector fs_blocks; for (auto size : {1023, 1024, 1025}) { auto input = std::make_shared(); @@ -646,8 +646,6 @@ TEST(block_manager, regression_block_boundary) { auto fsdata = build_dwarfs(lgr, input, "null", cfg); - fs_sizes.push_back(fsdata.size()); - auto mm = std::make_shared(fsdata); filesystem_v2 fs(lgr, mm, opts); @@ -657,10 +655,13 @@ TEST(block_manager, regression_block_boundary) { EXPECT_EQ(2, vfsbuf.files); EXPECT_EQ(size, vfsbuf.blocks); + + fs_blocks.push_back(fs.num_blocks()); } - EXPECT_TRUE(std::is_sorted(fs_sizes.begin(), fs_sizes.end())) - << folly::join(", ", fs_sizes); + std::vector const fs_blocks_expected{1, 1, 2}; + + EXPECT_EQ(fs_blocks_expected, fs_blocks); } class compression_regression : public testing::TestWithParam {};