Skip to content
Merged
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
25 changes: 9 additions & 16 deletions tests/TUnit.TestProject/ParallelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ public class ParallelTests
private static readonly ConcurrentBag<DateTimeRange> TestDateTimeRanges = [];

[After(Test)]
public async Task TestOverlaps()
public void RecordExecutionRange()
{
TestDateTimeRanges.Add(new DateTimeRange(TestContext.Current!.Execution.TestStart!.Value.DateTime, TestContext.Current.Execution.Result!.End!.Value.DateTime));

await AssertOverlaps();
}

[Test, Repeat(3)]
Expand All @@ -35,20 +33,15 @@ public async Task Parallel_Test3()
await Task.Delay(5000);
}

private async Task AssertOverlaps()
[After(Class)]
public static async Task AssertOverlaps()
{
if (TestDateTimeRanges.Count < 5)
{
return;
}

foreach (var testDateTimeRange in TestDateTimeRanges)
{
await Assert.That(TestDateTimeRanges
.Except([testDateTimeRange])
.Any(x => x.Overlap(testDateTimeRange)))
.IsTrue();
}
// Later repetitions may run alone on a busy runner. One overlapping pair
// is enough to prove that this class can execute tests concurrently.
var ranges = TestDateTimeRanges.ToArray();
await Assert.That(ranges.Any(range => ranges.Any(other =>
!ReferenceEquals(range, other) && range.Overlap(other))))
.IsTrue();
}

private class DateTimeRange(DateTime start, DateTime end)
Expand Down
Loading