-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some non-determinism in tests #18675
Conversation
/cc @Pilchie |
@@ -257,8 +257,7 @@ public virtual Task GroupBy_aggregate_projecting_conditional_expression(bool isA | |||
isAsync, | |||
ss => ss.Set<Order>().GroupBy(o => o.OrderDate).Select( | |||
g => | |||
new { g.Key, SomeValue = g.Count() == 0 ? 1 : g.Sum(o => o.OrderID % 2 == 0 ? 1 : 0) / g.Count() }), | |||
e => e.SomeValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maumar may have better idea on what should be element sorter here. May be combination of Key + SomeValue could be unique and gives us stable ordering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that could also work. I'm not sure I understand when we want to assert order and when we don't care - in this test AFAICT ordering doesn't seem to be important (but no problem to add).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no element sorter we do contains match if expected result appear in actual results. It has slight case of incorrect result when there are duplication. So @maumar added element sorters. When element sorter is specified, both results (expected/actual) are sorted using that and then element by element match. So you want unique deterministic ordering in element sorter. We also have built-in element sorters for our entityTypes so you don't have to specify always.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case of anonymous types i usually order by tuple of the properties:
e => (e.Key, e.SomeValue), if that's still not deterministic then removing elementSorter is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, the tuple makes the test pass on PG, thanks!
57d8d75
to
fb8fc9e
Compare
This are subtle and super annoying to track down... Too bad tests pass on SQL Server/Sqlite...