Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a Performance Test for FastDeploy Task #9258

Merged
merged 4 commits into from
Sep 10, 2024
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
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
Loading