Skip to content
Merged
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
12 changes: 8 additions & 4 deletions .github/workflows/cloud-database-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ jobs:
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.plan.outputs.targets) }}
# The two suites that exercise the persister. Named outright rather than selected by test
# category, because the category also carries the transport tests, which test the queue
# transport against its own connection string and have no business running here.
# The suites that exercise the primary and audit persisters. Named outright rather than
# selected by test category, because the category also carries the transport tests, which test
# the queue transport against its own connection string and have no business running here.
env:
PERSISTENCE_PROJECT: src/ServiceControl.Persistence.Tests.${{ matrix.provider }}/ServiceControl.Persistence.Tests.${{ matrix.provider }}.csproj
ACCEPTANCE_PROJECT: src/ServiceControl.AcceptanceTests.${{ matrix.provider }}/ServiceControl.AcceptanceTests.${{ matrix.provider }}.csproj
AUDIT_PERSISTENCE_PROJECT: src/ServiceControl.Audit.Persistence.Tests.${{ matrix.provider }}/ServiceControl.Audit.Persistence.Tests.${{ matrix.provider }}.csproj
AUDIT_ACCEPTANCE_PROJECT: src/ServiceControl.Audit.AcceptanceTests.${{ matrix.provider }}/ServiceControl.Audit.AcceptanceTests.${{ matrix.provider }}.csproj
steps:
- name: Check for secrets
env:
Expand Down Expand Up @@ -104,6 +106,8 @@ jobs:
run: |
dotnet build $Env:PERSISTENCE_PROJECT --configuration Release
dotnet build $Env:ACCEPTANCE_PROJECT --configuration Release
dotnet build $Env:AUDIT_PERSISTENCE_PROJECT --configuration Release
dotnet build $Env:AUDIT_ACCEPTANCE_PROJECT --configuration Release
- name: Azure login
uses: azure/login@v3.1.0
if: startsWith(matrix.target, 'azure-')
Expand Down Expand Up @@ -134,7 +138,7 @@ jobs:
- name: Run tests
uses: Particular/run-tests-action@v1.9.0
with:
projects: ${{ env.PERSISTENCE_PROJECT }};${{ env.ACCEPTANCE_PROJECT }}
projects: ${{ env.PERSISTENCE_PROJECT }};${{ env.ACCEPTANCE_PROJECT }};${{ env.AUDIT_PERSISTENCE_PROJECT }};${{ env.AUDIT_ACCEPTANCE_PROJECT }}
max-parallel: 2
env:
ServiceControl_TESTS_FILTER: ${{ matrix.provider }}
Expand Down
2 changes: 2 additions & 0 deletions src/ProjectReferences.Persisters.Audit.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project>

<ItemGroup Label="Persisters">
<ProjectReference Include="..\ServiceControl.Audit.Persistence.EFCore.PostgreSql\ServiceControl.Audit.Persistence.EFCore.PostgreSql.csproj" ReferenceOutputAssembly="false" Private="false" />
<ProjectReference Include="..\ServiceControl.Audit.Persistence.EFCore.SqlServer\ServiceControl.Audit.Persistence.EFCore.SqlServer.csproj" ReferenceOutputAssembly="false" Private="false" />
<ProjectReference Include="..\ServiceControl.Audit.Persistence.RavenDB\ServiceControl.Audit.Persistence.RavenDB.csproj" ReferenceOutputAssembly="false" Private="false" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*.cs]

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.PS0018.severity = none
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace ServiceControl.Audit.AcceptanceTests.PostgreSql;

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ServiceControl.Audit.AcceptanceTests.TestSupport;
using ServiceControl.Audit.Persistence.EFCore.Abstractions;
using ServiceControl.Persistence.Tests;

