Skip to content

Commit

Permalink
Try to get the tests to run on the UI thread
Browse files Browse the repository at this point in the history
  • Loading branch information
dellis1972 committed Sep 17, 2024
1 parent 491ca7e commit d3794d7
Show file tree
Hide file tree
Showing 34 changed files with 498 additions and 22 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ jobs:
DOTNET_ROOT: ${{github.workspace}}/dotnet64
MGFXC_WINE_PATH: /home/runner/.winemonogame
CI: true
continue-on-error: true
if: runner.os == 'Linux'

- name: Test
Expand All @@ -89,14 +88,12 @@ jobs:
DOTNET_ROOT: ${{github.workspace}}/dotnet64
MGFXC_WINE_PATH: /Users/runner/.winemonogame
CI: true
continue-on-error: true
if: runner.os == 'macOS'

- name: Test
run: dotnet test Tools/MonoGame.Tools.Tests/MonoGame.Tools.Tests.csproj --blame-hang-timeout 1m -c Release
env:
CI: true
continue-on-error: true
if: runner.os == 'Windows'

- name: Expose GitHub Runtime
Expand Down Expand Up @@ -195,16 +192,17 @@ jobs:
run: dotnet test tests-tools/MonoGame.Tools.Tests.dll --blame-hang-timeout 1m
env:
CI: true
continue-on-error: true

- name: Run Tests
run: dotnet test tests-desktopgl/MonoGame.Tests.dll --blame-hang-timeout 1m --filter="TestCategory!=Audio & TestCategory!=Effects"
run: ./MonoGame.Tests --blame-hang-timeout 1m --filter="TestCategory!=Audio & TestCategory!=Effects"
env:
CI: true
continue-on-error: true
working-directory: tests-desktopgl
if: runner.os != 'Windows'

