From c326870a2b21d83a33b30cb36800599d946860eb Mon Sep 17 00:00:00 2001 From: Smit Patel Date: Wed, 15 Jul 2020 08:32:08 -0700 Subject: [PATCH] Fix non-deterministic test issue in ManyToManyQueryTestBase Resolves #21636 --- .../Query/ManyToManyQueryTestBase.cs | 10 +++++----- .../Query/ManyToManyNoTrackingQuerySqlServerTest.cs | 13 ++++++++----- .../Query/ManyToManyQuerySqlServerTest.cs | 13 ++++++++----- .../TPTManyToManyNoTrackingQuerySqlServerTest.cs | 13 ++++++++----- .../Query/TPTManyToManyQuerySqlServerTest.cs | 13 ++++++++----- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/test/EFCore.Specification.Tests/Query/ManyToManyQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ManyToManyQueryTestBase.cs index b13bf4f3f3d..b6b8cb4b41f 100644 --- a/test/EFCore.Specification.Tests/Query/ManyToManyQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ManyToManyQueryTestBase.cs @@ -98,7 +98,7 @@ public virtual Task Skip_navigation_long_count_with_predicate(bool async) { return AssertQuery( async, - ss => ss.Set().OrderByDescending(e => e.SelfSkipSharedLeft.LongCount(e => e.Name.StartsWith("L"))), + ss => ss.Set().OrderByDescending(e => e.SelfSkipSharedLeft.LongCount(e => e.Name.StartsWith("L"))).ThenBy(e => e.Id), assertOrder: true, entryCount: 20); } @@ -249,7 +249,7 @@ public virtual Task Join_with_skip_navigation(bool async) async, ss => from t in ss.Set() join s in ss.Set() - on t.Id equals s.SelfSkipSharedRight.FirstOrDefault().Id + on t.Id equals s.SelfSkipSharedRight.OrderBy(e => e.Id).FirstOrDefault().Id select new { t, s }, elementSorter: e => (e.t.Id, e.s.Id), elementAsserter: (e, a) => @@ -268,13 +268,13 @@ public virtual Task Left_join_with_skip_navigation(bool async) async, ss => from t in ss.Set() join s in ss.Set() - on t.TwoSkipShared.FirstOrDefault().Id equals s.ThreeSkipFull.FirstOrDefault().Id into grouping + on t.TwoSkipShared.OrderBy(e => e.Id).FirstOrDefault().Id equals s.ThreeSkipFull.OrderBy(e => e.Id).FirstOrDefault().Id into grouping from s in grouping.DefaultIfEmpty() orderby t.Key1, s.Key1 select new { t, s }, ss => from t in ss.Set() join s in ss.Set() - on t.TwoSkipShared.FirstOrDefault().MaybeScalar(e => e.Id) equals s.ThreeSkipFull.FirstOrDefault().MaybeScalar(e => e.Id) into grouping + on t.TwoSkipShared.OrderBy(e => e.Id).FirstOrDefault().MaybeScalar(e => e.Id) equals s.ThreeSkipFull.OrderBy(e => e.Id).FirstOrDefault().MaybeScalar(e => e.Id) into grouping from s in grouping.DefaultIfEmpty() orderby t.MaybeScalar(e => e.Key1), s.MaybeScalar(e => e.Key1) select new { t, s }, @@ -417,7 +417,7 @@ public virtual Task Select_skip_navigation_first_or_default(bool async) async, ss => from r in ss.Set() orderby r.Id - select r.CompositeKeySkipFull.FirstOrDefault(), + select r.CompositeKeySkipFull.OrderBy(e => e.Key1).FirstOrDefault(), assertOrder: true, entryCount: 12); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyNoTrackingQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyNoTrackingQuerySqlServerTest.cs index caee325bfd5..fc6bf143631 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyNoTrackingQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyNoTrackingQuerySqlServerTest.cs @@ -131,7 +131,7 @@ ORDER BY ( SELECT COUNT_BIG(*) FROM [JoinTwoSelfShared] AS [j] INNER JOIN [EntityTwos] AS [e0] ON [j].[LeftId] = [e0].[Id] - WHERE ([e].[Id] = [j].[RightId]) AND ([e0].[Name] IS NOT NULL AND ([e0].[Name] LIKE N'L%'))) DESC"); + WHERE ([e].[Id] = [j].[RightId]) AND ([e0].[Name] IS NOT NULL AND ([e0].[Name] LIKE N'L%'))) DESC, [e].[Id]"); } public override async Task Skip_navigation_select_many_average(bool async) @@ -364,7 +364,8 @@ FROM [EntityTwos] AS [e] SELECT TOP(1) [e1].[Id] FROM [JoinTwoSelfShared] AS [j] INNER JOIN [EntityTwos] AS [e1] ON [j].[RightId] = [e1].[Id] - WHERE [e0].[Id] = [j].[LeftId])"); + WHERE [e0].[Id] = [j].[LeftId] + ORDER BY [e1].[Id])"); } public override async Task Left_join_with_skip_navigation(bool async) @@ -378,11 +379,13 @@ LEFT JOIN [EntityCompositeKeys] AS [e0] ON ( SELECT TOP(1) [e1].[Id] FROM [JoinTwoToCompositeKeyShared] AS [j] INNER JOIN [EntityTwos] AS [e1] ON [j].[TwoId] = [e1].[Id] - WHERE (([e].[Key1] = [j].[CompositeId1]) AND ([e].[Key2] = [j].[CompositeId2])) AND ([e].[Key3] = [j].[CompositeId3])) = ( + WHERE (([e].[Key1] = [j].[CompositeId1]) AND ([e].[Key2] = [j].[CompositeId2])) AND ([e].[Key3] = [j].[CompositeId3]) + ORDER BY [e1].[Id]) = ( SELECT TOP(1) [e2].[Id] FROM [JoinThreeToCompositeKeyFull] AS [j0] INNER JOIN [EntityThrees] AS [e2] ON [j0].[ThreeId] = [e2].[Id] - WHERE (([e0].[Key1] = [j0].[CompositeId1]) AND ([e0].[Key2] = [j0].[CompositeId2])) AND ([e0].[Key3] = [j0].[CompositeId3])) + WHERE (([e0].[Key1] = [j0].[CompositeId1]) AND ([e0].[Key2] = [j0].[CompositeId2])) AND ([e0].[Key3] = [j0].[CompositeId3]) + ORDER BY [e2].[Id]) ORDER BY [e].[Key1], [e0].[Key1]"); } @@ -551,7 +554,7 @@ FROM [EntityThrees] AS [e] LEFT JOIN ( SELECT [t].[Key1], [t].[Key2], [t].[Key3], [t].[Name], [t].[ThreeId], [t].[CompositeId1], [t].[CompositeId2], [t].[CompositeId3] FROM ( - SELECT [e0].[Key1], [e0].[Key2], [e0].[Key3], [e0].[Name], [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], ROW_NUMBER() OVER(PARTITION BY [j].[ThreeId] ORDER BY [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], [e0].[Key1], [e0].[Key2], [e0].[Key3]) AS [row] + SELECT [e0].[Key1], [e0].[Key2], [e0].[Key3], [e0].[Name], [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], ROW_NUMBER() OVER(PARTITION BY [j].[ThreeId] ORDER BY [e0].[Key1]) AS [row] FROM [JoinThreeToCompositeKeyFull] AS [j] INNER JOIN [EntityCompositeKeys] AS [e0] ON (([j].[CompositeId1] = [e0].[Key1]) AND ([j].[CompositeId2] = [e0].[Key2])) AND ([j].[CompositeId3] = [e0].[Key3]) ) AS [t] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyQuerySqlServerTest.cs index 4f520e66a04..2f95c28b1a5 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/ManyToManyQuerySqlServerTest.cs @@ -131,7 +131,7 @@ ORDER BY ( SELECT COUNT_BIG(*) FROM [JoinTwoSelfShared] AS [j] INNER JOIN [EntityTwos] AS [e0] ON [j].[LeftId] = [e0].[Id] - WHERE ([e].[Id] = [j].[RightId]) AND ([e0].[Name] IS NOT NULL AND ([e0].[Name] LIKE N'L%'))) DESC"); + WHERE ([e].[Id] = [j].[RightId]) AND ([e0].[Name] IS NOT NULL AND ([e0].[Name] LIKE N'L%'))) DESC, [e].[Id]"); } public override async Task Skip_navigation_select_many_average(bool async) @@ -364,7 +364,8 @@ FROM [EntityTwos] AS [e] SELECT TOP(1) [e1].[Id] FROM [JoinTwoSelfShared] AS [j] INNER JOIN [EntityTwos] AS [e1] ON [j].[RightId] = [e1].[Id] - WHERE [e0].[Id] = [j].[LeftId])"); + WHERE [e0].[Id] = [j].[LeftId] + ORDER BY [e1].[Id])"); } public override async Task Left_join_with_skip_navigation(bool async) @@ -378,11 +379,13 @@ LEFT JOIN [EntityCompositeKeys] AS [e0] ON ( SELECT TOP(1) [e1].[Id] FROM [JoinTwoToCompositeKeyShared] AS [j] INNER JOIN [EntityTwos] AS [e1] ON [j].[TwoId] = [e1].[Id] - WHERE (([e].[Key1] = [j].[CompositeId1]) AND ([e].[Key2] = [j].[CompositeId2])) AND ([e].[Key3] = [j].[CompositeId3])) = ( + WHERE (([e].[Key1] = [j].[CompositeId1]) AND ([e].[Key2] = [j].[CompositeId2])) AND ([e].[Key3] = [j].[CompositeId3]) + ORDER BY [e1].[Id]) = ( SELECT TOP(1) [e2].[Id] FROM [JoinThreeToCompositeKeyFull] AS [j0] INNER JOIN [EntityThrees] AS [e2] ON [j0].[ThreeId] = [e2].[Id] - WHERE (([e0].[Key1] = [j0].[CompositeId1]) AND ([e0].[Key2] = [j0].[CompositeId2])) AND ([e0].[Key3] = [j0].[CompositeId3])) + WHERE (([e0].[Key1] = [j0].[CompositeId1]) AND ([e0].[Key2] = [j0].[CompositeId2])) AND ([e0].[Key3] = [j0].[CompositeId3]) + ORDER BY [e2].[Id]) ORDER BY [e].[Key1], [e0].[Key1]"); } @@ -551,7 +554,7 @@ FROM [EntityThrees] AS [e] LEFT JOIN ( SELECT [t].[Key1], [t].[Key2], [t].[Key3], [t].[Name], [t].[ThreeId], [t].[CompositeId1], [t].[CompositeId2], [t].[CompositeId3] FROM ( - SELECT [e0].[Key1], [e0].[Key2], [e0].[Key3], [e0].[Name], [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], ROW_NUMBER() OVER(PARTITION BY [j].[ThreeId] ORDER BY [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], [e0].[Key1], [e0].[Key2], [e0].[Key3]) AS [row] + SELECT [e0].[Key1], [e0].[Key2], [e0].[Key3], [e0].[Name], [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], ROW_NUMBER() OVER(PARTITION BY [j].[ThreeId] ORDER BY [e0].[Key1]) AS [row] FROM [JoinThreeToCompositeKeyFull] AS [j] INNER JOIN [EntityCompositeKeys] AS [e0] ON (([j].[CompositeId1] = [e0].[Key1]) AND ([j].[CompositeId2] = [e0].[Key2])) AND ([j].[CompositeId3] = [e0].[Key3]) ) AS [t] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTManyToManyNoTrackingQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTManyToManyNoTrackingQuerySqlServerTest.cs index 371e441aebd..88c07ac2536 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPTManyToManyNoTrackingQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTManyToManyNoTrackingQuerySqlServerTest.cs @@ -134,7 +134,7 @@ ORDER BY ( SELECT COUNT_BIG(*) FROM [JoinTwoSelfShared] AS [j] INNER JOIN [EntityTwos] AS [e0] ON [j].[LeftId] = [e0].[Id] - WHERE ([e].[Id] = [j].[RightId]) AND ([e0].[Name] IS NOT NULL AND ([e0].[Name] LIKE N'L%'))) DESC"); + WHERE ([e].[Id] = [j].[RightId]) AND ([e0].[Name] IS NOT NULL AND ([e0].[Name] LIKE N'L%'))) DESC, [e].[Id]"); } public override async Task Skip_navigation_select_many_average(bool async) @@ -394,7 +394,8 @@ FROM [EntityTwos] AS [e] SELECT TOP(1) [e1].[Id] FROM [JoinTwoSelfShared] AS [j] INNER JOIN [EntityTwos] AS [e1] ON [j].[RightId] = [e1].[Id] - WHERE [e0].[Id] = [j].[LeftId])"); + WHERE [e0].[Id] = [j].[LeftId] + ORDER BY [e1].[Id])"); } public override async Task Left_join_with_skip_navigation(bool async) @@ -408,11 +409,13 @@ LEFT JOIN [EntityCompositeKeys] AS [e0] ON ( SELECT TOP(1) [e1].[Id] FROM [JoinTwoToCompositeKeyShared] AS [j] INNER JOIN [EntityTwos] AS [e1] ON [j].[TwoId] = [e1].[Id] - WHERE (([e].[Key1] = [j].[CompositeId1]) AND ([e].[Key2] = [j].[CompositeId2])) AND ([e].[Key3] = [j].[CompositeId3])) = ( + WHERE (([e].[Key1] = [j].[CompositeId1]) AND ([e].[Key2] = [j].[CompositeId2])) AND ([e].[Key3] = [j].[CompositeId3]) + ORDER BY [e1].[Id]) = ( SELECT TOP(1) [e2].[Id] FROM [JoinThreeToCompositeKeyFull] AS [j0] INNER JOIN [EntityThrees] AS [e2] ON [j0].[ThreeId] = [e2].[Id] - WHERE (([e0].[Key1] = [j0].[CompositeId1]) AND ([e0].[Key2] = [j0].[CompositeId2])) AND ([e0].[Key3] = [j0].[CompositeId3])) + WHERE (([e0].[Key1] = [j0].[CompositeId1]) AND ([e0].[Key2] = [j0].[CompositeId2])) AND ([e0].[Key3] = [j0].[CompositeId3]) + ORDER BY [e2].[Id]) ORDER BY [e].[Key1], [e0].[Key1]"); } @@ -598,7 +601,7 @@ FROM [EntityThrees] AS [e] LEFT JOIN ( SELECT [t].[Key1], [t].[Key2], [t].[Key3], [t].[Name], [t].[ThreeId], [t].[CompositeId1], [t].[CompositeId2], [t].[CompositeId3] FROM ( - SELECT [e0].[Key1], [e0].[Key2], [e0].[Key3], [e0].[Name], [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], ROW_NUMBER() OVER(PARTITION BY [j].[ThreeId] ORDER BY [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], [e0].[Key1], [e0].[Key2], [e0].[Key3]) AS [row] + SELECT [e0].[Key1], [e0].[Key2], [e0].[Key3], [e0].[Name], [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], ROW_NUMBER() OVER(PARTITION BY [j].[ThreeId] ORDER BY [e0].[Key1]) AS [row] FROM [JoinThreeToCompositeKeyFull] AS [j] INNER JOIN [EntityCompositeKeys] AS [e0] ON (([j].[CompositeId1] = [e0].[Key1]) AND ([j].[CompositeId2] = [e0].[Key2])) AND ([j].[CompositeId3] = [e0].[Key3]) ) AS [t] diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTManyToManyQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTManyToManyQuerySqlServerTest.cs index 8ea699413f0..d3c62252abd 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPTManyToManyQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTManyToManyQuerySqlServerTest.cs @@ -134,7 +134,7 @@ ORDER BY ( SELECT COUNT_BIG(*) FROM [JoinTwoSelfShared] AS [j] INNER JOIN [EntityTwos] AS [e0] ON [j].[LeftId] = [e0].[Id] - WHERE ([e].[Id] = [j].[RightId]) AND ([e0].[Name] IS NOT NULL AND ([e0].[Name] LIKE N'L%'))) DESC"); + WHERE ([e].[Id] = [j].[RightId]) AND ([e0].[Name] IS NOT NULL AND ([e0].[Name] LIKE N'L%'))) DESC, [e].[Id]"); } public override async Task Skip_navigation_select_many_average(bool async) @@ -394,7 +394,8 @@ FROM [EntityTwos] AS [e] SELECT TOP(1) [e1].[Id] FROM [JoinTwoSelfShared] AS [j] INNER JOIN [EntityTwos] AS [e1] ON [j].[RightId] = [e1].[Id] - WHERE [e0].[Id] = [j].[LeftId])"); + WHERE [e0].[Id] = [j].[LeftId] + ORDER BY [e1].[Id])"); } public override async Task Left_join_with_skip_navigation(bool async) @@ -408,11 +409,13 @@ LEFT JOIN [EntityCompositeKeys] AS [e0] ON ( SELECT TOP(1) [e1].[Id] FROM [JoinTwoToCompositeKeyShared] AS [j] INNER JOIN [EntityTwos] AS [e1] ON [j].[TwoId] = [e1].[Id] - WHERE (([e].[Key1] = [j].[CompositeId1]) AND ([e].[Key2] = [j].[CompositeId2])) AND ([e].[Key3] = [j].[CompositeId3])) = ( + WHERE (([e].[Key1] = [j].[CompositeId1]) AND ([e].[Key2] = [j].[CompositeId2])) AND ([e].[Key3] = [j].[CompositeId3]) + ORDER BY [e1].[Id]) = ( SELECT TOP(1) [e2].[Id] FROM [JoinThreeToCompositeKeyFull] AS [j0] INNER JOIN [EntityThrees] AS [e2] ON [j0].[ThreeId] = [e2].[Id] - WHERE (([e0].[Key1] = [j0].[CompositeId1]) AND ([e0].[Key2] = [j0].[CompositeId2])) AND ([e0].[Key3] = [j0].[CompositeId3])) + WHERE (([e0].[Key1] = [j0].[CompositeId1]) AND ([e0].[Key2] = [j0].[CompositeId2])) AND ([e0].[Key3] = [j0].[CompositeId3]) + ORDER BY [e2].[Id]) ORDER BY [e].[Key1], [e0].[Key1]"); } @@ -598,7 +601,7 @@ FROM [EntityThrees] AS [e] LEFT JOIN ( SELECT [t].[Key1], [t].[Key2], [t].[Key3], [t].[Name], [t].[ThreeId], [t].[CompositeId1], [t].[CompositeId2], [t].[CompositeId3] FROM ( - SELECT [e0].[Key1], [e0].[Key2], [e0].[Key3], [e0].[Name], [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], ROW_NUMBER() OVER(PARTITION BY [j].[ThreeId] ORDER BY [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], [e0].[Key1], [e0].[Key2], [e0].[Key3]) AS [row] + SELECT [e0].[Key1], [e0].[Key2], [e0].[Key3], [e0].[Name], [j].[ThreeId], [j].[CompositeId1], [j].[CompositeId2], [j].[CompositeId3], ROW_NUMBER() OVER(PARTITION BY [j].[ThreeId] ORDER BY [e0].[Key1]) AS [row] FROM [JoinThreeToCompositeKeyFull] AS [j] INNER JOIN [EntityCompositeKeys] AS [e0] ON (([j].[CompositeId1] = [e0].[Key1]) AND ([j].[CompositeId2] = [e0].[Key2])) AND ([j].[CompositeId3] = [e0].[Key3]) ) AS [t]