Skip to content

Commit 08abfa6

Browse files
NH-3850 - Polymorphic Linq query results aggregators failures: amending test cases for acknowledging cases which will not be fixed, including a potential breaking change.
1 parent 94eda20 commit 08abfa6

File tree

1 file changed

+72
-5
lines changed
  • src/NHibernate.Test/NHSpecificTest/NH3850

1 file changed

+72
-5
lines changed

src/NHibernate.Test/NHSpecificTest/NH3850/Fixture.cs

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
24
using System.Linq;
5+
using System.Reflection;
36
using System.Text;
47
using NHibernate.Linq;
58
using NUnit.Framework;
@@ -350,14 +353,14 @@ public void AnyObject()
350353
}
351354

352355
// Failing case till NH-3850 is fixed
353-
[Test]
356+
[Test, Ignore("Won't fix: requires reshaping the query")]
354357
public void AverageBBase()
355358
{
356359
Average<DomainClassBExtendedByA>(1.5m);
357360
}
358361

359362
// Non-reg case
360-
[Test]
363+
[Test, Ignore("Accidentally works: requires reshaping the query for being reliable")]
361364
public void AverageCBase()
362365
{
363366
Average<DomainClassCExtendedByD>(1.5m);
@@ -378,7 +381,7 @@ public void AverageF()
378381
}
379382

380383
// Failing case till NH-3850 is fixed
381-
[Test]
384+
[Test, Ignore("Won't fix: requires reshaping the query")]
382385
public void AverageGBase()
383386
{
384387
Average<DomainClassGExtendedByH>(2.5m);
@@ -401,7 +404,7 @@ private void Average<DC>(decimal? expectedResult) where DC : DomainClassBase
401404
}
402405

403406
// Failing case till NH-3850 is fixed
404-
[Test]
407+
[Test, Ignore("Won't fix: requires reshaping the query")]
405408
public void AverageObject()
406409
{
407410
using (var session = OpenSession())
@@ -1113,7 +1116,7 @@ public void SumE()
11131116
}
11141117

11151118
// Non-reg case
1116-
[Test]
1119+
[Test, Ignore("Candidate potential breaking changes: Sum would now yield 0 instead of null on empty result sets.")]
11171120
public void SumF()
11181121
{
11191122
Sum<DomainClassF>(null);
@@ -1161,5 +1164,69 @@ private void Sum<DC>(int? expectedResult) where DC : DomainClassBase
11611164
Assert.AreEqual(expectedResult.Value, dbl.Value, 0.001d);
11621165
}
11631166
}
1167+
1168+
[Test]
1169+
public void BadOverload()
1170+
{
1171+
var sumMethodTemplate = ReflectionHelper.GetMethod(() => Queryable.Sum((IQueryable<int>)null));
1172+
Assert.Throws<InvalidOperationException>(() =>
1173+
{
1174+
ReflectionHelper.GetMethodOverload(sumMethodTemplate, new[] { typeof(object) });
1175+
});
1176+
}
1177+
1178+
[Test, Explicit("Just a blunt perf comparison among some candidate overload reflection patterns, one being required for NH-3850")]
1179+
public void OverloadReflectionBluntPerfCompare()
1180+
{
1181+
var sumMethodTemplate = ReflectionHelper.GetMethod(() => Queryable.Sum((IQueryable<int>)null));
1182+
1183+
var swNoSameParamsCheck = new Stopwatch();
1184+
swNoSameParamsCheck.Start();
1185+
for (var i = 0; i < 1000; i++)
1186+
{
1187+
var sumMethod = sumMethodTemplate.DeclaringType.GetMethod(sumMethodTemplate.Name,
1188+
(sumMethodTemplate.IsStatic ? BindingFlags.Static : BindingFlags.Instance) | BindingFlags.Public,
1189+
null, new[] { typeof(IQueryable<decimal>) }, null);
1190+
Trace.TraceInformation(sumMethod.ToString());
1191+
}
1192+
swNoSameParamsCheck.Stop();
1193+
1194+
var swCurrentChoiceSameType = new Stopwatch();
1195+
swCurrentChoiceSameType.Start();
1196+
for (var i = 0; i < 1000; i++)
1197+
{
1198+
var sumMethod = ReflectionHelper.GetMethodOverload(sumMethodTemplate, new[] { typeof(IQueryable<int>) });
1199+
Trace.TraceInformation(sumMethod.ToString());
1200+
}
1201+
swCurrentChoiceSameType.Stop();
1202+
1203+
var swCurrentChoice = new Stopwatch();
1204+
swCurrentChoice.Start();
1205+
for (var i = 0; i < 1000; i++)
1206+
{
1207+
var sumMethod = ReflectionHelper.GetMethodOverload(sumMethodTemplate, new[] { typeof(IQueryable<long>) });
1208+
Trace.TraceInformation(sumMethod.ToString());
1209+
}
1210+
swCurrentChoice.Stop();
1211+
1212+
var swEnHlp = new Stopwatch();
1213+
swEnHlp.Start();
1214+
for (var i = 0; i < 1000; i++)
1215+
{
1216+
// Testing the obsolete helper perf. Disable obsolete warning. Remove this swEnHlp part of the test if this helper is to be removed.
1217+
#pragma warning disable 0618
1218+
var sumMethod = EnumerableHelper.GetMethod("Sum", new[] { typeof(IEnumerable<int>) });
1219+
#pragma warning restore 0618
1220+
Trace.TraceInformation(sumMethod.ToString());
1221+
}
1222+
swEnHlp.Stop();
1223+
1224+
Assert.Pass(@"Blunt perf timings:
1225+
Direct reflection: {0}
1226+
Current impl, same overload: {1}
1227+
Current impl, other overload: {2}
1228+
EnumerableHelper.GetMethod(non generic overload): {3}",
1229+
swNoSameParamsCheck.Elapsed, swCurrentChoiceSameType.Elapsed, swCurrentChoice.Elapsed, swEnHlp.Elapsed);
1230+
}
11641231
}
11651232
}

0 commit comments

Comments
 (0)