Skip to content

Commit 1f55f46

Browse files
griffitdhazzik
authored andcommitted
NH-2176 - Add test case
1 parent 0041b52 commit 1f55f46

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Transactions;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.NH2176
6+
{
7+
[TestFixture]
8+
public class Fixture : BugTestCase
9+
{
10+
protected override void OnSetUp()
11+
{
12+
base.OnSetUp();
13+
using (var s = OpenSession())
14+
using (var tx = s.BeginTransaction())
15+
{
16+
var steve = new Person {Name = "Steve"};
17+
var peter = new Person {Name = "Peter"};
18+
var simon = new Person {Name = "Simon"};
19+
var paul = new Person {Name = "Paul"};
20+
var john = new Person {Name = "John"};
21+
var eric = new Person {Name = "Eric"};
22+
23+
s.Save(steve);
24+
s.Save(peter);
25+
s.Save(simon);
26+
s.Save(paul);
27+
s.Save(john);
28+
s.Save(eric);
29+
30+
tx.Commit();
31+
}
32+
}
33+
34+
protected override void OnTearDown()
35+
{
36+
base.OnTearDown();
37+
using (var s = OpenSession())
38+
using (var tx = s.BeginTransaction())
39+
{
40+
s.Delete("from Person");
41+
tx.Commit();
42+
}
43+
}
44+
45+
// Whilst this bug seems specific to Oracle I think it is valid to run the
46+
// test against all database types.
47+
[Test]
48+
public void MultipleConsecutiveTransactionScopesCanBeUsedInsideASingleSession()
49+
{
50+
using (var s = OpenSession())
51+
{
52+
// usually fails after just a few loops in oracle
53+
// this can be run for 10000 loops in sql server without problem
54+
for (var i = 0; i < 100; ++i)
55+
{
56+
Console.WriteLine(i.ToString());
57+
58+
using (var scope = new TransactionScope())
59+
{
60+
var criteria = s.CreateCriteria<Person>();
61+
var people = criteria.List<Person>();
62+
63+
Assert.That(people.Count, Is.EqualTo(6));
64+
65+
scope.Complete();
66+
}
67+
68+
// The exeption is caused by a race condition between two threads.
69+
// This can be demonstracted by uncommenting the following line which
70+
// causes the test to run without an exception.
71+
//System.Threading.Thread.Sleep(1000);
72+
}
73+
}
74+
}
75+
}
76+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
namespace="NHibernate.Test.NHSpecificTest.NH2176"
4+
assembly="NHibernate.Test"
5+
>
6+
<class name="Person" table="NH2176_Person">
7+
8+
<id name="Id" column="PersonId">
9+
<generator class="identity"/>
10+
</id>
11+
12+
<property name="Name" column="Name" />
13+
14+
</class>
15+
</hibernate-mapping>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH2176
2+
{
3+
public class Person
4+
{
5+
public virtual int Id { get; set; }
6+
public virtual string Name { get; set; }
7+
}
8+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@
791791
<Compile Include="NHSpecificTest\NH3564\FixtureByCode.cs" />
792792
<Compile Include="NHSpecificTest\NH3583\Entity.cs" />
793793
<Compile Include="NHSpecificTest\NH3583\AutoFlushFixture.cs" />
794+
<Compile Include="NHSpecificTest\NH2176\Fixture.cs" />
795+
<Compile Include="NHSpecificTest\NH2176\Model.cs" />
794796
<Compile Include="NHSpecificTest\NH3372\Entity.cs" />
795797
<Compile Include="NHSpecificTest\NH3372\Fixture.cs" />
796798
<Compile Include="NHSpecificTest\NH3453\Classes.cs" />
@@ -3258,6 +3260,7 @@
32583260
<EmbeddedResource Include="NHSpecificTest\NH3666\Mappings.hbm.xml">
32593261
<SubType>Designer</SubType>
32603262
</EmbeddedResource>
3263+
<EmbeddedResource Include="NHSpecificTest\NH2176\Mappings.hbm.xml" />
32613264
<EmbeddedResource Include="VersionTest\Db\MsSQL\ProductWithVersionAndLazyProperty.hbm.xml" />
32623265
<EmbeddedResource Include="NHSpecificTest\NH3754\Mappings.hbm.xml" />
32633266
<EmbeddedResource Include="NHSpecificTest\NH3800\Mappings.hbm.xml">

0 commit comments

Comments
 (0)