Skip to content

Commit

Permalink
NH-3985 - Fix for subsequent child sessions being returned in dispose…
Browse files Browse the repository at this point in the history
…d state
  • Loading branch information
alobakov authored and hazzik committed Apr 25, 2017
1 parent 2d2095b commit 4558d53
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3985/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace NHibernate.Test.NHSpecificTest.NH3985
{
public partial class Process
{
public virtual Guid ProcessID { get; set; }
public virtual string Name { get; set; }
}
}
43 changes: 43 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3985/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NUnit.Framework;
using System;

namespace NHibernate.Test.NHSpecificTest.NH3985
{
/// <summary>
/// The test verifies that subsequent child sessions are not issued in already-disposed state.
/// </summary>
[TestFixture]
public class Fixture : BugTestCase
{
[Test]
public void GetChildSession_ShouldReturnNonDisposedInstance()
{
using (var rootSession = OpenSession())
{
using (var childSession1 = rootSession.GetChildSession())
{
}

using (var childSession2 = rootSession.GetChildSession())
{
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
}
}
}

[Test]
public void GetChildSession_ShouldReturnNonClosedInstance()
{
using (var rootSession = OpenSession())
{
var childSession1 = rootSession.GetChildSession();
childSession1.Close();

using (var childSession2 = rootSession.GetChildSession())
{
Assert.DoesNotThrow(() => { childSession2.Get<Process>(Guid.NewGuid()); });
}
}
}
}
}
7 changes: 7 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH3985/Mappings.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3985">
<class name="Process">
<id name="ProcessID" generator="guid.comb" />
<property name="Name" />
</class>
</hibernate-mapping>
3 changes: 3 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\IExample.cs" />
<Compile Include="Insertordering\NH3931Entities.cs" />
<Compile Include="NHSpecificTest\NH1904\StructFixture.cs" />
<Compile Include="NHSpecificTest\NH3985\Entity.cs" />
<Compile Include="NHSpecificTest\NH3985\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3247\Entity.cs" />
<Compile Include="NHSpecificTest\NH3247\Fixture.cs" />
<Compile Include="NHSpecificTest\NH3386\Entity.cs" />
Expand Down Expand Up @@ -2668,6 +2670,7 @@
<EmbeddedResource Include="NHSpecificTest\NH2195\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3187\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3932\Model\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3985\Mappings.hbm.xml" />
<EmbeddedResource Include="TypedManyToOne\Customer.hbm.xml" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/NHibernate/Impl/SessionImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public sealed class SessionImpl : AbstractSessionImpl, IEventSource, ISerializab
private readonly StatefulPersistenceContext persistenceContext;

[NonSerialized]
private readonly ISession rootSession;
private readonly SessionImpl rootSession;

[NonSerialized]
ISession _childSession;
Expand Down Expand Up @@ -381,6 +381,7 @@ public DbConnection Close()
{
SetClosed();
Cleanup();
if (rootSession != null) rootSession._childSession = null;
}
}
}
Expand Down Expand Up @@ -1681,6 +1682,7 @@ private void Dispose(bool isDisposing)
// free unmanaged resources here

IsAlreadyDisposed = true;

// nothing for Finalizer to do - so tell the GC to ignore it
GC.SuppressFinalize(this);
}
Expand Down

0 comments on commit 4558d53

Please sign in to comment.