Skip to content

Commit ea06b62

Browse files
authored
fix: Fix another round of avalonia flaky tests (#2178)
1 parent 84ec7cb commit ea06b62

4 files changed

Lines changed: 33 additions & 23 deletions

File tree

tests/Spice86.Tests/UI/BreakpointUiTestBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ protected static void ShowWindowAndWait(Window window) {
135135
ProcessUiEvents();
136136
}
137137

138+
/// <summary>
139+
/// Closes a window and processes any deferred UI events triggered by the close
140+
/// (e.g., window state saving) before the test context is torn down.
141+
/// </summary>
142+
protected static void CloseWindowAndWait(Window window) {
143+
window.Close();
144+
ProcessUiEvents();
145+
}
146+
138147
/// <summary>
139148
/// Selects a breakpoint type tab by name and processes UI events.
140149
/// </summary>

tests/Spice86.Tests/UI/BreakpointsViewUiTests.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void BreakpointsView_CanCreateExecutionBreakpoint() {
4444
viewModel.IsExecutionBreakpointSelected.Should().BeTrue();
4545

4646
// Cleanup
47-
window.Close();
47+
CloseWindowAndWait(window);
4848
}
4949

5050
/// <summary>
@@ -75,7 +75,7 @@ public void BreakpointsView_CanCreateExecutionBreakpointWithCondition() {
7575
viewModel.CreatingBreakpoint.Should().BeFalse();
7676

7777
// Cleanup
78-
window.Close();
78+
CloseWindowAndWait(window);
7979
}
8080

8181
/// <summary>
@@ -104,7 +104,7 @@ public void BreakpointsView_InvalidConditionExpression_ShowsError() {
104104
}
105105

106106
// Cleanup
107-
window.Close();
107+
CloseWindowAndWait(window);
108108
}
109109

110110
/// <summary>
@@ -130,7 +130,7 @@ public void BreakpointsView_CancelCreation_ClearsCreatingState() {
130130
viewModel.CreatingBreakpoint.Should().BeFalse();
131131

132132
// Cleanup
133-
window.Close();
133+
CloseWindowAndWait(window);
134134
}
135135

136136
/// <summary>
@@ -147,7 +147,7 @@ public void BreakpointsView_ShowsBreakpointTypeTabs() {
147147
viewModel.BreakpointTabs.Should().NotBeEmpty();
148148

149149
// Cleanup
150-
window.Close();
150+
CloseWindowAndWait(window);
151151
}
152152

153153
/// <summary>
@@ -180,7 +180,7 @@ public void BreakpointsView_AcceptsComparisonOperatorConditions() {
180180
}
181181

182182
// Cleanup
183-
window.Close();
183+
CloseWindowAndWait(window);
184184
}
185185

186186
/// <summary>
@@ -213,7 +213,7 @@ public void BreakpointsView_AcceptsLogicalOperatorConditions() {
213213
}
214214

215215
// Cleanup
216-
window.Close();
216+
CloseWindowAndWait(window);
217217
}
218218

219219
/// <summary>
@@ -241,7 +241,7 @@ public void BreakpointsView_CanCreateMemoryBreakpoint() {
241241
}
242242

243243
// Cleanup
244-
window.Close();
244+
CloseWindowAndWait(window);
245245
}
246246

247247
/// <summary>
@@ -276,7 +276,7 @@ public void BreakpointsView_CanCreateCyclesBreakpoint() {
276276
}
277277

278278
// Cleanup
279-
window.Close();
279+
CloseWindowAndWait(window);
280280
}
281281

282282
/// <summary>
@@ -311,7 +311,7 @@ public void BreakpointsView_CanCreateInterruptBreakpoint() {
311311
}
312312

313313
// Cleanup
314-
window.Close();
314+
CloseWindowAndWait(window);
315315
}
316316

317317
/// <summary>
@@ -346,7 +346,7 @@ public void BreakpointsView_CanCreateIoPortBreakpoint() {
346346
}
347347

348348
// Cleanup
349-
window.Close();
349+
CloseWindowAndWait(window);
350350
}
351351

352352
/// <summary>
@@ -379,7 +379,7 @@ public void BreakpointsView_AcceptsBitwiseOperatorConditions() {
379379
}
380380

381381
// Cleanup
382-
window.Close();
382+
CloseWindowAndWait(window);
383383
}
384384

385385
/// <summary>
@@ -412,7 +412,7 @@ public void BreakpointsView_AcceptsArithmeticOperatorConditions() {
412412
}
413413

