Skip to content

Commit

Permalink
Merge pull request #2083 from unoplatform/dev/dr/runtimeTestsUpdate
Browse files Browse the repository at this point in the history
test: Update runtime-test engine
  • Loading branch information
dr1rrb authored Dec 5, 2023
2 parents d640576 + 223cf15 commit d5a18e8
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 134 deletions.
56 changes: 56 additions & 0 deletions build/ci/.azure-pipelines.RuntimeTests.Skia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
jobs:
- job: Skia_Tests
displayName: 'Runtime Tests - Skia GTK'
timeoutInMinutes: 60

pool:
vmImage: 'ubuntu-20.04'

variables:
NUGET_PACKAGES: $(build.sourcesdirectory)/.nuget

steps:
- checkout: self
clean: true

- task: UseDotNet@2
displayName: 'Use .NET'
inputs:
packageType: 'sdk'
version: '7.x'

- script: |
dotnet tool install -g uno.check
uno-check --target skiagtk --fix --non-interactive --ci
displayName: 'Run uno-check'
- script: dotnet build Uno.Extensions.RuntimeTests.Skia.Gtk.csproj -c Debug -p:UnoTargetFrameworkOverride=net7.0 -p:GeneratePackageOnBuild=false -bl:$(Build.ArtifactStagingDirectory)/skia-gtk-runtime-test-build.binlog
displayName: 'Build Runtime Tests app (GTK)'
workingDirectory: $(Build.SourcesDirectory)/src/Uno.Extensions.RuntimeTests/Uno.Extensions.RuntimeTests.Skia.Gtk

- task: PublishBuildArtifacts@1
displayName: Publish Build Logs
retryCountOnTaskFailure: 3
condition: always()
inputs:
PathtoPublish: $(build.artifactstagingdirectory)/skia-gtk-runtime-test-build.binlog
ArtifactName: skia-runtime-test-build
ArtifactType: Container

- script: xvfb-run --auto-servernum --server-args='-screen 0 1280x1024x24' dotnet Uno.Extensions.RuntimeTests.Skia.Gtk.dll
displayName: 'Run Runtime Tests (GTK)'
workingDirectory: $(Build.SourcesDirectory)/src/Uno.Extensions.RuntimeTests/Uno.Extensions.RuntimeTests.Skia.Gtk/bin/Debug/net7.0
env:
UNO_RUNTIME_TESTS_RUN_TESTS: '{}'
UNO_RUNTIME_TESTS_OUTPUT_PATH: '$(Common.TestResultsDirectory)/skia-gtk-runtime-tests-results.xml'

- task: PublishTestResults@2
displayName: 'Publish GTK Runtime Tests Results'
condition: always()
retryCountOnTaskFailure: 3
inputs:
testRunTitle: 'GTK Runtime Tests Run'
testResultsFormat: 'NUnit'
testResultsFiles: '$(Common.TestResultsDirectory)/skia-gtk-runtime-tests-results.xml'
failTaskOnFailedTests: true
1 change: 1 addition & 0 deletions build/ci/.azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ jobs:

- template: .azure-pipelines.Wasm.yml
- template: .azure-pipelines.UITests.Wasm.yml
- template: .azure-pipelines.RuntimeTests.Skia.yml
- template: .azure-pipelines.Changelog.yml

2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<PackageVersion Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="5.0.19"/>
<PackageVersion Include="Uno.UI.MSAL" Version="5.0.19" />
<PackageVersion Include="Uno.UI.Runtime.WebAssembly" Version="5.0.19" />
<PackageVersion Include="Uno.UI.RuntimeTests.Engine" Version="0.14.0-dev.54" />
<PackageVersion Include="Uno.UI.RuntimeTests.Engine" Version="0.24.0-dev.95" />
<PackageVersion Include="Uno.WinUI" Version="5.0.19" />
<PackageVersion Include="Uno.WinUI.Markup" Version="5.0.13" />
<PackageVersion Include="Uno.WinUI.MSAL" Version="5.0.19" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public async Task When_ParameterFeed_Then_SubscribedWithSameContext()
{
var vm = new BindableWhen_ParameterFeed_Then_SubscribedWithSameContext_ViewModel();

await UIHelper.WaitFor(() => vm.MyFeed != 0, default);
await TestHelper.WaitFor(() => vm.MyFeed != 0, default);

var current = vm.MyFeed;
vm.DoSomething.Execute(null);

await UIHelper.WaitFor(() => vm.Model.CommandLastParameter != -1, default);
await TestHelper.WaitFor(() => vm.Model.CommandLastParameter != -1, default);

Assert.AreEqual(1, vm.FeedInvokeCount);
Assert.AreEqual(current, vm.Model.CommandLastParameter);
Expand All @@ -64,12 +64,12 @@ public async Task When_ParameterFeed_Then_SubscribedWithSameContext_UsingUI()

await UIHelper.Load(ui, default);

await UIHelper.WaitFor(() => vm.MyFeed is not 0, default);
await TestHelper.WaitFor(() => vm.MyFeed is not 0, default);

var current = vm.MyFeed;
doSomething.Command.Execute(null);

await UIHelper.WaitFor(() => vm.Model.CommandLastParameter != -1, default);
await TestHelper.WaitFor(() => vm.Model.CommandLastParameter != -1, default);

Assert.AreEqual(1, vm.FeedInvokeCount);
Assert.AreEqual(current, vm.Model.CommandLastParameter);
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.Extensions.Reactive.UI.Tests/Given_FeedView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task When_Loading()

tcs.SetResult(42);

await UIHelper.WaitFor(() => isLoadingValues.Count > 0, CT);
await TestHelper.WaitFor(() => isLoadingValues.Count > 0, CT);
}

