Repository navigation
Choose the right find_memleak target for each server test. - #1007
Merged
Merged
Conversation
`BSTR` values are made by `SysAllocString`, and this goes through the COM task allocator. So `mallocspy` can count them exactly. The old `working_set` target gave a false leak, because the first call in a process brings in pages that look like a leak. This change makes `check_leaks` use `find_memleak(func, target="mallocspy")`. Then `test_creation` does not need the old `limit=4096` workaround, so we remove it.
`VARIANT(MYCOLOR(...))` stores the record as a `VT_RECORD`, and its data is allocated with the COM task allocator. So `mallocspy` can count this allocation exactly. The old `working_set` target gave a false leak, because the first call in a process brings in pages that look like a leak. This change makes `VariantTest` use `find_memleak(func, target="mallocspy")`.
`from_param` creates a `SAFEARRAY` of `MYCOLOR` records. `mallocspy` counts the `SAFEARRAY` descriptor and data exactly. The old `working_set` target gave a false leak, because the first call in a process brings in pages that look like a leak. This change makes `SafeArrayTest` use `find_memleak(doit, target="mallocspy")`.
This test was skipped with "This fails with a memory leak. Figure out if false positive." The leak was a false positive from `working_set`, which measures resident pages and reports first-call page faults as leaks. `mallocspy` counts the COM task allocations of the `VARIANT`'s `SAFEARRAY` exactly, so the test can run again.
This test was skipped with "This fails with a memory leak. Figure out if false positive." The leak was a false positive from `working_set`, which measures resident pages and reports first-call page faults as leaks. `mallocspy` counts the COM task allocation of the `VARIANT`'s `SAFEARRAY` of doubles exactly, so the test can run again.
This test was skipped with "This fails with a memory leak. Figure out if false positive." The leak was a false positive from `working_set`, which measures resident pages and reports first-call page faults as leaks. `mallocspy` counts the `SAFEARRAY` of `BSTR`s and its elements exactly, so the test can run again.
This test was skipped with "This fails with a memory leak. Figure out if false positive." The leak was a false positive from `working_set`, which measures resident pages and reports first-call page faults as leaks. `mallocspy` counts the `SAFEARRAY` of longs exactly, so the test can run again.
This test was skipped with "This test takes a long time. Do we need it? Can it be rewritten?" The slowness came from `working_set`, which needs many iterations to stabilize. `mallocspy` counts the COM task allocations of the iterated `BSTR`s and `VARIANT`s exactly, so the test is deterministic and can run again.
This test was skipped with "This test takes a long time. Do we need it? Can it be rewritten?" The slowness came from `working_set`, which needs many iterations to stabilize. `mallocspy` counts the COM task allocations of the `VARIANT`s returned by `Next` exactly, so the test is deterministic and can run again.
This test was skipped with "This test takes a long time. Do we need it? Can it be rewritten?" The slowness came from `working_set`, which needs many iterations to stabilize. `mallocspy` counts the COM task allocations of the `BSTR`s and `VARIANT`s from iterating the collection twice exactly, so the test is deterministic and can run again.
…rvers. `BaseServerTest._find_memleak` now reads a `_memleak_target` class attribute instead of always using `private_usage`. The right target depends on where the server runs: - In-process servers (`TestInproc`, `TestInproc_win32com`) use `mallocspy`, which counts their COM task allocations exactly. - Out-of-process servers (`TestLocalServer`, `TestLocalServer_win32com`) use `private_usage`, because `mallocspy` cannot see allocations made in another process. This keeps the exact counting where it is possible and falls back to commit charge only where it is needed.
`TestInproc` overrode `test_eval` with a skip, because it "fails occasionally with a memory leak on INPROC". The override body was only `pass`, so it disabled the inherited `BaseServerTest.test_eval`. In-process servers now use `mallocspy`, which counts COM task allocations exactly, so the occasional false leak is gone. Removing the override lets `test_eval` run again for the in-process server.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1007 +/- ##
==========================================
+ Coverage 92.29% 92.58% +0.28%
==========================================
Files 150 150
Lines 16064 16059 -5
==========================================
+ Hits 14827 14868 +41
+ Misses 1237 1191 -46 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 #971
Summary
Now each server test picks the
find_memleaktarget that fits its server. So the leak check uses the right method for each case.Why
Before this change, every server test used the same target:
"working_set".The
"working_set"target measures the amount of memory pages in RAM right now. It is noisy.It can go up even when there is no leak. It can stay flat even when there is a leak.
So the test sometimes failed in CI for no real reason, and sometimes missed a real leak. This is the problem in #971.
There is a second problem. A local server runs in a different process.
"mallocspy"only sees memory in the current process. So"mallocspy"cannot see the server's memory in a local server test.We must measure this process's committed memory instead.
So one target cannot fit all tests. Each test needs the right tool.
This PR tries to remove false positives and false negatives by switching the method to fit the server and the method under test.
This PR is the next step after #996, #997, and #1002. #996 added
"private_usage". #997 added theIMallocSpyinterface. #1002 added the"mallocspy"target. This PR uses those targets in the server tests.What the tests check
TestInprocandTestInproc_win32comuse"mallocspy", because the server runs in this process.TestLocalServerandTestLocalServer_win32comuse"private_usage", because the server runs in another process._find_memleakstill fails the test when the target reports a leak.These tests are important because they prove each test uses the right method.
If a test uses the wrong method, it can fail for no reason, or it can miss a real leak.
Comments in the code
The place where each test sets its target has a comment. The comment says why that target is right for that test.
For example, the in-process tests say that
"mallocspy"can count the server's COM allocations exactly.The local server tests say that
"mallocspy"cannot see the other process, so we measure this process's committed memory instead.These comments help the next reader. A reader can see the reason without reading the whole issue.
Trade-offs
Pros:
"mallocspy"counts COM allocations."private_usage"), which is better than"working_set".Cons:
_memleak_targetby hand. If a new test class forgets it, the test will fail with an error."private_usage"is still noisy, because it measures the whole process.Justification
The change does not change the old behavior of
find_memleak. It only chooses a target per test. The old"working_set"target still works and is still the default.We do not make
"mallocspy"the only way. We keep"working_set"and"private_usage"too, so each test can pick the best method.Limits
This change does not make the tests fully stable. A better method may be found later. But this is the best we can do now.
It should have fewer false positives and false negatives than
"working_set".Out of Scope
find_memleak."working_set"and"private_usage"behavior."working_set"target.