Skip to content

Commit

Permalink
Fix to #27155 - Average_Grouped_from_LINQ_101 is non-deterministic
Browse files Browse the repository at this point in the history
Added custom asserter that checks results within range, rather than adding sql server specific expected query
For the second test, added proper collection asserter so we can impose the order within nested collection.

Fixes #27155
  • Loading branch information
maumar committed Aug 10, 2022
1 parent b85b83f commit c6f5316
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ public Ef6GroupByInMemoryTest(Ef6GroupByInMemoryFixture fixture, ITestOutputHelp
{
}

public override Task Average_Grouped_from_LINQ_101(bool async)
=> AssertQuery(
async,
ss => from p in ss.Set<ProductForLinq>()
group p by p.Category
into g
select new { Category = g.Key, AveragePrice = g.Average(p => p.UnitPrice) },
elementSorter: e => (e.Category, e.AveragePrice));

public class Ef6GroupByInMemoryFixture : Ef6GroupByFixtureBase
{
protected override ITestStoreFactory TestStoreFactory
Expand Down
13 changes: 7 additions & 6 deletions test/EFCore.Specification.Tests/Query/Ef6GroupByTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,12 @@ public virtual Task Average_Grouped_from_LINQ_101(bool async)
group p by p.Category
into g
select new { Category = g.Key, AveragePrice = g.Average(p => p.UnitPrice) },
ss => from p in ss.Set<ProductForLinq>()
group p by p.Category
into g
select new { Category = g.Key, AveragePrice = Math.Round(g.Average(p => p.UnitPrice) - 0.0000005m, 6) },
elementSorter: e => (e.Category, e.AveragePrice));
elementSorter: e => (e.Category, e.AveragePrice),
elementAsserter: (e, a) =>
{
AssertEqual(e.Category, a.Category);
Assert.InRange(a.AveragePrice, e.AveragePrice - 0.00005m, e.AveragePrice + 0.00005m);
});

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
Expand Down Expand Up @@ -644,7 +645,7 @@ in temp
Assert.Equal(l.Id, r.Id);
Assert.Equal(l.Age, r.Age);
Assert.Equal(l.Style, r.Style);
Assert.Equal(l.Values, r.Values);
AssertCollection(l.Values, r.Values, elementSorter: e => (e.Id, e.Style, e.Age));
});
[ConditionalTheory] // From #19506
Expand Down

0 comments on commit c6f5316

Please sign in to comment.