[TestMethod]
Expand All @@ -58,7 +58,7 @@ public async Task When_NotVisible_Then_DoesNotSubscribeToSource()

root.Visibility = Visibility.Visible;

await UIHelper.WaitFor(() => isLoaded, CT);
await TestHelper.WaitFor(() => isLoaded, CT);

isLoaded.Should().BeTrue("The FeedView should have subscribed to the source when it became visible.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ await UIHelper.WaitFor(async ct =>
var lvItems = Array.Empty<ListViewItem>();
await UIHelper.WaitFor(async ct =>
{
lvItems = UIHelper.FindChildren<ListViewItem>(lv).ToArray();
lvItems = UIHelper.GetChildren<ListViewItem>(lv).ToArray();
return lvItems.Length > 0;
}, CT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task When_SelectSingleFromView_ListView()

InputInjectorHelper.Current.Tap(items[1]);

await UIHelper.WaitFor(async ct => (await vm.Items.GetSelectedItem(ct))?.Value == 42, CT);
await TestHelper.WaitFor(async ct => (await vm.Items.GetSelectedItem(ct))?.Value == 42, CT);
}

[TestMethod]
Expand All @@ -55,7 +55,7 @@ public async Task When_SelectMultipleFromView_ListView()
InputInjectorHelper.Current.Tap(items[0]);
InputInjectorHelper.Current.Tap(items[1]);

await UIHelper.WaitFor(async ct =>
await TestHelper.WaitFor(async ct =>
{
return (await vm.Items.GetSelectedItems(ct)).SequenceEqual(new MyItem[] { new(41), new(42) });
}, CT);
Expand All @@ -72,17 +72,17 @@ public async Task When_EditSingleSelectedItem_Then_SelectionPreserved()

InputInjectorHelper.Current.Tap(items[1]);

await UIHelper.WaitFor(async ct =>
await TestHelper.WaitFor(async ct =>
{
// Selection is preserved on ...
return lv.SelectedItem is MyItem { Value: 42 } // ... the ListView ...
&& ((ISelectionInfo)lv.ItemsSource).IsSelected(1) // ... the BindableCollection ...
&& await vm.Items.GetSelectedItem(ct) is { Value: 42 }; // ... and the Feed!
}, CT);

await vm.Model.Items.Update(items => items.Replace(items[1], items[1] with { Version = 2 }), CT);
await vm.Model.Items.UpdateAsync(items => items.Replace(items[1], items[1] with { Version = 2 }), CT);

await UIHelper.WaitFor(async ct =>
await TestHelper.WaitFor(async ct =>
{
// Selection is preserved on ...
return lv.SelectedItem is MyItem { Value: 42, Version: 2 } // ... the ListView ...
Expand All @@ -99,9 +99,9 @@ await UIHelper.WaitFor(async ct =>
await UIHelper.Load(lv, CT);

var lvItems = Array.Empty<ListViewItem>();
await UIHelper.WaitFor(async ct =>
await TestHelper.WaitFor(async ct =>
{
lvItems = UIHelper.FindChildren<ListViewItem>(lv).ToArray();
lvItems = UIHelper.GetChildren<ListViewItem>(lv).ToArray();
return lvItems.Length > 0;
}, CT);

Expand Down
63 changes: 1 addition & 62 deletions src/Uno.Extensions.RuntimeTests.Core/UIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,10 @@

namespace Uno.UI.RuntimeTests;

public static class UIHelper
public static partial class UIHelper
{
public static TimeSpan DefaultTimeout => Debugger.IsAttached ? TimeSpan.FromMinutes(60) : TimeSpan.FromSeconds(1);

public static UIElement? Content
{
get => UnitTestsUIContentHelper.Content;
set => UnitTestsUIContentHelper.Content = value;
}

public static async Task Load(FrameworkElement element, CancellationToken ct)
{
Content = element;
await WaitForLoaded(element, ct);
}

public static IEnumerable<T> FindChildren<T>(DependencyObject element)
{
if (element is T t)
{
yield return t;
}

for (var i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
foreach (var child in FindChildren<T>(VisualTreeHelper.GetChild(element, i)))
{
yield return child;
}
}
}

public static async Task WaitForLoaded(FrameworkElement element, CancellationToken ct)
{
if (element.IsLoaded)
{
return;
}

var tcs = new TaskCompletionSource<object?>();
using var _ = ct.CanBeCanceled ? ct.Register(() => tcs.TrySetCanceled()) : default;
try
{
element.Loaded += OnElementLoaded;

if (!element.IsLoaded)
{
var timeout = Task.Delay(DefaultTimeout, ct);
if (await Task.WhenAny(tcs.Task, timeout) == timeout)
{
throw new TimeoutException($"Failed to load element within {DefaultTimeout}.");
}
}
}
finally
{
element.Loaded -= OnElementLoaded;
}

void OnElementLoaded(object sender, RoutedEventArgs e)
{
element.Loaded -= OnElementLoaded;
tcs.TrySetResult(default);
}
}

public static async ValueTask WaitFor(Func<bool> predicate, CancellationToken ct)
=> await WaitFor(async _ => predicate(), ct);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Application x:Class="RuntimeTests.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RuntimeTests.WPF"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
<Application
x:Class="RuntimeTests.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RuntimeTests.WPF">
<Application.Resources>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Uno.UI.Runtime.Skia.Wpf;

namespace RuntimeTests.WPF
namespace RuntimeTests.WPF;

public partial class App : Application
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public App()
{
new WpfHost(Dispatcher, () => new Uno.Extensions.RuntimeTests.App()).Run();
}
}

This file was deleted.

This file was deleted.

0 comments on commit d5a18e8

Please sign in to comment.