Skip to content

Commit

Permalink
[tests] Add a Performance Test for FastDeploy Task (#9258)
Browse files Browse the repository at this point in the history
We need to check the speed of the `<FastDeploy/>` Task to make sure
we do not regress.  This will also help us keep track of any
improvements we make. 

The timeout has been set to 20 seconds for an initial deploy on an
emulator to take into account the fact that the emulators are really
slow on CI.
  • Loading branch information
dellis1972 authored Sep 10, 2024
1 parent b1c2b33 commit 0599369
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/PerformanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,41 @@ void Profile (ProjectBuilder builder, Action<ProjectBuilder> action, [CallerMemb
}
}

void ProfileTask (ProjectBuilder builder, string task, int iterations, Action<ProjectBuilder> action, [CallerMemberName] string caller = null)
{
if (!csv_values.TryGetValue (caller, out int expected)) {
Assert.Fail ($"No timeout value found for a key of {caller}");
}
double total = 0;
for (int i=0; i < iterations; i++) {
action (builder);
var duration = GetTaskDurationFromBinLog (builder, task);
TestContext.Out.WriteLine($"run {i} took: {duration}ms");
total += duration;
}
total /= iterations;
TestContext.Out.WriteLine($"expected: {expected}ms, actual: {total}ms");
if (total > expected) {
Assert.Fail ($"Exceeded expected time of {expected}ms, actual {total}ms");
}
}

double GetTaskDurationFromBinLog (ProjectBuilder builder, string task)
{
var binlog = Path.Combine (Root, builder.ProjectDirectory, $"{Path.GetFileNameWithoutExtension (builder.BuildLogFile)}.binlog");
FileAssert.Exists (binlog);

var build = BinaryLog.ReadBuild (binlog);
var duration = build
.FindChildrenRecursive<Task> (t => t.Name == task)
.Aggregate (TimeSpan.Zero, (duration, target) => duration + target.Duration);

if (duration == TimeSpan.Zero)
throw new InvalidDataException ($"No task build duration found in {binlog}");

return duration.TotalMilliseconds;
}

double GetDurationFromBinLog (ProjectBuilder builder)
{
var binlog = Path.Combine (Root, builder.ProjectDirectory, $"{Path.GetFileNameWithoutExtension (builder.BuildLogFile)}.binlog");
Expand Down Expand Up @@ -332,5 +367,27 @@ public void Install_CSharp_Change ()
Profile (builder, b => b.Install (proj));
}
}

[Test]
[Category ("UsesDevice")]
[Retry (Retry)]
public void Install_CSharp_FromClean ()
{
AssertCommercialBuild (); // This test will fail without Fast Deployment

var proj = CreateApplicationProject ();
proj.PackageName = "com.xamarin.install_csharp_change";
proj.MainActivity = proj.DefaultMainActivity;
using (var builder = CreateBuilderWithoutLogFile ()) {
builder.BuildLogFile = "install.log";
builder.Verbosity = LoggerVerbosity.Quiet;
builder.Install (proj);
builder.AutomaticNuGetRestore = false;
ProfileTask (builder, "FastDeploy", 20, b => {
b.Uninstall (proj);
b.Install (proj);
});
}
}
}
}
2 changes: 2 additions & 0 deletions tests/msbuild-times-reference/MSBuildDeviceIntegration.csv
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ Build_JLO_Change,4500
Build_XAML_Change,3000
Install_CSharp_Change,4000
Install_XAML_Change,3750
Install_CSharp_FromClean,3000
Install_CSharp_FromClean,20000

0 comments on commit 0599369

Please sign in to comment.