Skip to content

Commit 770ab3c

Browse files
committed
ExpressionSessionLeakTest: Add failing test for NH-3579.
1 parent 0899043 commit 770ab3c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Linq;
3+
using NHibernate.DomainModel.Northwind.Entities;
4+
using NHibernate.Linq;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.Linq
8+
{
9+
public class ExpressionSessionLeakTest : LinqTestCase
10+
{
11+
[Test]
12+
[Ignore("Not fixed yet. NH-3579")]
13+
public void SessionGetsCollected()
14+
{
15+
var reference = DoLinqInSeparateSession();
16+
17+
GC.Collect();
18+
19+
Assert.Null(reference.Target);
20+
}
21+
22+
23+
private WeakReference DoLinqInSeparateSession()
24+
{
25+
var leakTest = session.SessionFactory.OpenSession();
26+
27+
// It appears linq expressions will (or might) contain a reference to the
28+
// IQueryable. At time of writing, linq expressions are helt within NhLinqExpression,
29+
// which in turn will be held in the query plan cache. Since the IQueryable will
30+
// be an NhQueryable, which holds a reference to the SessionImpl instance,
31+
// we will be leaking session instances.
32+
33+
var query = leakTest.Query<Customer>().FirstOrDefault(t => t.CustomerId != "");
34+
leakTest.Dispose();
35+
36+
return new WeakReference(leakTest, false);
37+
}
38+
}
39+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@
513513
<Compile Include="Linq\CasingTest.cs" />
514514
<Compile Include="Linq\CharComparisonTests.cs" />
515515
<Compile Include="Linq\DateTimeTests.cs" />
516+
<Compile Include="Linq\ExpressionSessionLeakTest.cs" />
516517
<Compile Include="Linq\LoggingTests.cs" />
517518
<Compile Include="Linq\QueryTimeoutTests.cs" />
518519
<Compile Include="Linq\JoinTests.cs" />

0 commit comments

Comments
 (0)