414414
// Cleanup
415-
window.Close();
415+
CloseWindowAndWait(window);
416416
}
417417

418418
/// <summary>
@@ -436,7 +436,7 @@ public void BreakpointsView_CanCreateInterruptBreakpointWithCondition() {
436436
viewModel.Breakpoints.Should().ContainSingle(bp =>
437437
bp.Type == BreakPointType.CPU_INTERRUPT && bp.ConditionExpression == "ah == 0x09");
438438

439-
window.Close();
439+
CloseWindowAndWait(window);
440440
}
441441

442442
/// <summary>
@@ -461,7 +461,7 @@ public void BreakpointsView_InterruptBreakpoint_InvalidCondition_KeepsDialogOpen
461461
viewModel.Breakpoints.Count.Should().Be(initialCount);
462462
viewModel.CreatingBreakpoint.Should().BeTrue();
463463

464-
window.Close();
464+
CloseWindowAndWait(window);
465465
}
466466

467467
/// <summary>
@@ -485,7 +485,7 @@ public void BreakpointsView_CanCreateIoPortBreakpointWithCondition() {
485485
viewModel.Breakpoints.Should().ContainSingle(bp =>
486486
bp.Type == BreakPointType.IO_ACCESS && bp.ConditionExpression == "al == 0x01");
487487

488-
window.Close();
488+
CloseWindowAndWait(window);
489489
}
490490

491491
/// <summary>
@@ -508,7 +508,7 @@ public void BreakpointsView_InterruptBreakpoint_OutOfRange_BlocksConfirmation()
508508
ProcessUiEvents();
509509
viewModel.ConfirmBreakpointCreationCommand.CanExecute(null).Should().BeTrue();
510510

511-
window.Close();
511+
CloseWindowAndWait(window);
512512
}
513513

514514
/// <summary>
@@ -531,7 +531,7 @@ public void BreakpointsView_IoPortBreakpoint_OutOfRange_BlocksConfirmation() {
531531
ProcessUiEvents();
532532
viewModel.ConfirmBreakpointCreationCommand.CanExecute(null).Should().BeTrue();
533533

534-
window.Close();
534+
CloseWindowAndWait(window);
535535
}
536536

537537
/// <summary>
@@ -565,7 +565,7 @@ public void BreakpointsView_InterruptBreakpoint_Wildcard_CreatesAndRoundTrips()
565565
// Assert: edit restores "*" instead of casting -1 to 0xFFFFFFFF
566566
viewModel.InterruptNumber.Should().Be("*");
567567

568-
window.Close();
568+
CloseWindowAndWait(window);
569569
}
570570

571571
/// <summary>
@@ -597,7 +597,7 @@ public void BreakpointsView_IoPortBreakpoint_Wildcard_CreatesAndRoundTrips() {
597597
// Assert: edit restores "*" instead of casting -1 to 0xFFFFFFFF
598598
viewModel.IoPortNumber.Should().Be("*");
599599

600-
window.Close();
600+
CloseWindowAndWait(window);
601601
}
602602

603603
/// <summary>
@@ -619,6 +619,6 @@ public void BreakpointsView_BeginCreateBreakpoint_ClearsInterruptAndIoConditions
619619
viewModel.InterruptConditionExpression.Should().BeNull();
620620
viewModel.IoPortConditionExpression.Should().BeNull();
621621

622-
window.Close();
622+
CloseWindowAndWait(window);
623623
}
624624
}

tests/Spice86.Tests/UI/HeadlessInfrastructureTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void TestHeadlessWindowCanBeShown() {
3737

3838
// Cleanup
3939
window.Close();
40+
Avalonia.Threading.Dispatcher.UIThread.RunJobs();
4041
}
4142

4243
/// <summary>

tests/Spice86.Tests/UI/MemoryViewUiTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task FirstOccurrence_Reinvoked_ReappliesSelectionOnFoundAddress() {
4343
harness.HexEditor.Selection.Range.Start.ByteIndex.Should().Be(expectedByteIndex);
4444

4545
// Cleanup
46-
harness.Window.Close();
46+
CloseWindowAndWait(harness.Window);
4747
}
4848

4949
[AvaloniaFact]
@@ -71,6 +71,6 @@ public async Task FirstOccurrence_WhenFoundAddressIsOutsideCurrentWindow_Reframe
7171
harness.HexEditor.Selection.Range.Start.ByteIndex.Should().Be(0UL);
7272

7373
// Cleanup
74-
harness.Window.Close();
74+
CloseWindowAndWait(harness.Window);
7575
}
7676
}

0 commit comments

Comments
 (0)