public class AcceptanceTestStorageConfiguration : IAcceptanceTestStorageConfiguration
{
public string PersistenceType { get; } = "PostgreSQL";

public async Task<IDictionary<string, string>> CustomizeSettings(CancellationToken cancellationToken = default)
{
var schema = $"sc_at_{Guid.NewGuid():n}";

connectionString = await PostgreSqlSharedContainer.GetConnectionStringAsync(cancellationToken);
await TestSchema.Create(connectionString, schema, cancellationToken);

schemas.Add(schema);

return new Dictionary<string, string>
{
[EFPersistenceConfigurationBase.ConnectionStringKey] = connectionString,
[EFPersistenceConfigurationBase.SchemaKey] = schema
};
}

public async Task Cleanup(CancellationToken cancellationToken = default)
{
while (schemas.TryTake(out var schema))
{
await TestSchema.Drop(connectionString, schema, cancellationToken);
}
}

// The runner holds this lock while it writes the persister settings to the process-wide AppSettings.
public async Task<IDisposable> UseDatabaseLifecycleLock(CancellationToken cancellationToken = default)
{
await initializationLock.WaitAsync(cancellationToken);
return new Release();
}

sealed class Release : IDisposable
{
public void Dispose() => initializationLock.Release();
}

static readonly SemaphoreSlim initializationLock = new(1, 1);
readonly ConcurrentBag<string> schemas = [];
string connectionString;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<Using Include="ServiceControl.Audit.AcceptanceTests.PostgreSql" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceControl.AcceptanceTesting\ServiceControl.AcceptanceTesting.csproj" />
<ProjectReference Include="..\ServiceControl.Audit\ServiceControl.Audit.csproj" />
<ProjectReference Include="..\ServiceControl.Audit.Persistence.EFCore.PostgreSql\ServiceControl.Audit.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.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NServiceBus.SagaAudit" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit.Analyzers" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Testcontainers.PostgreSql" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\ServiceControl.Audit.AcceptanceTests\**\*.cs" Exclude="..\ServiceControl.Audit.AcceptanceTests\obj\**\*.*;..\ServiceControl.Audit.AcceptanceTests\bin\**\*.*" LinkBase="Shared" />
<Compile Include="..\ServiceControl.Persistence.Tests.PostgreSql\PostgreSqlSharedContainer.cs" />
<Compile Include="..\ServiceControl.Persistence.Tests.PostgreSql\TestSchema.cs" />
<Compile Include="..\ServiceControl.Persistence.Tests.PostgreSql\StopSharedPostgreSql.cs" />

<!-- The EF Core persisters always index bodies for full text search, whatever EnableFullTextSearchOnBodies says. -->
<Compile Remove="..\ServiceControl.Audit.AcceptanceTests\Auditing\When_processed_message_searched_by_body_content.FullTextSearchDisabled.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[*.cs]

# Justification: Test project
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.PS0018.severity = none
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace ServiceControl.Audit.AcceptanceTests.SqlServer;

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ServiceControl.Audit.AcceptanceTests.TestSupport;
using ServiceControl.Audit.Persistence.EFCore.Abstractions;
using ServiceControl.Persistence.Tests;

public class AcceptanceTestStorageConfiguration : IAcceptanceTestStorageConfiguration
{
public string PersistenceType { get; } = "SQLServer";

public async Task<IDictionary<string, string>> CustomizeSettings(CancellationToken cancellationToken = default)
{
var schema = $"sc_at_{Guid.NewGuid():n}";

connectionString = await SqlServerSharedContainer.GetConnectionStringAsync(cancellationToken);
await TestSchema.Create(connectionString, schema, cancellationToken);

schemas.Add(schema);

return new Dictionary<string, string>
{
[EFPersistenceConfigurationBase.ConnectionStringKey] = connectionString,
[EFPersistenceConfigurationBase.SchemaKey] = schema
};
}

public async Task Cleanup(CancellationToken cancellationToken = default)
{
while (schemas.TryTake(out var schema))
{
await TestSchema.Drop(connectionString, schema, cancellationToken);
}
}

// The runner holds this lock while it writes the persister settings to the process-wide AppSettings.
public async Task<IDisposable> UseDatabaseLifecycleLock(CancellationToken cancellationToken = default)
{
await initializationLock.WaitAsync(cancellationToken);
return new Release();
}

sealed class Release : IDisposable
{
public void Dispose() => initializationLock.Release();
}

static readonly SemaphoreSlim initializationLock = new(1, 1);
readonly ConcurrentBag<string> schemas = [];
string connectionString;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<Using Include="ServiceControl.Audit.AcceptanceTests.SqlServer" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceControl.AcceptanceTesting\ServiceControl.AcceptanceTesting.csproj" />
<ProjectReference Include="..\ServiceControl.Audit\ServiceControl.Audit.csproj" />
<ProjectReference Include="..\ServiceControl.Audit.Persistence.EFCore.SqlServer\ServiceControl.Audit.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.AspNetCore.Mvc.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NServiceBus.SagaAudit" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit.Analyzers" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Testcontainers.MsSql" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\ServiceControl.Audit.AcceptanceTests\**\*.cs" Exclude="..\ServiceControl.Audit.AcceptanceTests\obj\**\*.*;..\ServiceControl.Audit.AcceptanceTests\bin\**\*.*" LinkBase="Shared" />
<Compile Include="..\ServiceControl.Persistence.Tests.SqlServer\SqlServerSharedContainer.cs" />
<Compile Include="..\ServiceControl.Persistence.Tests.SqlServer\TestSchema.cs" />
<Compile Include="..\ServiceControl.Persistence.Tests.SqlServer\StopSharedSqlServer.cs" />

<!-- The EF Core persisters always index bodies for full text search, whatever EnableFullTextSearchOnBodies says. -->
<Compile Remove="..\ServiceControl.Audit.AcceptanceTests\Auditing\When_processed_message_searched_by_body_content.FullTextSearchDisabled.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace ServiceControl.Audit.AcceptanceTests.Auditing
{
using System.Threading.Tasks;
using AcceptanceTesting;
using Audit.Auditing.MessagesView;
using NServiceBus;
using NServiceBus.AcceptanceTesting;
using NUnit.Framework;

partial class When_processed_message_searched_by_body_content
{
[Test]
public async Task Should_not_be_found_when_fulltext_search_disabled()
{
SetSettings = settings => settings.EnableFullTextSearchOnBodies = false;

var searchString = "forty-two";

var context = await Define<MyContext>()
.WithEndpoint<Sender>(b => b.When((bus, c) => bus.Send(new MyMessage
{
Something = "Somewhere in the body is the answer to all of the questions. forty-two"
})))
.WithEndpoint<Receiver>()
.Done(async c =>
{
if (c.MessageId != null && await this.TryGetMany<MessagesView>($"/api/messages/search/{c.MessageId}"))
{
c.MessageIngested = true;
}

if (!c.MessageIngested)
{
return false;
}

c.MessageFound = await this.TryGetMany<MessagesView>($"/api/messages/search/{searchString}");
return true;
})
.Run();

using (Assert.EnterMultipleScope())
{
Assert.That(context.MessageIngested, Is.True);
Assert.That(context.MessageFound, Is.False);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using NServiceBus.AcceptanceTesting.Customization;
using NUnit.Framework;

class When_processed_message_searched_by_body_content : AcceptanceTest
partial class When_processed_message_searched_by_body_content : AcceptanceTest
{
[Test]
public async Task Should_be_found_when_fulltext_search_enabled()
Expand Down Expand Up @@ -44,43 +44,6 @@ public async Task Should_be_found_when_fulltext_search_enabled()
Assert.That(context.MessageFound, Is.True);
}

[Test]
public async Task Should_not_be_found_when_fulltext_search_disabled()
{
SetSettings = settings => settings.EnableFullTextSearchOnBodies = false;

var searchString = "forty-two";

var context = await Define<MyContext>()
.WithEndpoint<Sender>(b => b.When((bus, c) => bus.Send(new MyMessage
{
Something = "Somewhere in the body is the answer to all of the questions. forty-two"
})))
.WithEndpoint<Receiver>()
.Done(async c =>
{
if (c.MessageId != null && await this.TryGetMany<MessagesView>($"/api/messages/search/{c.MessageId}"))
{
c.MessageIngested = true;
}

if (!c.MessageIngested)
{
return false;
}

c.MessageFound = await this.TryGetMany<MessagesView>($"/api/messages/search/{searchString}");
return true;
})
.Run();

using (Assert.EnterMultipleScope())
{
Assert.That(context.MessageIngested, Is.True);
Assert.That(context.MessageFound, Is.False);
}
}

public class Sender : EndpointConfigurationBuilder
{
public Sender() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[*.cs]

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

# Disable style rules for auto-generated EF migrations
[Migrations/**.cs]
dotnet_diagnostic.IDE0065.severity = none
generated_code = true
Loading
Loading