Skip to content

Commit ef5e70d

Browse files
committed
ExpressionSessionLeakTest - mark as KnownBug and refactor to use using statement.
1 parent 770ab3c commit ef5e70d

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/NHibernate.Test/Linq/ExpressionSessionLeakTest.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,30 @@ namespace NHibernate.Test.Linq
88
{
99
public class ExpressionSessionLeakTest : LinqTestCase
1010
{
11-
[Test]
12-
[Ignore("Not fixed yet. NH-3579")]
11+
[Test, KnownBug("NH-3579")]
1312
public void SessionGetsCollected()
1413
{
1514
var reference = DoLinqInSeparateSession();
1615

1716
GC.Collect();
1817

19-
Assert.Null(reference.Target);
18+
Assert.That(reference.IsAlive, Is.False);
2019
}
2120

22-
2321
private WeakReference DoLinqInSeparateSession()
2422
{
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);
23+
using (var leakTest = session.SessionFactory.OpenSession())
24+
{
25+
// It appears linq expressions will (or might) contain a reference to the
26+
// IQueryable. At time of writing, linq expressions are helt within NhLinqExpression,
27+
// which in turn will be held in the query plan cache. Since the IQueryable will
28+
// be an NhQueryable, which holds a reference to the SessionImpl instance,
29+
// we will be leaking session instances.
30+
31+
var query = leakTest.Query<Customer>().FirstOrDefault(t => t.CustomerId != "");
32+
33+
return new WeakReference(leakTest, false);
34+
}
3735
}
3836
}
3937
}

0 commit comments

Comments
 (0)