-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug #450: Re-enable using connection pooling by default for SQL server (
#451)
- Loading branch information
Showing
7 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
unittests/SqlServer/Running_MigrationScripts/Real_world_issues.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using grate.Configuration; | ||
using grate.Migration; | ||
using TestCommon.Generic.Running_MigrationScripts; | ||
using TestCommon.TestInfrastructure; | ||
using static grate.Configuration.KnownFolderKeys; | ||
|
||
namespace SqlServer.Running_MigrationScripts; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
/// <summary> | ||
/// Issues that have been encountered in the real world. | ||
/// Create tests to reproduce the issue and then fix the issue, and keep the test to ensure it doesn't regress. | ||
/// </summary> | ||
[Collection(nameof(SqlServerTestContainer))] | ||
public class Real_world_issues(IGrateTestContext context, ITestOutputHelper testOutput) : MigrationsScriptsBase(context, testOutput) | ||
{ | ||
private const string Bug232Sql = @" | ||
ALTER DATABASE {{DatabaseName}} SET ALLOW_SNAPSHOT_ISOLATION ON; | ||
ALTER DATABASE {{DatabaseName}} SET READ_COMMITTED_SNAPSHOT ON"; | ||
|
||
/// <summary> | ||
/// Regression in 1.4.0 made us disable connection pooling if not explicitly set in the connection string. | ||
/// however, this makes connections a lot slower, especially if using Azure AD authentication, where obtaining | ||
/// the token takes a while. Disabling pooling means we have to get the token every time we open a connection, | ||
/// as the connection is actually closed, not just returned to the pool. | ||
/// | ||
/// To run the "RunAfterCreateDatabase" scripts in its own transaction from the command line, use the following: | ||
/// | ||
/// --folders=runAfterCreateDatabase=transactionHandling:autonomous | ||
/// | ||
/// </summary> | ||
/// <exception cref="Exception"></exception> | ||
[Fact] | ||
public async Task Bug232_Timeout_v1U002E4U002E0_Regression() | ||
{ | ||
// V1.4 regressed something, trying to repro | ||
|
||
var db = TestConfig.RandomDatabase(); | ||
|
||
var parent = CreateRandomTempDirectory(); | ||
var knownFolders = FoldersConfiguration.Default(); | ||
|
||
// Use autonomous transactions for the RunAfterCreateDatabase folder makes this work without having to | ||
// disable connection pooling | ||
knownFolders[RunAfterCreateDatabase] = knownFolders[RunAfterCreateDatabase]! with { TransactionHandling = TransactionHandling.Autonomous }; | ||
|
||
var path = new DirectoryInfo(Path.Combine(parent.ToString(), knownFolders[RunAfterCreateDatabase]?.Path ?? throw new Exception("Config Fail"))); | ||
|
||
WriteSql(path, "token.sql", Bug232Sql); | ||
|
||
var config = GrateConfigurationBuilder.Create(Context.DefaultConfiguration) | ||
.WithConnectionString(Context.ConnectionString(db)) | ||
.WithFolders(knownFolders) | ||
.WithSqlFilesDirectory(parent) | ||
.Build(); | ||
|
||
await using (var migrator = Context.Migrator.WithConfiguration(config)) | ||
{ | ||
await migrator.Migrate(); | ||
} | ||
|
||
// Now drop it and do it again | ||
config = config with | ||
{ | ||
Drop = true | ||
}; | ||
|
||
await using (var migrator = Context.Migrator.WithConfiguration(config)) | ||
{ | ||
await migrator.Migrate(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters