Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,40 @@ public async Task When_VisualTree_Paused_Then_ReloadCompleted_StillFires()

await UnitTestsUIContentHelper.WaitForIdle();

using (UIUpdate.Pause(HotReloadUIPhases.VisualTree))
var edited = false;
try
{
var completed = TestingUpdateHandler.WaitForReloadCompleted();
using (UIUpdate.Pause(HotReloadUIPhases.VisualTree))
{
var completed = TestingUpdateHandler.WaitForReloadCompleted();

// While the pause is held, the update is queued and the op is
// reported as Ignored ("UI update paused by UpdateFile").
await HotReloadHelper.UpdateServerFile<HR_Frame_Pages_Page1>(
"Hello", "PausedTest", ct);
// While the pause is held, the update is queued and the op is
// reported as Ignored ("UI update paused by UpdateFile").
await HotReloadHelper.UpdateServerFile<HR_Frame_Pages_Page1>(
"First page", "Paused page", ct);
edited = true;

// ReloadCompleted has not fired yet β€” it fires when the drain
// eventually applies the queued types after Dispose below.
Assert.IsFalse(completed.IsCompleted, "ReloadCompleted should not fire while VisualTree is paused.");
}
// ReloadCompleted has not fired yet β€” it fires when the drain
// eventually applies the queued types after Dispose below.
Assert.IsFalse(completed.IsCompleted, "ReloadCompleted should not fire while VisualTree is paused.");
}

