Repository navigation
test/mgr: Add scaffolding and surface level tests to various objects within the Mgr - #71237
stzuraski898 wants to merge 15 commits into
Conversation
NitzanMordhai
left a comment
There was a problem hiding this comment.
@stzuraski898 i added some comments
a3f8d29 to
e643a1e
Compare
|
@NitzanMordhai I've pushed changes that should resolve the issues stated, going to look further into the finish function. The changes have introduced a warning, which I'm not sure should be fixed as part of this effort:
The tests build and run without issue otherwise |
e643a1e to
8fd5b60
Compare
NitzanMordhai
left a comment
There was a problem hiding this comment.
@stzuraski898, please check my new comments on your changes.
| bool needs_restart = registry->handle_mgr_map(mgr_map); | ||
| ASSERT_FALSE(needs_restart); | ||
|
|
||
| needs_restart = registry->handle_mgr_map(mgr_map); |
There was a problem hiding this comment.
Please explain. it looks like you are calling with the same mgr_map, what is the difference?
There was a problem hiding this comment.
The first call exercises the if (mgr_map.epoch == 0) { path
And the second handles the else. Both asserts may be false, but they are testing different return locations.
| } | ||
| }; | ||
|
|
||
| class MgrStandbyTestHelper : public TestMgr { |
There was a problem hiding this comment.
Can you please explain why we also have that class and StandbyPyModulesTestHelper - they look exactly the same
There was a problem hiding this comment.
There shouldn't be, will combine into one.
8fd5b60 to
b5d4a21
Compare
|
@NitzanMordhai think I've gotten to everything, I also did a second look over the setup and tests, and for an initial 'prove the setup works' state I think these are sufficient. Next after this PR will be implementing deeper test coverage for each object. |
|
jenkins test windows |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Several named test targets never instantiate or exercise the component they claim to cover.
Review effort: Balanced
Findings: 3
Open (3)
What changed in this PR
Adds reusable manager test scaffolding and initial unit tests for manager components.
Changes:
- Introduces fixtures for manager services, collectors, Python modules, and counters.
- Adds construction and public-API tests.
- Refactors CMake targets around shared object libraries.
| File | Description |
|---|---|
src/test/mgr/TestMgr.h |
Adds shared fixtures and mocks. |
src/test/mgr/test_threadmonitor.cc |
Tests ThreadMonitor construction. |
src/test/mgr/test_standbypymodules.cc |
Tests standby Python-module construction. |
src/test/mgr/test_pyosdmap.cc |
Adds OSDMap behavior tests. |
src/test/mgr/test_pymodulerunner.cc |
Tests runner dependencies. |
src/test/mgr/test_pymoduleregistry.cc |
Tests registry queries and clients. |
src/test/mgr/test_perfcounterinstance.cc |
Tests counter buffering behavior. |
src/test/mgr/test_osdperfmetriccollector.cc |
Tests OSD collector initialization. |
src/test/mgr/test_mgrstandby.cc |
Checks standby scaffolding. |
src/test/mgr/test_mgroprequest.cc |
Tests tracked request creation. |
src/test/mgr/test_mgrclient.cc |
Tests client lifecycle. |
src/test/mgr/test_mgr.cc |
Checks manager scaffolding. |
src/test/mgr/test_metriccollector.cc |
Tests collector construction. |
src/test/mgr/test_mdsperfmetriccollector.cc |
Adds MDS collector test target. |
src/test/mgr/test_daemonserver.cc |
Checks daemon-server scaffolding. |
src/test/mgr/test_daemonperfcounters.cc |
Tests empty counter initialization. |
src/test/mgr/test_daemonhealthmetriccollector.cc |
Tests collector factory behavior. |
src/test/mgr/CMakeLists.txt |
Registers and shares unit-test sources. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| TEST_F(MetricCollectorTestHelper, MDSPerfMetricCollectorBasicSetup) { | ||
| ASSERT_NE(cct, nullptr); | ||
| } |
| TEST_F(TestMgr, PyModuleRunner_PyModuleCreation) { | ||
| auto py_module = std::make_shared<PyModule>("test_module"); | ||
| ASSERT_NE(py_module, nullptr); | ||
| EXPECT_EQ(py_module->get_name(), "test_module"); |
| TEST_F(PyOSDMapTest, OSDMapInitialized) { | ||
| ASSERT_EQ(osd_map.get_epoch(), 1); | ||
| } |
NitzanMordhai
left a comment
There was a problem hiding this comment.
@stzuraski898 please see my comments
| @@ -1,7 +1,68 @@ | |||
| set(unittest_mgr_base_srcs | |||
There was a problem hiding this comment.
That is not a good way to have all those CMakeLists changes in one commit. What will happen if you need to revert 1 of the test commits? build will break
There was a problem hiding this comment.
I've moved each test entry into the individual commits.
There was a problem hiding this comment.
Better, thanks. A few things are left: all the TestMgr.h helpers are still added in the first commit, the MgrOpRequest commit adds no test (test_mgroprequest.cc is already on main, so the commit title is misleading), and the PyModuleRunner commit has no CMake change.
| target_include_directories(unittest_mgr_common_obj PRIVATE | ||
| $<TARGET_PROPERTY:RocksDB::RocksDB,INTERFACE_INCLUDE_DIRECTORIES> | ||
| $<TARGET_PROPERTY:Python3::Python,INTERFACE_INCLUDE_DIRECTORIES>) | ||
| target_compile_definitions(unittest_mgr_common_obj PRIVATE UNIT_TESTS_BUILT) |
There was a problem hiding this comment.
All those target_compile_definitions(unittest_mgr_common_obj PRIVATE UNIT_TESTS_BUILT) are redundant, you can remove them (8 places)
| ${unittest_mgr_common_with_mgr_objs} | ||
| ) | ||
| add_ceph_unittest(unittest_mgr_pyosdmap) | ||
| target_compile_definitions(unittest_mgr_pyosdmap PRIVATE UNIT_TESTS_BUILT) |
| ${unittest_mgr_common_with_mgr_objs} | ||
| ) | ||
| add_ceph_unittest(unittest_mgr_pymodulerunner) | ||
| target_compile_definitions(unittest_mgr_pymodulerunner PRIVATE UNIT_TESTS_BUILT) |
| ${unittest_mgr_common_with_mgr_objs} | ||
| ) | ||
| add_ceph_unittest(unittest_mgr_standbypymodules) | ||
| target_compile_definitions(unittest_mgr_standbypymodules PRIVATE UNIT_TESTS_BUILT) |
| ${unittest_mgr_common_with_mgr_objs} | ||
| ) | ||
| add_ceph_unittest(unittest_mgr_daemonserver) | ||
| target_compile_definitions(unittest_mgr_daemonserver PRIVATE UNIT_TESTS_BUILT) |
| ${CMAKE_SOURCE_DIR}/src/mgr/MgrStandby.cc | ||
| ) | ||
| add_ceph_unittest(unittest_mgr_mgrstandby) | ||
| target_compile_definitions(unittest_mgr_mgrstandby PRIVATE UNIT_TESTS_BUILT) |
| ${unittest_mgr_common_with_mgr_objs} | ||
| ) | ||
| add_ceph_unittest(unittest_mgr_mgr) | ||
| target_compile_definitions(unittest_mgr_mgr PRIVATE UNIT_TESTS_BUILT) |
| TEST_F(PyOSDMapTest, OSDMapInitialized) { | ||
| ASSERT_EQ(osd_map.get_epoch(), 1); | ||
| } | ||
|
|
There was a problem hiding this comment.
Please check the copilot comment here - test_pyosdmap never tested any pyosdmap, it only tests osdmap .. change the name or change the tests.
There was a problem hiding this comment.
same for test_pymodulerunner.cc
There was a problem hiding this comment.
I've updated the tests, the primary goal was to just have the scaffolding in place but now we do some surface level verification that setup was successful.
There was a problem hiding this comment.
The new test_pymodulerunner.cc never builds, because the unittest_mgr_pymodulerunner target is gone from CMakeLists.txt. Please add the target back in the PyModuleRunner commit.
b5d4a21 to
b071e59
Compare
src/test/mgr/test_perfcounterinstance.cc and its unittest target do not exist on the base branch. Cherry-pick the PerfCounterInstance scaffolding (the test file and a unittest_mgr_perfcounterinstance CMake target) from ceph/ceph PR ceph#71237 as a temporary measure until that PR merges; this should be reconciled when the PR lands. Only the PerfCounterInstance scaffolding is imported. PR ceph#71237 wires the target through OBJECT libraries; here the target links the PerfCounterInstance.cc source directly to remain self-contained on the base branch. Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: Claude Code (Opus 4.8)
Introduce src/test/mgr/test_perfcounterinstance.cc and its unittest_mgr_perfcounterinstance CMake target. This scaffolding does not exist on ceph-origin/main; it is cherry-picked from ceph#71237 as a temporary measure until that PR merges, and should be reconciled when the PR lands. Only the PerfCounterInstance test file and its target are taken; no other test files from that PR are imported. The CMake target is adapted to the base branch's conventions (compiling src/mgr/PerfCounterInstance.cc directly), mirroring the existing unittest_mgr_daemonstate target. Coordinated with #81019, which cherry-picks the same file; if both land, the scaffolding is added once. Fixes: https://tracker.ceph.com/issues/81020 Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: Claude Code (Opus 4.8)
The MgrOpRequest unit-test harness does not exist on the base branch, so the test fixture (MgrOpRequestTestHelper) and a BasicSetup smoke test are cherry-picked from the pending scaffolding in ceph/ceph PR ceph#71237, kept self-contained as a temporary measure. They should be reconciled with src/test/mgr/TestMgr.h when PR ceph#71237 lands. Adds the unittest_mgr_mgroprequest target to src/test/mgr/CMakeLists.txt, linking only the mgr object that provides MgrOpRequest. #81341 cherry-picks the same scaffolding; if both land, the scaffolding is added once. Fixes: https://tracker.ceph.com/issues/81340 Assisted-by: Claude Opus 4.8 Signed-off-by: Steven Zuraski <[email protected]>
b071e59 to
da1f798
Compare
NitzanMordhai
left a comment
There was a problem hiding this comment.
@stzuraski898 please fix the new comments, also check the CmakeLists again, we have few files that compiled more then one time, we can reduce it, also check PyFormatter, PyUtil, ServiceMap, MgrMapCache, the 5 MetricCollector files, DaemonHealthMetric*, ThreadMonitor and MgrOpRequest
| return mod; | ||
| } | ||
| }; | ||
| using PyModuleRunnerTest = PyModuleRunnerTestHelper; |
There was a problem hiding this comment.
That one is never used, do we really need it?
| ) | ||
| add_ceph_unittest(unittest_mgr_mgroprequest) | ||
| if(WITH_LTTNG) | ||
| add_dependencies(unittest_mgr_mgroprequest mgr_op_tp) |
There was a problem hiding this comment.
Please check if that add_dependencies is really needed, you have 9 of those, i think you can drop them
| set(unittest_mgr_daemonstate_srcs | ||
| ${CMAKE_SOURCE_DIR}/src/mgr/DaemonState.cc | ||
| ${CMAKE_SOURCE_DIR}/src/mgr/DaemonPerfCounters.cc | ||
| ${CMAKE_SOURCE_DIR}/src/mgr/PerfCounterInstance.cc |
There was a problem hiding this comment.
why do we need PerfCounterInstance.cc compiled 3 times? (lines 9, 26 and 166)
| @@ -1,7 +1,68 @@ | |||
| set(unittest_mgr_base_srcs | |||
| ${CMAKE_SOURCE_DIR}/src/mgr/ClusterState.cc | |||
There was a problem hiding this comment.
ClusterState.cc compiled twice..
There was a problem hiding this comment.
Each file is compiled once now, thanks. But putting ClusterState.cc and DaemonKey.cc in one object library means daemonkey, pyformatter, pyutil, daemonstate and the other small tests now link ClusterState, which they didn't on main. Separate object libraries for each would fix that.
| @@ -1,7 +1,68 @@ | |||
| set(unittest_mgr_base_srcs | |||
| ${CMAKE_SOURCE_DIR}/src/mgr/ClusterState.cc | |||
| ${CMAKE_SOURCE_DIR}/src/mgr/DaemonKey.cc | |||
There was a problem hiding this comment.
DaemonKey.cc compiled twice
da1f798 to
f765add
Compare
|
This PR has been added to wip-bharath37-testing-20261124.044935-main. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
| ASSERT_NE(cs->test_get_objecter(), nullptr); | ||
| ASSERT_EQ(mgr_map.epoch, 0); | ||
| ASSERT_GE(osd_map.get_epoch(), 0); | ||
| } |
There was a problem hiding this comment.
Could we exercise MgrStandby itself here? BasicSetup checks objects created by the fixture, so it would still pass if the MgrStandby constructor failed. If there’s no standby behavior we want to cover yet, I’d leave this target out for now
There was a problem hiding this comment.
Sure, we can do that. I dropped the MgrStandby commit. The BasicSetup 'test' was mostly aimed at proving the scaffolding works, rather than being a real test. The goal of this PR was to get scaffolding in place, to follow up with unit test coverage for individual objects in future efforts.
| ASSERT_NE(cct, nullptr); | ||
| } | ||
|
|
||
| TEST_F(ThreadMonitorTestHelper, Construction) { |
There was a problem hiding this comment.
The fixture already constructs and destroys a ThreadMonitor for each test. Could we use that instance to call start_monitoring() and stop_monitoring()? That would exercise shutdown with a worker that has actually started.
There was a problem hiding this comment.
I added three tests that use thread_monitor, StartAndStopMonitoring, RestartMonitoring, DestroyWhileMonitoring
|
|
||
| PyObject *takes_obj = PyObject_CallMethod(py_crush, "_find_takes", nullptr); | ||
| ASSERT_NE(takes_obj, nullptr); | ||
| EXPECT_TRUE(PyDict_Check(takes_obj)); |
There was a problem hiding this comment.
Could we give the map a known root and a rule, then check the IDs returned under roots and takes? Python callers look up those keys by name. With an empty map and only PyDict_Check, both wrappers could return {} or swap the key names and the test would still pass
There was a problem hiding this comment.
The test now builds two root buckets, and empty results or swapped keys would now fail, and because the two sets differ, so would swapping the two wrappers' results.
|
|
||
| registry->register_client("test_client", addrs2, true); | ||
| clients = registry->get_clients(); | ||
| ASSERT_EQ(clients.size(), 1); |
There was a problem hiding this comment.
Could we also check that test_client maps to addrs2 after the second registration? The size is one either way, so keeping the old addrs1 would pass this test too.
There was a problem hiding this comment.
The test now checks that the stored value = addrs2, and does not equal addrs1.
|
|
||
| MockMetricListener mds_listener; | ||
| MDSPerfMetricCollector mds_collector(mds_listener); | ||
| ASSERT_EQ(mds_listener.update_count, 0); |
There was a problem hiding this comment.
Could we add a first query, check that the listener gets one notification, then remove its last registration and check for a second? Both counters start at zero, so the current assertions would pass even if MetricCollector stopped calling handle_query_updated() altogether
There was a problem hiding this comment.
Yes, I've done this for both the OSD and MDS collectors. I also added a check that removing an unknown query ID returns -ENOENT and sends no notification.
| #include "TestMgr.h" | ||
| #include "mgr/DaemonServer.h" | ||
|
|
||
| TEST_F(DaemonServerTestHelper, BasicSetup) { |
There was a problem hiding this comment.
Could we use this test to exercise a DaemonServer operation, such as adding and removing a perf query? These assertions only check pointers that SetUp() just initialized, and MgrTestHelper.ConstructAndDestruct already covers construction through Mgr::server. I’d defer the separate executable if there’s no server behavior we need to check yet
There was a problem hiding this comment.
(see above about original intentions)
Sure this is doable, and I've added the tests.
|
|
||
| void SetUp() override { | ||
| TestMgr::SetUp(); | ||
| if (!main_ts) { |
There was a problem hiding this comment.
Could we pass the fixture’s save_ts to the runner? If Google Test repeats the suite and recreates its global environment, PythonEnv starts a new interpreter, but the static main_ts still points into the old one. The runner then uses that pointer during teardown. PyEval_SaveThread() already gives us the right state for each setup.
| ) | ||
|
|
||
| add_library(unittest_mgr_common_obj OBJECT ${unittest_mgr_common_srcs}) | ||
| target_include_directories(unittest_mgr_common_obj PRIVATE |
There was a problem hiding this comment.
Could we give this target the same PY_SSIZE_T_CLEAN definition as ceph-mgr? It compiles ActivePyModule.cc separately. On Python 3.10 through 3.12, the s# format used by _handle_command raises SystemError without that definition, so a command could work in the daemon and fail in the test
There was a problem hiding this comment.
I added target_compile_definitions(unittest_mgr_common_obj PRIVATE PY_SSIZE_T_CLEAN)
| target_include_directories(unittest_mgr_common_obj PRIVATE | ||
| $<TARGET_PROPERTY:RocksDB::RocksDB,INTERFACE_INCLUDE_DIRECTORIES> | ||
| $<TARGET_PROPERTY:Python3::Python,INTERFACE_INCLUDE_DIRECTORIES>) | ||
| target_link_libraries(unittest_mgr_common_obj legacy-option-headers) |
There was a problem hiding this comment.
Could we add SQLite3::SQLite3 to unittest_mgr_common_obj when WITH_LIBCEPHSQLITE is enabled? This target compiles Mgr.cc, so it needs SQLite’s include directory. Linking SQLite only to the test executables leaves sqlite3.h out of the compile command when SQLite is installed outside the
default include path
There was a problem hiding this comment.
Yes, unittest_mgr_common_obj's link to SQLite3 has been updated
|
@stzuraski898 - I encountered a merge conflict while creating the Shaman build. Could you please resolve the conflict and re-add the |
|
This PR has been removed from wip-bharath37-testing-20261124.044935-main. |
Factor shared src/mgr unit test sources into object libraries and reuse them across the test/mgr executables instead of compiling the same mgr source files repeatedly for each test binary. This keeps the existing test coverage while reducing redundant compilation in mgr unit test builds. Fixes: https://tracker.ceph.com/issues/77389 Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
9d616cf to
fe80b16
Compare
Introduce src/test/mgr/test_perfcounterinstance.cc and its unittest_mgr_perfcounterinstance CMake target. This commit is temporary scaffolding cherry-picked from ceph#71237 (branch wip-sz-77389-wideMgrScaffolding) and should be taken out once PR 71237 is merged. Only the PerfCounterInstance test file and its target are taken; no other test files from that PR are imported. The CMake target compiles src/mgr/PerfCounterInstance.cc directly, mirroring the existing unittest_mgr_daemonstate target. Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]> Assisted-by: IBM Bob
fe80b16 to
ba8c386
Compare
|
I believe all comments have been addressed in the newest push @tchaikov @NitzanMordhai |

So far, unit testing of the Mgr has been focused on writing tests for specific objects, adding scaffolding to TestMgr.h as needed. This PR introduces scaffolding needed to test objects within the Mgr so that parallel testing efforts can be undertaken, with a consistent starting point.
Each test file contains at minimum one SetUp/TearDown round trip, verifying that the object can be constructed and destroyed without crashing. PerfCounterInstance and PyModuleRegistry have deeper coverage of their public APIs (circular-buffer behaviour, client registration/replace semantics, module query methods).
These tests in these commits are meant to be a starting point to enable future testing efforts, and are by no means a complete or comprehensive testing effort.
Fixes: https://tracker.ceph.com/issues/77389
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.