Skip to content

Commit 96ac0d3

Browse files
NH-4026 - Firebird locks table till connection are actually closed, not only returned to pool. Clearing the pool as a solution.
1 parent 704c122 commit 96ac0d3

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/NHibernate.Test/NHSpecificTest/NH1908ThreadSafety/Fixture.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading;
5-
using NHibernate.Util;
5+
using NHibernate.Dialect;
66
using NUnit.Framework;
77

88
namespace NHibernate.Test.NHSpecificTest.NH1908ThreadSafety
@@ -12,29 +12,12 @@ public class Fixture : BugTestCase
1212
{
1313
protected override bool AppliesTo(Dialect.Dialect dialect)
1414
{
15-
return !(dialect is Dialect.Oracle8iDialect);
15+
return !(dialect is Oracle8iDialect);
1616
// Oracle sometimes causes: ORA-12520: TNS:listener could not find available handler for requested type of server
1717
// Following links bizarrely suggest it's an Oracle limitation under load:
1818
// http://www.orafaq.com/forum/t/60019/2/ & http://www.ispirer.com/wiki/sqlways/troubleshooting-guide/oracle/import/tns_listener
1919
}
2020

21-
protected override void OnTearDown()
22-
{
23-
base.OnTearDown();
24-
25-
if (!(Dialect is Dialect.FirebirdDialect))
26-
return;
27-
28-
// Firebird will pool each connection created during the test and will not drop the created tables
29-
// which will result in other tests failing when they try to create tables with same name
30-
// By clearing the connection pool the tables will get dropped. This is done by the following code.
31-
var fbConnectionType = ReflectHelper.TypeFromAssembly("FirebirdSql.Data.FirebirdClient.FbConnection", "FirebirdSql.Data.FirebirdClient", false);
32-
var clearPool = fbConnectionType.GetMethod("ClearPool");
33-
var sillyConnection = Sfi.ConnectionProvider.GetConnection();
34-
clearPool.Invoke(null, new object[] { sillyConnection });
35-
Sfi.ConnectionProvider.CloseConnection(sillyConnection);
36-
}
37-
3821
[Test]
3922
public void UsingFiltersIsThreadSafe()
4023
{

src/NHibernate.Test/TestCase.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using NHibernate.Hql.Ast.ANTLR;
1515
using NUnit.Framework.Interfaces;
1616
using System.Text;
17+
using NHibernate.Dialect;
18+
using NHibernate.Util;
1719

1820
namespace NHibernate.Test
1921
{
@@ -269,6 +271,27 @@ protected virtual void CreateSchema()
269271

270272
protected virtual void DropSchema()
271273
{
274+
if (Dialect is FirebirdDialect)
275+
{
276+
// Firebird will pool each connection created during the test and will marked as used any table
277+
// referenced by queries. It will at best delays those tables drop until connections are actually
278+
// closed, or immediately fail dropping them.
279+
// This results in other tests failing when they try to create tables with same name.
280+
// By clearing the connection pool the tables will get dropped. This is done by the following code.
281+
// Moved from NH1908 test case, contributed by Amro El-Fakharany.
282+
var clearConnection = Sfi.ConnectionProvider.GetConnection();
283+
try
284+
{
285+
var fbConnectionType = clearConnection.GetType();
286+
var clearPool = fbConnectionType.GetMethod("ClearPool");
287+
clearPool.Invoke(null, new object[] {clearConnection});
288+
}
289+
finally
290+
{
291+
Sfi.ConnectionProvider.CloseConnection(clearConnection);
292+
}
293+
}
294+
272295
new SchemaExport(cfg).Drop(OutputDdl, true);
273296
}
274297

0 commit comments

Comments
 (0)