Skip to content
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

Merged
merged 1 commit into from
Oct 31, 2019
Merged

Fix some non-determinism in tests #18675

merged 1 commit into from
Oct 31, 2019

Conversation

roji
Copy link
Member

@roji roji commented Oct 31, 2019

This are subtle and super annoying to track down... Too bad tests pass on SQL Server/Sqlite...

@roji
Copy link
Member Author

roji commented Oct 31, 2019

/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);
Copy link
Member

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.

Copy link
Member Author

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).

Copy link
Member

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.

Copy link
Contributor

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

Copy link
Member Author

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!

@smitpatel smitpatel requested a review from maumar October 31, 2019 17:55
@roji roji merged commit bb01f02 into release/3.1 Oct 31, 2019
@roji roji deleted the NonDeterminismBegone branch October 31, 2019 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants