[tests] Fix CGRenderingBufferProviderTest.SizeProperty_DoesNotThrow to have consistent results.#24574
Conversation
…o have consistent results. Use an autorelease pool to ensure object lifetime is consistent, and thus asserts work as expected.
There was a problem hiding this comment.
Pull request overview
Stabilizes CGRenderingBufferProviderTest.SizeProperty_DoesNotThrow by making native object lifetime more deterministic so the assertions behave consistently across runs.
Changes:
- Wraps provider creation/usage in an
NSAutoreleasePool. - Updates the expected
releaseInfocallback behavior after the pool is drained.
| using (var pool = new NSAutoreleasePool ()) { | ||
| var provider = CGRenderingBufferProvider.Create ((nint) 0x0ee1f00d, (nuint) size, | ||
| lockPointer: (info) => { | ||
| calledOnLockPointer = true; | ||
| var rv = Marshal.AllocHGlobal (size); | ||
| return rv; | ||
| }, | ||
| unlockPointer: (info, pointer) => { | ||
| calledOnUnlockPointer = true; | ||
| Marshal.FreeHGlobal (pointer); | ||
| }, | ||
| releaseInfo: (info) => { | ||
| calledOnReleaseInfo = true; | ||
| }); | ||
| Assert.That (provider, Is.Not.Null, "provider"); | ||
| Assert.That (provider.Size, Is.EqualTo ((nuint) size), "size"); |
There was a problem hiding this comment.
provider is created inside the autorelease pool but never disposed. Since CGRenderingBufferProvider inherits NativeObject, the native handle is only released deterministically when Dispose is called; otherwise releaseInfo may or may not run before the assertions (depends on GC/finalization), which can keep this test flaky. Wrap the provider in using/using var (inside the pool) so its lifetime is deterministic, and then keep the calledOnReleaseInfo assertion outside the pool (similar to BitmapContextTest.cs's CreateAdaptive_4).
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #a505d7b] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #a505d7b] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #a505d7b] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #a505d7b] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #a505d7b] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #a505d7b] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #a505d7b] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #a505d7b] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #a505d7b] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 117 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
…o have consistent results. (#24574) Use an autorelease pool to ensure object lifetime is consistent, and thus asserts work as expected.
…o have consistent results. (#24574) Use an autorelease pool to ensure object lifetime is consistent, and thus asserts work as expected.
Use an autorelease pool to ensure object lifetime is consistent, and thus asserts work as expected.