Skip to content

Commit 2190224

Browse files
Copilotpascalberger
andcommitted
Add comprehensive performance testing and validation for parallel processing
Co-authored-by: pascalberger <2190718+pascalberger@users.noreply.github.com>
1 parent 6065f24 commit 2190224

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace Cake.Issues.Testing;
2+
3+
using System.Collections.Generic;
4+
using System.Threading;
5+
using Cake.Core.Diagnostics;
6+
7+
/// <summary>
8+
/// Implementation of a <see cref="BaseIssueProvider"/> that simulates slow processing for performance testing.
9+
/// </summary>
10+
public class FakeSlowIssueProvider : BaseIssueProvider
11+
{
12+
private readonly List<IIssue> issues = [];
13+
private readonly int delayMs;
14+
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="FakeSlowIssueProvider"/> class.
17+
/// </summary>
18+
/// <param name="log">The Cake log instance.</param>
19+
/// <param name="issues">Issues which should be returned by the issue provider.</param>
20+
/// <param name="delayMs">Simulated processing delay in milliseconds.</param>
21+
public FakeSlowIssueProvider(ICakeLog log, IEnumerable<IIssue> issues, int delayMs)
22+
: base(log)
23+
{
24+
issues.NotNull();
25+
26+
this.issues.AddRange(issues);
27+
this.delayMs = delayMs;
28+
}
29+
30+
/// <inheritdoc/>
31+
public override string ProviderName => "Fake Slow Issue Provider";
32+
33+
/// <inheritdoc/>
34+
protected override IEnumerable<IIssue> InternalReadIssues()
35+
{
36+
// Simulate slow processing
37+
Thread.Sleep(this.delayMs);
38+
return this.issues;
39+
}
40+
}

src/Cake.Issues.Tests/IssueReaderTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,5 +435,51 @@ public void Should_Handle_Provider_Initialization_Failures_Concurrently()
435435
issues.ShouldContain(x => x.MessageText == "Success1");
436436
issues.ShouldContain(x => x.MessageText == "Success2");
437437
}
438+
439+
[Fact]
440+
public void Should_Demonstrate_Parallel_Processing_Benefits_With_Simulated_Delays()
441+
{
442+
// Given - Create providers that simulate processing delays
443+
const int providerCount = 5;
444+
const int delayPerProviderMs = 50; // Simulate 50ms delay per provider
445+
var fixture = new IssuesFixture();
446+
fixture.IssueProviders.Clear();
447+
448+
for (var i = 0; i < providerCount; i++)
449+
{
450+
var issue = IssueBuilder
451+
.NewIssue($"SlowIssue{i}", $"SlowProviderType{i}", $"SlowProviderName{i}")
452+
.InFile($@"src\SlowFile{i}.cs", i + 1)
453+
.OfRule($"SlowRule{i}")
454+
.WithPriority(IssuePriority.Warning)
455+
.Create();
456+
fixture.IssueProviders.Add(new FakeSlowIssueProvider(fixture.Log, [issue], delayPerProviderMs));
457+
}
458+
459+
// When
460+
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
461+
var issues = fixture.ReadIssues().ToList();
462+
stopwatch.Stop();
463+
464+
// Then
465+
issues.Count.ShouldBe(providerCount);
466+
467+
// With parallel processing, total time should be significantly less than
468+
// sum of all delays (providerCount * delayPerProviderMs)
469+
var expectedSequentialTime = providerCount * delayPerProviderMs;
470+
var actualTime = stopwatch.ElapsedMilliseconds;
471+
472+
// Allow for some overhead but expect significant improvement
473+
var maxExpectedParallelTime = expectedSequentialTime * 0.4; // Should be much faster than 40% of sequential time
474+
475+
System.Console.WriteLine($"Sequential time would be ~{expectedSequentialTime}ms, parallel time was {actualTime}ms");
476+
477+
// This assertion may be flaky in CI environments, so we'll use a generous threshold
478+
actualTime.ShouldBeLessThan(expectedSequentialTime);
479+
480+
// Verify all issues have correct properties set
481+
// The Run property should be set to the same value from settings (even if null)
482+
issues.ShouldAllBe(x => x.Run == fixture.Settings.Run);
483+
}
438484
}
439485
}

0 commit comments

Comments
 (0)