diff --git a/tests/MSBuildDeviceIntegration/Tests/PerformanceTest.cs b/tests/MSBuildDeviceIntegration/Tests/PerformanceTest.cs index 6035670c25f..118fd906e8b 100644 --- a/tests/MSBuildDeviceIntegration/Tests/PerformanceTest.cs +++ b/tests/MSBuildDeviceIntegration/Tests/PerformanceTest.cs @@ -62,11 +62,12 @@ void Profile (ProjectBuilder builder, int iterations, Action act } double total = 0; - StructuredBuild build = null; + double maxEvaluationTime = 0; for (int i=0; i < iterations; i++) { action (builder); - build = ReadBinLog (builder); + var build = ReadBinLog (builder); var actual = GetDuration (build, builder); + maxEvaluationTime = Math.Max (maxEvaluationTime, GetMaxEvaluationTime (build)); TestContext.Out.WriteLine ($"run {i} took: {actual}ms"); total += actual; if (afterRun is not null) @@ -75,7 +76,7 @@ void Profile (ProjectBuilder builder, int iterations, Action act total /= iterations; TestContext.Out.WriteLine ($"expected: {expected}ms, actual: {total}ms"); if (total > expected) { - AssertSlowMachine (build, expected, total); + AssertSlowMachine (maxEvaluationTime, expected, total); Assert.Fail ($"Exceeded expected time of {expected}ms, actual {total}ms"); } } @@ -86,32 +87,37 @@ void ProfileTask (ProjectBuilder builder, string task, int iterations, Action expected) { - AssertSlowMachine (build, expected, total); + AssertSlowMachine (maxEvaluationTime, expected, total); Assert.Fail ($"Exceeded expected time of {expected}ms, actual {total}ms"); } } - void AssertSlowMachine (StructuredBuild build, int expected, double actual) + void AssertSlowMachine (double maxEvaluationTime, int expected, double actual) { - var evaluations = build.FindChildrenRecursive (); - var maxEval = evaluations.Any () ? evaluations.Max (e => e.Duration.TotalMilliseconds) : 0; - TestContext.Out.WriteLine ($"max evaluation time: {maxEval}ms (threshold: {MaxEvaluationTimeInMs}ms)"); - if (maxEval > MaxEvaluationTimeInMs) { - Assert.Inconclusive ($"Exceeded expected time of {expected}ms, actual {actual}ms, but evaluation time was {maxEval:F0}ms (threshold: {MaxEvaluationTimeInMs}ms), indicating a slow CI machine."); + TestContext.Out.WriteLine ($"max evaluation time: {maxEvaluationTime}ms (threshold: {MaxEvaluationTimeInMs}ms)"); + if (maxEvaluationTime > MaxEvaluationTimeInMs) { + Assert.Inconclusive ($"Exceeded expected time of {expected}ms, actual {actual}ms, but evaluation time was {maxEvaluationTime:F0}ms (threshold: {MaxEvaluationTimeInMs}ms), indicating a slow CI machine."); } } + double GetMaxEvaluationTime (StructuredBuild build) + { + var evaluations = build.FindChildrenRecursive (); + return evaluations.Any () ? evaluations.Max (e => e.Duration.TotalMilliseconds) : 0; + } + StructuredBuild ReadBinLog (ProjectBuilder builder) { var binlog = Path.Combine (Root, builder.ProjectDirectory, $"{Path.GetFileNameWithoutExtension (builder.BuildLogFile)}.binlog");