Files
Umbraco-CMS/tests/Umbraco.Tests.AcceptanceTest.UmbracoProject/SqlServerDelayedDurabilityComposer.cs

45 lines
1.9 KiB
C#
Raw Normal View History

Remove Linux only Docker build for E2E tests (#14042) * Remove Linux only Docker build for E2E tests * Fix cmsVersion variable * Remove custom build number step (already done by Nerdbank.GitVersioning) * Add and use global.json to configure .NET SDK version * Only publish tests build output * Only include unit tests and integration build output (without reference assemblies) * Added "pr: none" to nightly trigger (#15044) * Only run SQL Server Acceptance Tests on release builds or when parameter is set * Use SQLite in-memory database and configure database optimizations (#15461) * Disable content version cleanup and server election * Reference Umbraco.Tests.AcceptanceTest.UmbracoProject instead of copying files * Suspend/disable scheduled publishing * Ensure all Playwright results are copied to the artifact staging directory * Update E2E SQL Server job and also run on Linux * Fix building acceptance test project * Fix building acceptance test project (suing PrivateAssets) * Explicitly disable building project references in E2E tests and use pre-built output * Include obj folder of acceptance test project in build artifacts * Download build artifacts * Re-add PrivateAssets * Revert to copying C# files to E2E application * Disable Integrated Security for SQL Server on Linux * Update SQL Server on Linux connection string * Disable encryption on SQL Server for Linux * Update SQL Server on Linux steps * Add Database to SQL Server connection string on Linux * Update Integration Tests and use SQL Server 2022 Docker image --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk> (cherry picked from commit 0e1ca76d6e5b50d83a9b76779c11e0bd9ae3f6ca)
2024-02-02 10:17:40 +01:00
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Extensions;
namespace UmbracoProject;
/// <summary>
/// Disable waiting on log IO to finish when commiting a transaction (we can tolerate some data loss) on SQL Server.
/// </summary>
public sealed class SqlServerDelayedDurabilityComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
var connectionString = builder.Config.GetUmbracoConnectionString(out var providerName);
if (!string.IsNullOrEmpty(connectionString) &&
Constants.ProviderNames.SQLServer.InvariantEquals(providerName))
{
builder.AddNotificationAsyncHandler<UnattendedInstallNotification, SqlServerDelayedDurabilityInstallNotification>();
}
}
private sealed class SqlServerDelayedDurabilityInstallNotification : INotificationAsyncHandler<UnattendedInstallNotification>
{
private readonly IOptions<ConnectionStrings> _connectionStrings;
public SqlServerDelayedDurabilityInstallNotification(IOptions<ConnectionStrings> connectionStrings) => _connectionStrings = connectionStrings;
public async Task HandleAsync(UnattendedInstallNotification notification, CancellationToken cancellationToken)
{
using var connection = new SqlConnection(_connectionStrings.Value.ConnectionString);
await connection.OpenAsync(cancellationToken);
// Disable waiting on log IO to finish when commiting a transaction (we can tolerate some data loss)
var command = new SqlCommand("ALTER DATABASE CURRENT SET DELAYED_DURABILITY = FORCED;", connection);
await command.ExecuteNonQueryAsync(cancellationToken);
}
}
}