Flaky test: `DataGridViewRow_PaintCells_Invoke_Success` deadlock
See original GitHub issueProblem description:
Observing almost permanent test deadlocks locally and on build agents, especially after correcting test decorations in https://github.com/dotnet/winforms/pull/3064. Inspecting a memory dump of a locally hung test process I got the following:

System.Windows.Forms.Primitives.dll!Interop.User32.SendMessageW(IHandle hWnd = {System.Windows.Forms.DataGridView}, Interop.User32.WM Msg = CHANGEUISTATE, System.IntPtr wParam = 0x0000000000030001, System.IntPtr lParam = 0x0000000000000000) Line 36 C# Symbols loaded.
System.Windows.Forms.dll!System.Windows.Forms.Control.ShowFocusCues.get() Line 3710 C# Symbols loaded.
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewTextBoxCell.PaintPrivate(System.Drawing.Graphics graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds = {X = 1 Y = 2 Width = 100 Height = 100}, System.Drawing.Rectangle cellBounds = {X = 42 Y = 2 Width = 100 Height = 100}, int rowIndex = 0, System.Windows.Forms.DataGridViewElementStates cellState = Displayed, object formattedValue = "", string errorText = "", System.Windows.Forms.DataGridViewCellStyle cellStyle = {System.Windows.Forms.DataGridViewCellStyle}, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle = {System.Windows.Forms.DataGridViewAdvancedBorderStyle}, System.Windows.Forms.DataGridViewPaintParts paintParts = All, bool computeContentBounds = false, bool computeErrorIconBounds = false, bool paint = true) Line 705 C# Symbols loaded.
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewTextBoxCell.Paint(System.Drawing.Graphics graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds = {X = 1 Y = 2 Width = 100 Height = 100}, System.Drawing.Rectangle cellBounds = {X = 42 Y = 2 Width = 100 Height = 100}, int rowIndex = 0, System.Windows.Forms.DataGridViewElementStates cellState = Displayed, object value = null, object formattedValue = "", string errorText = "", System.Windows.Forms.DataGridViewCellStyle cellStyle = {System.Windows.Forms.DataGridViewCellStyle}, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle = {System.Windows.Forms.DataGridViewAdvancedBorderStyle}, System.Windows.Forms.DataGridViewPaintParts paintParts = All) Line 606 C# Symbols loaded.
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewCell.PaintWork(System.Drawing.Graphics graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds = {X = 1 Y = 2 Width = 100 Height = 100}, System.Drawing.Rectangle cellBounds = {X = 42 Y = 2 Width = 100 Height = 100}, int rowIndex = 0, System.Windows.Forms.DataGridViewElementStates cellState = Displayed, System.Windows.Forms.DataGridViewCellStyle cellStyle = {System.Windows.Forms.DataGridViewCellStyle}, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle = {System.Windows.Forms.DataGridViewAdvancedBorderStyle}, System.Windows.Forms.DataGridViewPaintParts paintParts = All) Line 4287 C# Symbols loaded.
System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRow.PaintCells(System.Drawing.Graphics graphics = {System.Drawing.Graphics}, System.Drawing.Rectangle clipBounds = {X = 1 Y = 2 Width = 100 Height = 100}, System.Drawing.Rectangle rowBounds = {X = 1 Y = 2 Width = 100 Height = 100}, int rowIndex = 0, System.Windows.Forms.DataGridViewElementStates rowState = Displayed, bool isFirstDisplayedRow = true, bool isLastVisibleRow = false, System.Windows.Forms.DataGridViewPaintParts paintParts = All) Line 1617 C# Symbols loaded.
> System.Windows.Forms.Tests.dll!System.Windows.Forms.Tests.DataGridViewRowTests.DataGridViewRow_PaintCells_Invoke_Success(System.Windows.Forms.DataGridViewRow row = {System.Windows.Forms.DataGridViewRow}, System.Drawing.Rectangle clipBounds = {X = 1 Y = 2 Width = 100 Height = 100}, System.Drawing.Rectangle rowBounds = {X = 1 Y = 2 Width = 100 Height = 100}, int rowIndex = 0, System.Windows.Forms.DataGridViewElementStates rowState = Displayed, bool isFirstDisplayedRow = true, bool isLastVisibleRow = false, System.Windows.Forms.DataGridViewPaintParts paintParts = All) Line 3263 C# Symbols loaded.
There doesn’t appear any other threads with code from System.Windows.Forms, so it looks like this code deadlocks on itself.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

So if I understand correctly, an
[StaTheory]test has a data-generating attribute whose method is running but not on the same STA thread that the test runs on? I’d never considered that requirement but it makes sense to fix this. I don’t know whether xunit even gives the discovery attribute power to execute the data generating attribute. If so, I can fix this.Even if you fork my project and/or use a git submodule, etc., I’d love to keep the code as similar between our codebases as possible. This is an example of good stuff you’re finding that our customers who want to test WinForms will likely also hit.
Thread IDs are consistent now, so as far as I can tell it works. Test also doesn’t hang.