Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ jobs:
with:
connection-string-env-var: ServiceControl_TransportTests_SQL_ConnectionString
catalog: nservicebus
- name: Alias SQL Server connection string for persistence tests
if: matrix.test-category == 'SqlServer'
run: |
$connStr = $env:ServiceControl_TransportTests_SQL_ConnectionString -replace '(?i)(Initial Catalog|Database)=[^;]+', 'Initial Catalog=ServiceControl'
echo "ServiceControl_Persistence_SqlServer_ConnectionString=$connStr" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Setup PostgreSQL
uses: Particular/setup-postgres-action@v1.1.0
if: matrix.test-category == 'PostgreSQL'
Expand All @@ -83,6 +88,9 @@ jobs:
tag: ServiceControl
registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
registry-password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Alias PostgreSQL connection string for persistence tests
if: matrix.test-category == 'PostgreSQL'
run: echo "ServiceControl_Persistence_PostgreSql_ConnectionString=$env:ServiceControl_TransportTests_PostgreSQL_ConnectionString" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Setup RabbitMQ
uses: Particular/setup-rabbitmq-action@v1.7.1
if: matrix.test-category == 'RabbitMQ'
Expand Down
2 changes: 2 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<PackageVersion Include="PropertyChanging.Fody" Version="1.31.0" />
<PackageVersion Include="PublicApiGenerator" Version="11.5.4" />
<PackageVersion Include="RavenDB.Embedded" Version="6.2.17" />
<PackageVersion Include="Testcontainers.MsSql" Version="4.13.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.13.0" />
<PackageVersion Include="ReactiveUI.WPF" Version="22.3.1" />
<PackageVersion Include="Seq.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="ServiceControl.Contracts" Version="5.1.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
<ItemGroup>
<Artifact Include="$(OutputPath)" DestinationFolder="$(ArtifactsPath)Particular.ServiceControl/Persisters/PostgreSQL" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="ServiceControl.Persistence.Tests.PostgreSql" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@
<ItemGroup>
<Artifact Include="$(OutputPath)" DestinationFolder="$(ArtifactsPath)Particular.ServiceControl/Persisters/SQLServer" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="ServiceControl.Persistence.Tests.SqlServer" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@ namespace ServiceControl.Persistence.EFCore.Implementation;