- name: Run Tests
run: dotnet test tests-windowsdx/MonoGame.Tests.dll --blame-hang-timeout 1m
run: MonoGame.Tests --blame-hang-timeout 1m
env:
CI: true
working-directory: tests-windowsdx
if: runner.os == 'Windows'
15 changes: 14 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@
"type": "coreclr",
"request": "attach",
"processId": "${input.processid}",
}
},
{
"name": "MonoGame.Tests",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build-tests",
"program": "${workspaceFolder}/Artifacts/Tests/DesktopGL/Debug/MonoGame.Tests",
"args": [
"--test=MonoGame.Tests.Graphics.SpriteBatchTest.Draw_normal"
],
"cwd": "${workspaceFolder}/Artifacts/Tests/DesktopGL/Debug/",
"console": "internalConsole",
"stopAtEntry": false
},
],
"inputs": [
{
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dotnetCoreExplorer.searchpatterns": [
"Artifacts/Tests/**/MonoGame.Tests.dll",
"Artifacts/Tests/**/MonoGame.Tools.Tests.dll"
]
}
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "build-tests",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Tests/MonoGame.Tests.DesktopGL.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
5 changes: 5 additions & 0 deletions Tests/Framework/Graphics/BlendStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
namespace MonoGame.Tests.Graphics
{
[TestFixture]
[NonParallelizable]
internal class BlendStateTest : GraphicsDeviceTestFixtureBase
{
[Test]
[RunOnUI]
public void ShouldNotBeAbleToSetNullBlendState()
{
Assert.Throws<ArgumentNullException>(() => game.GraphicsDevice.BlendState = null);
}

[Test]
[RunOnUI]
public void ShouldNotBeAbleToMutateStateObjectAfterBindingToGraphicsDevice()
{
var blendState = new BlendState();
Expand All @@ -38,6 +41,7 @@ public void ShouldNotBeAbleToMutateStateObjectAfterBindingToGraphicsDevice()
}

[Test]
[RunOnUI]
public void ShouldNotBeAbleToMutateDefaultStateObjects()
{
DoAsserts(BlendState.Additive, d => Assert.Throws<InvalidOperationException>(d));
Expand Down Expand Up @@ -83,6 +87,7 @@ private static void DoAsserts(BlendState blendState, Action<TestDelegate> assert
#if DESKTOPGL
[Ignore("Fails similarity test. Needs Investigating")]
#endif
[RunOnUI]
public void VisualTests()
{
var blends = new[]
Expand Down
6 changes: 6 additions & 0 deletions Tests/Framework/Graphics/DepthStencilStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
namespace MonoGame.Tests.Graphics
{
[TestFixture]
[NonParallelizable]
internal class DepthStencilStateTest : GraphicsDeviceTestFixtureBase
{
[Test]
[RunOnUI]
public void ShouldNotBeAbleToSetNullDepthStencilState()
{
Assert.Throws<ArgumentNullException>(() => gd.DepthStencilState = null);
}

[Test]
[RunOnUI]
public void ShouldNotBeAbleToMutateStateObjectAfterBindingToGraphicsDevice()
{
var depthStencilState = new DepthStencilState();
Expand All @@ -39,6 +42,7 @@ public void ShouldNotBeAbleToMutateStateObjectAfterBindingToGraphicsDevice()
}

[Test]
[RunOnUI]
public void ShouldNotBeAbleToMutateDefaultStateObjects()
{
DoAsserts(DepthStencilState.Default, d => Assert.Throws<InvalidOperationException>(d));
Expand Down Expand Up @@ -68,6 +72,7 @@ private static void DoAsserts(DepthStencilState depthStencilState, Action<TestDe

[TestCase(false)]
[TestCase(true)]
[RunOnUI]
public void VisualTestDepthBufferEnable(bool depthBufferEnable)
{
PrepareFrameCapture();
Expand Down Expand Up @@ -95,6 +100,7 @@ public void VisualTestDepthBufferEnable(bool depthBufferEnable)
}

[Test]
[RunOnUI]
public void VisualTestStencilBuffer()
{
PrepareFrameCapture();
Expand Down
7 changes: 7 additions & 0 deletions Tests/Framework/Graphics/EffectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
namespace MonoGame.Tests.Graphics
{
[TestFixture]
[NonParallelizable]
internal class EffectTest : GraphicsDeviceTestFixtureBase
{
[Test]
[RunOnUI]
public void EffectConstructorShouldAllowIndexAndCount()
{
byte[] mgfxo = EffectResource.BasicEffect.Bytecode;
Expand All @@ -24,6 +26,7 @@ public void EffectConstructorShouldAllowIndexAndCount()
}

[Test]
[RunOnUI]
public void EffectPassShouldSetTexture()
{
var texture = new Texture2D(game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
Expand All @@ -45,6 +48,7 @@ public void EffectPassShouldSetTexture()
}

[Test]
[RunOnUI]
public void EffectPassShouldSetTextureOnSubsequentCalls()
{
var texture = new Texture2D(game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
Expand Down Expand Up @@ -73,6 +77,7 @@ public void EffectPassShouldSetTextureOnSubsequentCalls()
}

[Test]
[RunOnUI]
public void EffectPassShouldSetTextureEvenIfNull()
{
var texture = new Texture2D(game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
Expand All @@ -94,6 +99,7 @@ public void EffectPassShouldSetTextureEvenIfNull()
}

[Test]
[RunOnUI]
public void EffectPassShouldOverrideTextureIfNotExplicitlySet()
{
var texture = new Texture2D(game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
Expand All @@ -117,6 +123,7 @@ public void EffectPassShouldOverrideTextureIfNotExplicitlySet()
#if DESKTOPGL
[Ignore("Fails under OpenGL!")]
#endif
[RunOnUI]
public void EffectParameterShouldBeSetIfSetByNameAndGetByIndex()
{
// This relies on the parameters permanently being on the same index.
Expand Down
20 changes: 20 additions & 0 deletions Tests/Framework/Graphics/GraphicsDeviceManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
namespace MonoGame.Tests.Graphics
{
[TestFixture]
[NonParallelizable]
internal class GraphicsDeviceManagerTest
{
[Test]
[RunOnUI]
public void DefaultParameterValidation()
{
var game = new Game();
Expand All @@ -37,6 +39,7 @@ public void DefaultParameterValidation()
}

[Test]
[RunOnUI]
public void InitializeEventCount()
{
var game = new TestGameBase();
Expand Down Expand Up @@ -72,6 +75,7 @@ public void InitializeEventCount()
}

[Test]
[RunOnUI]
public void DoNotModifyPresentationParametersDirectly()
{
var game = new TestGameBase();
Expand All @@ -93,6 +97,7 @@ public void DoNotModifyPresentationParametersDirectly()
}

[Test]
[RunOnUI]
public void PreparingDeviceSettings()
{
var game = new TestGameBase();
Expand Down Expand Up @@ -131,6 +136,7 @@ public void PreparingDeviceSettings()
}

[Test]
[RunOnUI]
public void PreparingDeviceSettingsEventChangeGraphicsProfile()
{
var game = new TestGameBase();
Expand Down Expand Up @@ -169,6 +175,7 @@ public void PreparingDeviceSettingsEventChangeGraphicsProfile()
}

[Test]
[RunOnUI]
public void PreparingDeviceSettingsArgsPresentationParametersAreApplied()
{
var game = new TestGameBase();
Expand Down Expand Up @@ -202,6 +209,7 @@ public void PreparingDeviceSettingsArgsPresentationParametersAreApplied()
}

[Test]
[RunOnUI]
public void PreparingDeviceSettingsArgsThrowsWhenPPSetToNull()
{
var game = new TestGameBase();
Expand All @@ -222,6 +230,7 @@ public void PreparingDeviceSettingsArgsThrowsWhenPPSetToNull()
}

[Test]
[RunOnUI]
public void ApplyChangesReturnsWhenNoSetterCalled()
{
var game = new TestGameBase();
Expand Down Expand Up @@ -252,6 +261,7 @@ public void ApplyChangesReturnsWhenNoSetterCalled()
}

[Test]
[RunOnUI]
public void ApplyChangesInvokesPreparingDeviceSettings()
{
var game = new TestGameBase();
Expand All @@ -277,6 +287,7 @@ public void ApplyChangesInvokesPreparingDeviceSettings()
}

[Test]
[RunOnUI]
public void ApplyChangesResetsDevice()
{
var game = new TestGameBase();
Expand All @@ -296,6 +307,7 @@ public void ApplyChangesResetsDevice()
}

[Test]
[RunOnUI]
public void DeviceDisposingInvokedAfterDeviceDisposed()
{
var game = new TestGameBase();
Expand Down Expand Up @@ -326,6 +338,7 @@ public void DeviceDisposingInvokedAfterDeviceDisposed()
internal class GraphicsDeviceManagerFixtureTest : GraphicsDeviceTestFixtureBase
{
[Test]
[RunOnUI]
public void ResettingDeviceTriggersResetEvents()
{
var resetCount = 0;
Expand All @@ -347,6 +360,7 @@ public void ResettingDeviceTriggersResetEvents()
}

[Test]
[RunOnUI]
public void NewDeviceDoesNotTriggerReset()
{
var resetCount = 0;
Expand All @@ -370,6 +384,7 @@ public void NewDeviceDoesNotTriggerReset()
}

[Test]
[RunOnUI]
public void ClientSizeChangedOnDeviceReset()
{
var count = 0;
Expand All @@ -396,6 +411,7 @@ public void ClientSizeChangedOnDeviceReset()
#if DESKTOPGL
[Ignore("Expected 2 but got 3. Needs Investigating")]
#endif
[RunOnUI]
public void MultiSampleCountRoundsDown()
{
gdm.PreferMultiSampling = true;
Expand All @@ -412,11 +428,13 @@ public void MultiSampleCountRoundsDown()

}

[Test]
[TestCase(false)]
[TestCase(true)]
#if DESKTOPGL
[Ignore("Expected not 1024 but got 1024. Needs Investigating")]
#endif
[RunOnUI]
public void MSAAEnabled(bool enabled)
{
gdm.PreferMultiSampling = enabled;
Expand Down Expand Up @@ -492,6 +510,7 @@ public void MSAAEnabled(bool enabled)
}

[Test]
[RunOnUI]
public void UnsupportedMultiSampleCountDoesNotThrowException()
{
gdm.PreferMultiSampling = true;
Expand All @@ -513,6 +532,7 @@ public void UnsupportedMultiSampleCountDoesNotThrowException()

#if DIRECTX
[Test]
[RunOnUI]
public void TooHighMultiSampleCountClampedToMaxSupported()
{
var maxMultiSampleCount = gd.GraphicsCapabilities.MaxMultiSampleCount;
Expand Down
Loading

0 comments on commit d3794d7

Please sign in to comment.