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 0e1ca76d6e)
This commit is contained in:
Ronald Barendse
2024-02-02 10:17:40 +01:00
committed by Jacob Overgaard
parent b5b9c13bad
commit 30c1baecd7
11 changed files with 437 additions and 242 deletions

View File

@@ -0,0 +1,42 @@
using Microsoft.Data.Sqlite;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Extensions;
namespace UmbracoProject;
/// <summary>
/// Ensures a SQLite in-memory database is persisted for the whole application duration.
/// </summary>
public sealed class SQLiteMemoryComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
var connectionString = builder.Config.GetUmbracoConnectionString(out var providerName);
if (!string.IsNullOrEmpty(connectionString) &&
Constants.ProviderNames.SQLLite.InvariantEquals(providerName) &&
connectionString.InvariantContains("Mode=Memory"))
{
// Open new SQLite connection to ensure in-memory database is persisted for the whole application duration
var connection = new SqliteConnection(connectionString);
connection.Open();
// And ensure connection is kept open (by keeping a reference) and gets gracefully closed/disposed when application stops
builder.Services.AddHostedService(_ => new SQLiteMemoryHostedService(connection));
}
}
private sealed class SQLiteMemoryHostedService : IHostedService, IAsyncDisposable
{
private readonly SqliteConnection _connection;
public SQLiteMemoryHostedService(SqliteConnection connection) => _connection = connection;
public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
public async Task StopAsync(CancellationToken cancellationToken) => await _connection.CloseAsync();
public async ValueTask DisposeAsync() => await _connection.DisposeAsync();
}
}

View File

@@ -0,0 +1,44 @@
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);
}
}
}

View File

@@ -0,0 +1,13 @@
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Infrastructure;
namespace UmbracoProject;
/// <summary>
/// Suspends/disables scheduled publishing, because that takes an eager write lock every minute, resulting in flaky test runs on SQLite.
/// </summary>
public sealed class SuspendScheduledPublishingComposer : IComposer
{
public void Compose(IUmbracoBuilder builder) => Suspendable.ScheduledPublishing.Suspend();
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<!-- All C# files in the root of this project will be copied to the E2E/Acceptance Test application during build -->
<OutputType>Library</OutputType>
<RootNamespace>UmbracoProject</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Umbraco.Cms\Umbraco.Cms.csproj" />
</ItemGroup>
</Project>