test: add test for test coverage#442
Open
lucasfang wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds additional unit tests to increase coverage across common utility components (Status, FileType, Arrow memory adaptor, logging, and compression factory creation paths).
Changes:
- Add explicit tests for stringification/mapping helpers (
Status::CodeAsString,FileTypeUtils::ToString). - Add tests for error/default branches (OOM paths in Arrow pool adaptor, unsupported/unknown compression codecs).
- Extend logging tests to cover severity mapping, glog file sink behavior, and custom logger registration.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/paimon/common/utils/status_test.cpp | Adds coverage for Status::CodeAsString and Abort death behavior. |
| src/paimon/common/utils/file_type_test.cpp | Adds coverage for FileTypeUtils::ToString and an additional .tmp unwrap edge case. |
| src/paimon/common/utils/arrow/mem_utils_test.cpp | Adds OOM-path coverage for Arrow pool adaptor allocation/reallocation. |
| src/paimon/common/logging/logging_test.cpp | Adds tests around severity logging, glog file output, and custom logger registration. |
| src/paimon/common/compression/block_compression_factory_test.cpp | Adds coverage for factory creation from options/type, including invalid/default branches. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+31
to
+37
| TEST(FileTypeTest, TestToString) { | ||
| ASSERT_EQ(FileTypeUtils::ToString(FileType::kMeta), "meta"); | ||
| ASSERT_EQ(FileTypeUtils::ToString(FileType::kData), "data"); | ||
| ASSERT_EQ(FileTypeUtils::ToString(FileType::kBucketIndex), "bucket_index"); | ||
| ASSERT_EQ(FileTypeUtils::ToString(FileType::kGlobalIndex), "global_index"); | ||
| ASSERT_EQ(FileTypeUtils::ToString(FileType::kFileIndex), "file_index"); | ||
| } |
Comment on lines
+106
to
+125
| // Save the global glog flags we are about to change so other tests are unaffected. | ||
| const bool prev_logtostderr = FLAGS_logtostderr; | ||
| const bool prev_timestamp_in_name = FLAGS_timestamp_in_logfile_name; | ||
| const int32_t prev_minloglevel = FLAGS_minloglevel; | ||
|
|
||
| // A unique, empty directory so the only file inside is the one glog creates for us. | ||
| fs::path log_dir = fs::temp_directory_path() / | ||
| ("paimon_glog_disk_" + std::to_string(RandomNumber(0, 1'000'000'000))); | ||
| fs::create_directories(log_dir); | ||
| const fs::path base = log_dir / "paimon_demo"; | ||
|
|
||
| FLAGS_logtostderr = false; // must be false, otherwise glog skips the file sink | ||
| FLAGS_timestamp_in_logfile_name = false; // deterministic file name (no time/pid suffix) | ||
| FLAGS_minloglevel = google::GLOG_INFO; // do not filter out INFO | ||
|
|
||
| if (!google::IsGoogleLoggingInitialized()) { | ||
| google::InitGoogleLogging("paimon-log-disk-test"); | ||
| } | ||
| // Force INFO logs to a file under our unique directory. | ||
| google::SetLogDestination(google::GLOG_INFO, base.string().c_str()); |
Comment on lines
+165
to
+179
| // Keep this test last: it installs a process-wide logger creator that cannot be | ||
| // unset, so it must not run before tests that rely on the default logger. | ||
| TEST(LoggerTest, TestRegisterCustomLoggerCreator) { | ||
| g_creator_calls.store(0); | ||
| Logger::RegisterLogger([](const std::string& /*path*/) -> std::unique_ptr<Logger> { | ||
| g_creator_calls.fetch_add(1); | ||
| return std::make_unique<GlogForwardingLogger>(); | ||
| }); | ||
|
|
||
| auto logger = Logger::GetLogger("custom_path"); | ||
| ASSERT_TRUE(logger); | ||
| // GetLogger must have gone through the registered creator branch. | ||
| ASSERT_EQ(1, g_creator_calls.load()); | ||
| ASSERT_TRUE(logger->IsLevelEnabled(PAIMON_LOG_LEVEL_INFO)); | ||
| } |
Comment on lines
+54
to
+56
| bool IsLevelEnabled(PaimonLogLevel /*level*/) const override { | ||
| return true; | ||
| } |
Comment on lines
+117
to
+129
| TEST(MemUtilsTest, TestAllocateOutOfMemory) { | ||
| uint8_t* ptr = nullptr; | ||
|
|
||
| // Underlying pool returns nullptr for a positive size. | ||
| auto null_pool = | ||
| GetArrowPool(std::make_shared<FailingMemoryPool>(FailingMemoryPool::Mode::kReturnNull)); | ||
| ASSERT_TRUE(null_pool->Allocate(16, 64, &ptr).IsOutOfMemory()); | ||
|
|
||
| // Underlying pool throws std::bad_alloc. | ||
| auto throw_pool = | ||
| GetArrowPool(std::make_shared<FailingMemoryPool>(FailingMemoryPool::Mode::kThrowBadAlloc)); | ||
| ASSERT_TRUE(throw_pool->Allocate(16, 64, &ptr).IsOutOfMemory()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Linked issue: close #xxx
Tests
API and Format
Documentation
Generative AI tooling