// After dispose, the pending visual-tree types are drained and the
// completion callback fires with uiUpdated=true.
try
{
// After dispose, the pending visual-tree types are drained and the
// completion callback fires with uiUpdated=true.
var drained = TestingUpdateHandler.WaitForReloadCompleted();
var result = await drained.WaitAsync(ct);
Assert.IsTrue(result, "ReloadCompleted should report uiUpdated=true after pause is released and drain runs.");
}
finally
{
Comment thread
MartinZikmund marked this conversation as resolved.
Resolved
// Undo the file change so subsequent tests start from a known state.
await HotReloadHelper.UpdateServerFile<HR_Frame_Pages_Page1>(
"PausedTest", "Hello", CancellationToken.None);
// Undo the file change so subsequent tests start from a known state. The edit now also
// gets undone when the assertion inside the pause fails, and is skipped when it never
// landed β€” reverting an unmodified file trips the no-op guard and hides the real failure.
if (edited)
{
await HotReloadHelper.UpdateServerFile<HR_Frame_Pages_Page1>(
"Paused page", "First page", CancellationToken.None);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public static async Task UpdateServerFile<T>(string originalText, string replace
return;
}

EnsureOriginalTextIsPresent(message.FilePath, originalText, caller, line);

await Wait(RemoteControlClient.Instance.SendMessage(message), "send-msg");

if (Uno.HotReload.Client.UIUpdate.IsPaused(Uno.HotReload.Client.HotReloadUIPhases.VisualTree))
Expand Down Expand Up @@ -115,6 +117,8 @@ public static async Task UpdateServerFile(string filePathInProject, string origi
return;
}

EnsureOriginalTextIsPresent(message.FilePath, originalText, caller, line);

await Wait(RemoteControlClient.Instance.SendMessage(message), "send-msg");

if (Uno.HotReload.Client.UIUpdate.IsPaused(Uno.HotReload.Client.HotReloadUIPhases.VisualTree))
Expand Down Expand Up @@ -155,15 +159,22 @@ public static async Task UpdateProjectFileAndRevert(

await RemoteControlClient.Instance.WaitForConnection();

var edited = false;
try
{
await UpdateServerFile(filePathInProject, originalText, replacementText, ct, caller, line);
edited = true;

await callback();
}
finally
{
await UpdateServerFile(filePathInProject, replacementText, originalText, CancellationToken.None, caller + "<undo>", line);
// Only undo an edit that actually happened: reverting a file that was never modified
// throws from the same guard and would replace the original failure.
if (edited)
{
await UpdateServerFile(filePathInProject, replacementText, originalText, CancellationToken.None, caller + "<undo>", line);
}
}
}

Expand All @@ -186,15 +197,59 @@ public static async Task UpdateServerFileAndRevert<T>(

await RemoteControlClient.Instance.WaitForConnection();

var edited = false;
try
{
await UpdateServerFile<T>(originalText, replacementText, ct, caller, line);
edited = true;

await callback();
}
finally
{
await UpdateServerFile<T>(replacementText, originalText, CancellationToken.None, caller + "<undo>", line);
// Only undo an edit that actually happened: reverting a file that was never modified
// throws from the same guard and would replace the original failure.
if (edited)
{
await UpdateServerFile<T>(replacementText, originalText, CancellationToken.None, caller + "<undo>", line);
}
}
}

/// <summary>
/// Fails fast when <paramref name="originalText"/> is absent from the file the server is about to edit.
/// </summary>
/// <remarks>
/// The replacement is performed server-side and a search string that matches nothing is applied as a
/// silent no-op: no file change, no hot reload, and a test that then asserts against content which was
/// never updated. Checking here turns that into an explicit failure naming the file and the caller.
/// The check is skipped when the source is not readable from this process, leaving the server as the
/// authority rather than introducing a new failure mode.
/// </remarks>
private static void EnsureOriginalTextIsPresent(string filePath, string originalText, string caller, int line)
{
if (string.IsNullOrEmpty(filePath))
{
return;
}

string content;
try
{
content = File.ReadAllText(filePath);
}
catch (Exception e) when (e is IOException or UnauthorizedAccessException or NotSupportedException)
{
// Missing, locked or otherwise unreadable from this process: the server remains the
// authority, rather than an unreadable path becoming a failure mode of its own.
return;
}

if (!content.Contains(originalText, StringComparison.Ordinal))
{
throw new InvalidOperationException(
$"'{originalText}' was not found in '{filePath}' (requested by {caller}@{line}). " +
"The edit would have silently done nothing.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ public void When_GetRuntimeTargetFramework_Then_PlatformMatchesRuntimeIdentifier
: rid.StartsWith("tvos", StringComparison.OrdinalIgnoreCase) ? "tvos" // incl. tvossimulator
: rid.StartsWith("ios", StringComparison.OrdinalIgnoreCase) ? "ios" // incl. iossimulator
: rid.StartsWith("browser", StringComparison.OrdinalIgnoreCase) ? "browserwasm"
: "skia"; // win-*, linux-*, osx-*: the desktop family reports the `skia` pseudo-platform
// win-*, linux-*, osx-*, freebsd-*: the desktop family reports the `skia` pseudo-platform
: rid.StartsWith("win", StringComparison.OrdinalIgnoreCase)
|| rid.StartsWith("linux", StringComparison.OrdinalIgnoreCase)
|| rid.StartsWith("osx", StringComparison.OrdinalIgnoreCase)
|| rid.StartsWith("freebsd", StringComparison.OrdinalIgnoreCase) ? "skia"
// Anything else means the host never stamped a RID β€” RuntimeInformation then reports
// "unknown", which is no oracle at all. The CoreCLR-on-Android host does exactly that,
// and mapping it onto the desktop family made this test assert `skia` on Android.
: null;

var reported = ClientHotReloadProcessor.GetRuntimeTargetFramework(Microsoft.UI.Xaml.Application.Current.GetType().Assembly);

Expand All @@ -44,7 +52,17 @@ public void When_GetRuntimeTargetFramework_Then_PlatformMatchesRuntimeIdentifier
Assert.IsTrue(
Version.TryParse(frameworkVersion.Substring(3), out var version) && version.Major >= 9,
$"Unexpected framework version in '{reported}'.");
Assert.AreEqual(expectedPlatform, platform, $"Reported '{reported}' for runtime identifier '{rid}'.");

if (expectedPlatform is null)
{
Assert.IsFalse(
string.IsNullOrEmpty(platform),
$"Reported '{reported}' carries no platform (runtime identifier '{rid}' provides no cross-check).");
}
else
{
Assert.AreEqual(expectedPlatform, platform, $"Reported '{reported}' for runtime identifier '{rid}'.");
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ public partial class Given_HotReloadWorkspace
public async Task When_HotReloadScenario(string filters)
{
// Remove this class and this method from the filters
filters = string.Join(";", (filters?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>()).ToImmutableArray().RemoveAll(x => x == nameof(Given_HotReloadWorkspace) || x == nameof(When_HotReloadScenario)));
filters = string.Join(";", (filters?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>()).ToImmutableArray().RemoveAll(IsOuterTestFilter));
var resultFile = await RunTestApp(filters, CancellationToken.None);

// Parse the nunit XML results file and extract all failed tests
var tests = NUnitXmlParser.GetTests(resultFile);

// An empty result set means the HRApp never ran anything, which would otherwise be reported
// as success because there are no failures to collect.
Assert.IsTrue(
tests.Length > 0,
$"The hot reload test app reported no test results at all (filters: '{filters}').");

StringBuilder sb = new();

foreach (var test in tests)
Expand All @@ -82,6 +88,20 @@ public async Task When_HotReloadScenario(string filters)
}
}

/// <summary>
/// Identifies a filter entry that names the outer test rather than one of the HRApp's own tests.
/// </summary>
/// <remarks>
/// A CI retry rebuilds the filter from the published failed-tests list, which carries fully
/// qualified names. Matching only the bare identifiers let the outer name through to the HRApp,
/// which has no such test and consequently ran nothing.
/// </remarks>
private static bool IsOuterTestFilter(string filter)
=> filter == nameof(Given_HotReloadWorkspace)
|| filter == nameof(When_HotReloadScenario)
|| filter.EndsWith("." + nameof(Given_HotReloadWorkspace), StringComparison.Ordinal)
|| filter.EndsWith("." + nameof(When_HotReloadScenario), StringComparison.Ordinal);

[TestInitialize]
public async Task Initialize()
{
Expand Down
Loading