Skip to content

Commit bb5a9fb

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 9577f4a commit bb5a9fb

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,6 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
24
using System.Data;
35
using System.Linq;
6+
using System.Reflection;
47
using System.Text;
58
using NHibernate.Dialect;
69
using NHibernate.Driver;
@@ -370,14 +373,14 @@ public void AnyObject()
370373
}
371374

372375
// Failing case till NH-3850 is fixed
373-
[Test]
376+
[Test, Ignore("Won't fix: requires reshaping the query")]
374377
public void AverageBBase()
375378
{
376379
Average<DomainClassBExtendedByA>(1.5m);
377380
}
378381

379382
// Non-reg case
380-
[Test]
383+
[Test, Ignore("Accidentally works: requires reshaping the query for being reliable")]
381384
public void AverageCBase()
382385
{
383386
Average<DomainClassCExtendedByD>(1.5m);
@@ -398,7 +401,7 @@ public void AverageF()
398401
}
399402

400403
// Failing case till NH-3850 is fixed
401-
[Test]
404+
[Test, Ignore("Won't fix: requires reshaping the query")]
402405
public void AverageGBase()
403406
{
404407
Average<DomainClassGExtendedByH>(2.5m);
@@ -421,7 +424,7 @@ private void Average<DC>(decimal? expectedResult) where DC : DomainClassBase
421424
}
422425

423426
// Failing case till NH-3850 is fixed
424-
[Test]
427+
[Test, Ignore("Won't fix: requires reshaping the query")]
425428
public void AverageObject()
426429
{
427430
using (var session = OpenSession())
@@ -1133,7 +1136,7 @@ public void SumE()
11331136
}
11341137

11351138
// Non-reg case
1136-
[Test]
1139+
[Test, Ignore("Candidate potential breaking changes: Sum would now yield 0 instead of null on empty result sets.")]
11371140
public void SumF()
11381141
{
11391142
Sum<DomainClassF>(null);
@@ -1181,5 +1184,69 @@ private void Sum<DC>(int? expectedResult) where DC : DomainClassBase
11811184
Assert.AreEqual(expectedResult.Value, dbl.Value, 0.001d);
11821185
}
11831186
}
1187+
1188+
[Test]
1189+
public void BadOverload()
1190+
{
1191+
var sumMethodTemplate = ReflectionHelper.GetMethod(() => Queryable.Sum((IQueryable<int>)null));
1192+
Assert.Throws<InvalidOperationException>(() =>
1193+
{
1194+
ReflectionHelper.GetMethodOverload(sumMethodTemplate, new[] { typeof(object) });
1195+
});
1196+
}
1197+
1198+
[Test, Explicit("Just a blunt perf comparison among some candidate overload reflection patterns, one being required for NH-3850")]
1199+
public void OverloadReflectionBluntPerfCompare()
1200+
{
1201+
var sumMethodTemplate = ReflectionHelper.GetMethod(() => Queryable.Sum((IQueryable<int>)null));
1202+
1203+
var swNoSameParamsCheck = new Stopwatch();
1204+
swNoSameParamsCheck.Start();
1205+
for (var i = 0; i < 1000; i++)
1206+
{
1207+
var sumMethod = sumMethodTemplate.DeclaringType.GetMethod(sumMethodTemplate.Name,
1208+
(sumMethodTemplate.IsStatic ? BindingFlags.Static : BindingFlags.Instance) | BindingFlags.Public,
1209+
null, new[] { typeof(IQueryable<decimal>) }, null);
1210+
Trace.TraceInformation(sumMethod.ToString());
1211+
}
1212+
swNoSameParamsCheck.Stop();
1213+
1214+
var swCurrentChoiceSameType = new Stopwatch();
1215+
swCurrentChoiceSameType.Start();
1216+
for (var i = 0; i < 1000; i++)
1217+
{
1218+
var sumMethod = ReflectionHelper.GetMethodOverload(sumMethodTemplate, new[] { typeof(IQueryable<int>) });
1219+
Trace.TraceInformation(sumMethod.ToString());
1220+
}
1221+
swCurrentChoiceSameType.Stop();
1222+
1223+
var swCurrentChoice = new Stopwatch();
1224+
swCurrentChoice.Start();
1225+
for (var i = 0; i < 1000; i++)
1226+
{
1227+
var sumMethod = ReflectionHelper.GetMethodOverload(sumMethodTemplate, new[] { typeof(IQueryable<long>) });
1228+
Trace.TraceInformation(sumMethod.ToString());
1229+
}
1230+
swCurrentChoice.Stop();
1231+
1232+
var swEnHlp = new Stopwatch();
1233+
swEnHlp.Start();
1234+
for (var i = 0; i < 1000; i++)
1235+
{
1236+
// Testing the obsolete helper perf. Disable obsolete warning. Remove this swEnHlp part of the test if this helper is to be removed.
1237+
#pragma warning disable 0618
1238+
var sumMethod = EnumerableHelper.GetMethod("Sum", new[] { typeof(IEnumerable<int>) });
1239+
#pragma warning restore 0618
1240+
Trace.TraceInformation(sumMethod.ToString());
1241+
}
1242+
swEnHlp.Stop();
1243+
1244+
Assert.Pass(@"Blunt perf timings:
1245+
Direct reflection: {0}
1246+
Current impl, same overload: {1}
1247+
Current impl, other overload: {2}
1248+
EnumerableHelper.GetMethod(non generic overload): {3}",
1249+
swNoSameParamsCheck.Elapsed, swCurrentChoiceSameType.Elapsed, swCurrentChoice.Elapsed, swEnHlp.Elapsed);
1250+
}
11841251
}
11851252
}

0 commit comments

Comments
 (0)