libct: trim and de-mock container state unit tests - #5382
Open
kolyshkin wants to merge 1 commit into
Open
Conversation
kolyshkin
force-pushed
the
libct-test-demock
branch
from
July 29, 2026 00:03
40e58f7 to
3ecafb6
Compare
There was a problem hiding this comment.
Pull request overview
This PR simplifies libcontainer’s container state unit tests by removing mock-based and redundant coverage, and rewriting the remaining meaningful test to use a real cgroup v2 (fs2) manager operating against a temporary directory (via cgroups.TestMode).
Changes:
- Removed
mockCgroupManagerand two low-value tests (TestGetContainerPids,TestGetContainerState). - Added
newFakeCgroupManagerto create a realfs2cgroup manager backed by a temp directory. - Updated
TestGetContainerStateAfterUpdateto validate persisted state and confirm the updated memory limit is written tomemory.max.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+59
to
+61
| t.Helper() | ||
| cgroups.TestMode = true | ||
| t.Cleanup(func() { cgroups.TestMode = false }) |
kolyshkin
force-pushed
the
libct-test-demock
branch
from
August 1, 2026 04:10
3ecafb6 to
932697f
Compare
Removal of mockCgroupManager is needed so that oc/cgroups can add more methods without breaking runc compatibility. Remove the useless tests: - TestGetContainerPids merely asserted that Container.Processes returns what the mock cgroup manager was configured to return; - TestGetContainerState reimplemented the namespace type to /proc file name mapping it was meant to verify, so it could only detect drift between the two copies. Keep the useful one: - TestGetContainerStateAfterUpdate (added by commit e6e1c34). The test round-trips the container state through a real state directory and is the only unit level coverage of Set, saveState, updateState, and currentState. Rewrite it to use real fs2 cgroup manager instead of a mock. Package coverage goes from 7.4% to 7.3%. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin
force-pushed
the
libct-test-demock
branch
from
August 1, 2026 04:12
932697f to
765b657
Compare
lifubang
approved these changes
Aug 1, 2026
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.
Related to opencontainers/cgroups#61.
The removal of mockCgroupManager is needed so oc/cgroups can add more methods without breaking runc.
Remove the useless tests:
TestGetContainerPidsmerely asserted that Container.Processes returns what the mock cgroup manager was configured to return;TestGetContainerStatereimplemented the namespace type to /proc file name mapping it was meant to verify, so it could only detect drift between the two copies.Keep the useful one:
TestGetContainerStateAfterUpdate(initially added by commit e6e1c34)The test round-trips the container state through a real state directory and is the only unit level coverage of Set, saveState, updateState, and currentState. Rewrite it to use real fs2 cgroup manager instead of a mock.
Package coverage goes from 7.4% to 7.3%.