Skip to content

Leak tests suite#1021

Merged
wieslawsoltes merged 39 commits intomasterfrom
leak-tests-suite
Feb 5, 2026
Merged

Leak tests suite#1021
wieslawsoltes merged 39 commits intomasterfrom
leak-tests-suite

Conversation

@wieslawsoltes
Copy link
Owner

@wieslawsoltes wieslawsoltes commented Feb 4, 2026

Leak Tests PR Summary

PR Summary

  • Added a comprehensive headless leak-test suite for Dock.Avalonia controls and interactions, plus model-level leak tests for Dock.Model.Mvvm and Dock.Model.ReactiveUI.
  • Refactored DockControl factory/cache cleanup into a dedicated service that prunes per-layout caches and releases default locators when controls detach.
  • Hardened overlay and managed-window lifecycle cleanup paths to prevent lingering subscriptions/registrations.
  • Expanded input and drag-helper cleanup to avoid timer/subscription retention during drag scenarios.
  • Added CI workflow to execute leak tests in Release mode.
  • Fixed compiled-binding issues in HostWindow templates and updated sample markup that violated XAML text rules.

Source Changes (src/)

  • src/Dock.Avalonia/Controls/DockControl.axaml.cs
    • Moved control recycling and factory cleanup into DockControlFactoryService.
    • Added deterministic cleanup for activation tracking on de-initialize.
    • Centralized default context/host-window resolution via ResolveDefaultContext / ResolveDefaultHostWindow and released defaults when the owning control is removed.
  • src/Dock.Avalonia/Services/DockControlFactoryService.cs
    • New service that manages shared control recycling per factory and prunes per-layout caches when controls detach or layouts swap.
    • Releases DefaultContextLocator / DefaultHostWindowLocator / HostWindowLocator when the owning DockControl is removed.
  • src/Dock.Avalonia/Services/IDockControlFactoryService.cs
    • Interface for the above service.
  • src/Dock.Avalonia/Controls/ManagedWindowLayer.cs
    • Added explicit detach + registry cleanup in OnDetachedFromVisualTree to avoid retained layers and subscriptions.
  • src/Dock.Avalonia/Controls/Overlays/OverlayHost.cs
    • Attached/detached overlay collections only while visual tree attached.
    • Guarded provider-change handling while detached and marshalled provider updates onto the UI thread.
  • src/Dock.Avalonia/Internal/ItemDragHelper.cs
    • Detached auto-scroll timer handler on stop to prevent timer tick retention after drag.
  • src/Dock.Avalonia/Internal/WindowDragHelper.cs
    • Cleaned up released-event subscription and window PositionChanged hook on detach.
  • src/Dock.Controls.Recycling/ControlRecycling.cs
    • Added Remove support and unified cache key resolution (including ID-based keys).
  • src/Dock.Avalonia.Themes.Fluent/Controls/HostWindow.axaml
    • Added x:DataType to template data templates for compiled bindings.

Samples

  • samples/DockFigmaSample/Views/Documents/DesignCanvasView.axaml
    • Fixed invalid multi-line text by using Run + LineBreak and Run bindings.
  • samples/DockReactiveUIWindowRelationsSample/Views/MainView.axaml
    • Corrected binding scopes to satisfy compiled binding type checks.

Leak Test Harness

  • New tests/Dock.Avalonia.LeakTests project with a headless session harness, helper utilities, and organized test cases.
  • LeakTestHelpers provides:
    • Window lifecycle helpers (ShowWindow, CleanupWindow).
    • Input interaction simulation and dispatcher draining.
    • Pointer-driven click simulation for buttons/menu items plus input/static state scrubbing to avoid false-positive retention.
    • Context menu open/close helper that allows invoking interactions while the menu is visible.
    • Flyout open/close helper that allows invoking interactions while the flyout is visible.
    • Cleanup ordering adjusted so input state is cleared after closing windows.
    • Environment toggles: DOCK_LEAK_STRICT, DOCK_LEAK_TRACE, DOCK_LEAK_TRACE_ALL, DOCK_LEAK_INTERACTIONS.
  • LeakContext supports factory overrides; NoOpFactory keeps bindings intact while no-oping factory actions for menu/command interactions.
  • Added model-level leak tests in tests/Dock.Model.Mvvm.LeakTests and tests/Dock.Model.ReactiveUI.LeakTests.
  • CI: .github/workflows/leak-tests.yml runs leak tests in Release.

