Skip to content

Commit 763ac99

Browse files
JaBistDuNarrischJaBistDuNarrisch
authored andcommitted
Dispose Postgre connection
1 parent f2dee95 commit 763ac99

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Migrator.Tests/Providers/Base/TransformationProviderBase.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Data;
23
using System.Threading;
34
using System.Threading.Tasks;
45
using DotNetProjects.Migrator.Framework;
@@ -13,6 +14,7 @@
1314
using Migrator.Tests.Settings;
1415
using Migrator.Tests.Settings.Config;
1516
using Migrator.Tests.Settings.Models;
17+
using Npgsql;
1618
using NUnit.Framework;
1719

1820
namespace Migrator.Tests.Providers.Base;
@@ -22,13 +24,24 @@ namespace Migrator.Tests.Providers.Base;
2224
/// </summary>
2325
public abstract class TransformationProviderBase
2426
{
27+
private IDbConnection _dbConnection;
28+
2529
[TearDown]
2630
public virtual void TearDown()
2731
{
2832
DropTestTables();
2933

3034
Provider?.Rollback();
31-
Provider?.Dispose();
35+
36+
if (_dbConnection != null)
37+
{
38+
if (_dbConnection.State == ConnectionState.Open)
39+
{
40+
_dbConnection.Close();
41+
}
42+
43+
_dbConnection.Dispose();
44+
}
3245
}
3346

3447
protected void DropTestTables()
@@ -109,7 +122,10 @@ protected async Task BeginPostgreSQLTransactionAsync()
109122
var postgreIntegrationTestService = databaseIntegrationTestServiceFactory.Create(DatabaseProviderType.Postgres);
110123
var databaseInfo = await postgreIntegrationTestService.CreateTestDatabaseAsync(databaseConnectionConfig, cts.Token);
111124

112-
Provider = new PostgreSQLTransformationProvider(new PostgreSQLDialect(), databaseInfo.DatabaseConnectionConfig.ConnectionString, null, "default", "Npgsql");
125+
126+
_dbConnection = new NpgsqlConnection(databaseInfo.DatabaseConnectionConfig.ConnectionString);
127+
128+
Provider = new PostgreSQLTransformationProvider(new PostgreSQLDialect(), _dbConnection, null, "default", "Npgsql");
113129
Provider.BeginTransaction();
114130

115131
await Task.CompletedTask;

0 commit comments

Comments
 (0)