Skip to content

Commit 6dac072

Browse files
NH-4026 - clearing the pool for allowing table drop.
1 parent 704c122 commit 6dac072

File tree

2 files changed

+24
-19
lines changed

2 files changed

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

275297
protected virtual DebugSessionFactory BuildSessionFactory()

0 commit comments

Comments
 (0)