public class ExternalIntegrationRequestsDataStore : IExternalIntegrationRequestsDataStore, IHostedService
{
public void Subscribe(Func<object[], Task> callback) =>
throw new NotImplementedException();
public void Subscribe(Func<object[], Task> callback)
{
//todo:
}


public Task StoreDispatchRequest(IEnumerable<ExternalIntegrationDispatchRequest> dispatchRequests) =>
throw new NotImplementedException();

public Task StartAsync(CancellationToken cancellationToken) =>
throw new NotImplementedException();
public Task StartAsync(CancellationToken cancellationToken)
{
//todo:
return Task.CompletedTask;
}


public Task StopAsync(CancellationToken cancellationToken)
{
//todo:
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken) =>
throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ namespace ServiceControl.Persistence.EFCore.Implementation;

public class FailedMessageViewIndexNotifications : IFailedMessageViewIndexNotifications, IHostedService
{
public IDisposable Subscribe(Func<FailedMessageTotals, Task> callback) =>
throw new NotImplementedException();
public IDisposable Subscribe(Func<FailedMessageTotals, Task> callback)
{
//todo:
return Task.CompletedTask;
}

public Task StartAsync(CancellationToken cancellationToken) =>
throw new NotImplementedException();

public Task StopAsync(CancellationToken cancellationToken) =>
throw new NotImplementedException();
public Task StartAsync(CancellationToken cancellationToken)
{
//todo:
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
{
//todo:
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class PersistenceTestsContext : IPersistenceTestsContext
{
public PersistenceSettings PersistenceSettings { get; private set; }
public string GenerateFailedMessageRecordId(string messageId) => throw new System.NotImplementedException();

public Task Setup(IHostApplicationBuilder hostBuilder)
{
Expand Down
5 changes: 5 additions & 0 deletions src/ServiceControl.Persistence.Tests.PostgreSql/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*.cs]

# Justification: ServiceControl app has no synchronization context
dotnet_diagnostic.CA2007.severity = none

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ReSharper disable once CheckNamespace
namespace ServiceControl.Persistence.Tests;

using System.Threading.Tasks;
using EFCore.PostgreSql;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

public class PersistenceTestsContext : IPersistenceTestsContext
{
public async Task Setup(IHostApplicationBuilder hostBuilder)
{
PersistenceSettings = new PostgreSqlPersisterSettings
{
ConnectionString = await PostgreSqlSharedContainer.GetConnectionStringAsync()
};

var persistence = new PostgreSqlPersistenceConfiguration().Create(PersistenceSettings);

persistence.AddPersistence(hostBuilder.Services);
persistence.AddInstaller(hostBuilder.Services);
}

public async Task PostSetup(IHost host)
{
using var scope = host.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<PostgreSqlServiceControlDbContext>();
await db.Database.EnsureCreatedAsync();
}

public Task TearDown() => Task.CompletedTask;

public void CompleteDatabaseOperation() { }

public PersistenceSettings PersistenceSettings { get; set; }

public string GenerateFailedMessageRecordId(string messageId) => messageId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace ServiceControl.Persistence.Tests;

using System;
using System.Threading;
using System.Threading.Tasks;
using Testcontainers.PostgreSql;

static class PostgreSqlSharedContainer
{
public static async Task<string> GetConnectionStringAsync(CancellationToken ct = default)
{
var envConnStr = Environment.GetEnvironmentVariable("ServiceControl_Persistence_PostgreSql_ConnectionString");
if (!string.IsNullOrEmpty(envConnStr))
{
return envConnStr;
}

if (container != null)
{
return container.GetConnectionString();
}

await semaphore.WaitAsync(ct);
try
{
container ??= await StartContainerAsync(ct);
return container.GetConnectionString();
}
finally
{
semaphore.Release();
}
}

public static async Task Stop() => await (container?.DisposeAsync() ?? ValueTask.CompletedTask);

static async Task<PostgreSqlContainer> StartContainerAsync(CancellationToken ct)
{
var c = new PostgreSqlBuilder("postgres:16-alpine")
.Build();
await c.StartAsync(ct);
return c;
}

static PostgreSqlContainer container;
static readonly SemaphoreSlim semaphore = new(1, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace ServiceControl.Persistence.Tests;

using System.Threading.Tasks;
using EFCore.PostgreSql;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

public class ScratchTestDbLoading : PersistenceTestBase
{
[Test]
public async Task TestDbOperation()
{
using var scope = ServiceProvider.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<PostgreSqlServiceControlDbContext>();

var result = await db.Database.ExecuteSqlAsync($"SELECT 1 as Hello");
Assert.That(result, Is.EqualTo(1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceControl.Infrastructure\ServiceControl.Infrastructure.csproj" />
<ProjectReference Include="..\ServiceControl\ServiceControl.csproj" />
<ProjectReference Include="..\ServiceControl.Persistence.EFCore.PostgreSql\ServiceControl.Persistence.EFCore.PostgreSql.csproj" />
<ProjectReference Include="..\ServiceControl.Transports.Learning\ServiceControl.Transports.Learning.csproj" />
<ProjectReference Include="..\TestHelper\TestHelper.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NServiceBus.Testing" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit.Analyzers" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Particular.Approvals" />
<PackageReference Include="PublicApiGenerator" />
<PackageReference Include="Testcontainers.PostgreSql" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\ServiceControl.Persistence.Tests\**\*.cs" LinkBase="Shared" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ServiceControl;

using System.Threading.Tasks;
using NUnit.Framework;
using Persistence.Tests;

[SetUpFixture]
public class StopSharedPostgreSql
{
[OneTimeTearDown]
public async Task Teardown() => await PostgreSqlSharedContainer.Stop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//Don't apply the test category yet - we are currently failing the tests while building
//[assembly: IncludeInTestCategory("PostgreSQL")]
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public async Task PostSetup(IHost host)
public async Task TearDown() => await embeddedServer.DeleteDatabase(databaseName);

public PersistenceSettings PersistenceSettings { get; private set; }
public string GenerateFailedMessageRecordId(string messageId) => FailedMessageIdGenerator.MakeDocumentId(messageId);

public IDocumentStore DocumentStore { get; private set; }

Expand Down
5 changes: 5 additions & 0 deletions src/ServiceControl.Persistence.Tests.SqlServer/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*.cs]

# Justification: ServiceControl app has no synchronization context
dotnet_diagnostic.CA2007.severity = none

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ReSharper disable once CheckNamespace
namespace ServiceControl.Persistence.Tests;

using System.Threading.Tasks;
using EFCore.SqlServer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

public class PersistenceTestsContext : IPersistenceTestsContext
{
public async Task Setup(IHostApplicationBuilder hostBuilder)
{
PersistenceSettings = new SqlServerPersisterSettings
{
ConnectionString = await SqlServerSharedContainer.GetConnectionStringAsync()
};

var persistence = new SqlServerPersistenceConfiguration().Create(PersistenceSettings);

persistence.AddPersistence(hostBuilder.Services);
persistence.AddInstaller(hostBuilder.Services);
}

public async Task PostSetup(IHost host)
{
using var scope = host.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SqlServerServiceControlDbContext>();
await db.Database.EnsureCreatedAsync();
}

public Task TearDown() => Task.CompletedTask;

public void CompleteDatabaseOperation() { }

public PersistenceSettings PersistenceSettings { get; set; }

public string GenerateFailedMessageRecordId(string messageId) => messageId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace ServiceControl.Persistence.Tests;

using System.Threading.Tasks;
using EFCore.SqlServer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

public class ScratchTestDbLoading : PersistenceTestBase
{
[Test]
public async Task TestDbOperation()
{
using var scope = ServiceProvider.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<SqlServerServiceControlDbContext>();

var result = await db.Database.ExecuteSqlAsync($"SELECT 1 as Hello");
Assert.That(result, Is.EqualTo(-1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceControl.Infrastructure\ServiceControl.Infrastructure.csproj" />
<ProjectReference Include="..\ServiceControl\ServiceControl.csproj" />
<ProjectReference Include="..\ServiceControl.Persistence.EFCore.SqlServer\ServiceControl.Persistence.EFCore.SqlServer.csproj" />
<ProjectReference Include="..\ServiceControl.Transports.Learning\ServiceControl.Transports.Learning.csproj" />
<ProjectReference Include="..\TestHelper\TestHelper.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NServiceBus.Testing" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit.Analyzers" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Particular.Approvals" />
<PackageReference Include="PublicApiGenerator" />
<PackageReference Include="Testcontainers.MsSql" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\ServiceControl.Persistence.Tests\**\*.cs" LinkBase="Shared" />
</ItemGroup>

</Project>
Loading
Loading