Leak Test Coverage Table

Area Covered By Notes / Not Covered
DockControl lifecycle + layout swap DockControlLayoutLeakTests, LayoutDockControlLeakTests, DockControlEventLeakTests Focused on leak/cleanup, not full docking behavior correctness.
DockControl input and pointer interactions DockControlInputLeakTests, ControlInputLeakTests, DockControlDragLeakTests, TabStripItemActionLeakTests IME-specific and OS-level input device edge cases are not covered.
Drag overlays + preview windows DockControlOverlayWindowLeakTests, DockControlDragLeakTests No validation of OS-level native window handle leaks beyond GC.
Floating windows (native/managed) DockControlFloatingLeakTests, ManagedDockWindowDocumentLeakTests, HostWindowDragLeakTests, WindowLeakTests Platform-specific window manager quirks not covered.
Pinned dock + pin items DockControlPinnedLeakTests, PinnedDockSplitterLeakTests, ToolPinItemLeakTests Multi-edge pinned dock combinations not exhaustively covered.
Overlay system and registry OverlayHostLeakTests, OverlayLayerRegistryLeakTests, OverlayServiceLeakTests, DockSelectorOverlayLeakTests, DockTargetLeakTests Custom overlay layers from external packages not exercised.
Tab strips + tab items (document/tool) DocumentTabStripLeakTests, ToolTabStripLeakTests, TabStripItemActionLeakTests Keyboard tab navigation and custom tab templates are not tested.
Theme menu items (document/tool/MDI/chrome) ThemeMenuInteractionLeakTests Uses NoOpFactory so command bindings remain intact while avoiding side effects.
Command bars DockCommandBarManagerLeakTests, LeakTestCases.Controls (DockCommandBarHost) Uses no-op commands; real command execution/state logic not tested.
Dockable control tracking DockableControlLeakTests, BindingLeakTests, ModelLayoutLeakTests Covers binding/INPC retention; does not assert behavior of custom binding frameworks.
MDI controls and managed layers MdiControlDetachLeakTests, ManagedWindowLayerLeakTests, ManagedDockWindowDocumentLeakTests Complex multi-document resize/drag scenarios not exhaustively covered.
MDI document window interactions ThemeMdiInteractionLeakTests Tool-window chrome interactions and nested sub-menu routing not fully covered.
Overlay dialog controls ThemeOverlayInteractionLeakTests Covers button clicks; no dialog hosting/service flows.
DocumentDock items source paths DocumentDockItemsSourceLeakTests Only leak detection; not full items-source behavior validation.
General control/window detach ControlDetachLeakTests, ContentControlDetachLeakTests, ControlLifecycleLeakTests, AvaloniaViewLeakTests Focus on leak cleanup; no UI behavior assertions.
Model layer leak tests (Mvvm/ReactiveUI) Dock.Model.Mvvm.LeakTests, Dock.Model.ReactiveUI.LeakTests Other model frameworks not covered here.

Known Gaps (Leak Tests)

  • No automated GC-root analysis (dotnet-dump) in test runs.
  • No platform-specific window handle leak checks or GPU/render resource validations.
  • Custom user templates, third-party integrations, and host-specific UI frameworks are not exercised.
  • Leak tests do not validate functional docking correctness; they target retention/cleanup only.

Files Added/Updated (Tests/CI)

  • New leak test projects and harness: tests/Dock.Avalonia.LeakTests/*, tests/Dock.Model.Mvvm.LeakTests/*, tests/Dock.Model.ReactiveUI.LeakTests/*.
  • Solution updated: Dock.slnx.
  • CI workflow: .github/workflows/leak-tests.yml.
  • Theme interaction tests: tests/Dock.Avalonia.LeakTests/ThemeCommandInteractionLeakTests.cs, tests/Dock.Avalonia.LeakTests/ThemeOverlayInteractionLeakTests.cs, tests/Dock.Avalonia.LeakTests/ThemeMdiInteractionLeakTests.cs.
  • Theme menu interaction tests: tests/Dock.Avalonia.LeakTests/ThemeMenuInteractionLeakTests.cs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant