Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/Particular.LicensingComponent.UnitTests/NUnitSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using NUnit.Framework;

[assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
[assembly: Parallelizable(ParallelScope.All)]
[assembly: LevelOfParallelism(4)]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading;
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTesting.Customization;
using NServiceBus.Logging;
using NUnit.Framework;
using NUnit.Framework.Internal;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
namespace ServiceControl.AcceptanceTests
namespace ServiceControl.AcceptanceTests.RavenDB;

using System;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
using ServiceBus.Management.Infrastructure.Settings;
using ServiceControl.Persistence.Tests;
using ServiceControl.RavenDB;

public class AcceptanceTestStorageConfiguration
{
using System;
using System.Threading.Tasks;
using Persistence.Tests;
using ServiceBus.Management.Infrastructure.Settings;
using ServiceControl.RavenDB;
public string PersistenceType { get; } = "RavenDB";


public class AcceptanceTestStorageConfiguration
public async Task CustomizeSettings(Settings settings)
{
public string PersistenceType { get; } = "RavenDB";
databaseName = Guid.NewGuid().ToString("n");
databaseInstance = await SharedEmbeddedServer.GetInstance();

public async Task CustomizeSettings(Settings settings)
settings.PersisterSpecificSettings = new RavenPersisterSettings
{
databaseName = Guid.NewGuid().ToString("n");
databaseInstance = await SharedEmbeddedServer.GetInstance();

settings.PersisterSpecificSettings = new RavenPersisterSettings
{
ErrorRetentionPeriod = TimeSpan.FromDays(10),
ConnectionString = databaseInstance.ServerUrl,
DatabaseName = databaseName
};
}
ErrorRetentionPeriod = TimeSpan.FromDays(10),
ConnectionString = databaseInstance.ServerUrl,
DatabaseName = databaseName
};
}

public async Task Cleanup()
public async Task Cleanup()
{
if (databaseInstance == null)
{
if (databaseInstance == null)
{
return;
}
await databaseInstance.DeleteDatabase(databaseName);
return;
}
using var _ = await UseDatabaseLifecycleLock();
await databaseInstance.DeleteDatabase(databaseName);
}

EmbeddedDatabase databaseInstance;
string databaseName;
/// <summary>
/// The shared server cannot perform database lifecycle operations in parallel, take this lock when you
/// need to do one of these operations in a test.
/// </summary>
public static async Task<IDisposable> UseDatabaseLifecycleLock(CancellationToken cancellationToken = default)
{
await databaseLifecycleLock.WaitAsync(cancellationToken);
return Disposable.Create(() => databaseLifecycleLock.Release());
}
}

static readonly SemaphoreSlim databaseLifecycleLock = new SemaphoreSlim(1, 1);
EmbeddedDatabase databaseInstance;
string databaseName;
}
5 changes: 5 additions & 0 deletions src/ServiceControl.AcceptanceTests.RavenDB/NUnitSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using NUnit.Framework;

[assembly: FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
[assembly: Parallelizable(ParallelScope.All)]
[assembly: LevelOfParallelism(4)]
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using NUnit.Framework;
using ServiceControl.MessageFailures;
using ServiceControl.Recoverability;
using TestSupport;

class When_a_failed_message_is_retried : AcceptanceTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using ServiceControl.MessageFailures;
using Conventions = NServiceBus.AcceptanceTesting.Customization.Conventions;

[NonParallelizable]
class When_a_message_fails_to_import : AcceptanceTest
{
[Test]
Expand Down
29 changes: 29 additions & 0 deletions src/ServiceControl.AcceptanceTests.RavenDB/SetupFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace ServiceControl.AcceptanceTests.RavenDB;

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;

[SetUpFixture]
public class SetupFixture
{
[OneTimeSetUp]
public async Task Setup()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
ServiceBus.Management.Infrastructure.Installers.EventSourceCreator.Create();

//There is a delay for this becoming true, tests will fall over if they interleave in the wrong way.
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
while (!EventLog.SourceExists(ServiceBus.Management.Infrastructure.Installers.EventSourceCreator.SourceName))
{
cts.Token.ThrowIfCancellationRequested();
await Task.Delay(500, CancellationToken.None);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using ServiceControl.Operations;

[TestFixture]
[NonParallelizable]
class When_a_critical_error_is_triggered : AcceptanceTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ServiceControl.AcceptanceTests.Security.Cors
/// When AllowAnyOrigin is true (default for backwards compatibility), requests from any origin should be allowed.
/// The Access-Control-Allow-Origin header should be "*".
/// </summary>
[NonParallelizable]
class When_cors_allows_any_origin : AcceptanceTest
{
CorsTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ServiceControl.AcceptanceTests.Security.Cors
/// When AllowAnyOrigin is false and no AllowedOrigins are configured, CORS is effectively disabled.
/// No Access-Control-Allow-Origin header should be returned for any origin.
/// </summary>
[NonParallelizable]
class When_cors_is_disabled : AcceptanceTest
{
CorsTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ServiceControl.AcceptanceTests.Security.Cors
/// When a request comes from an origin that is in the AllowedOrigins list,
/// the response should include the Access-Control-Allow-Origin header with that specific origin.
/// </summary>
[NonParallelizable]
class When_request_from_allowed_origin : AcceptanceTest
{
CorsTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ServiceControl.AcceptanceTests.Security.Cors
/// When a request comes from an origin that is NOT in the AllowedOrigins list,
/// the response should NOT include an Access-Control-Allow-Origin header that matches the request origin.
/// </summary>
[NonParallelizable]
class When_request_from_disallowed_origin : AcceptanceTest
{
CorsTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Forwarded Headers Disabled
/// When forwarded headers processing is disabled, headers should be ignored regardless of trust.
/// </summary>
[NonParallelizable]
class When_forwarded_headers_are_disabled : AcceptanceTest
{
ForwardedHeadersTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Default Behavior with Headers
/// When forwarded headers are sent and TrustAllProxies is true (default), headers should be applied.
/// </summary>
[NonParallelizable]
class When_forwarded_headers_are_sent : AcceptanceTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Known Networks (CIDR)
/// When KnownNetworks are configured and the caller IP falls within, headers should be applied.
/// </summary>
[NonParallelizable]
class When_known_networks_are_configured : AcceptanceTest
{
ForwardedHeadersTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Known Proxies Only
/// When KnownProxies are configured and the caller IP matches, headers should be applied.
/// </summary>
[NonParallelizable]
class When_known_proxies_are_configured : AcceptanceTest
{
ForwardedHeadersTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// When TrustAllProxies is true and headers contain multiple values (proxy chain),
/// the original (leftmost) values should be returned.
/// </summary>
[NonParallelizable]
class When_multiple_header_values_are_sent : AcceptanceTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// When TrustAllProxies=false (known proxies configured), ForwardLimit=1,
/// so only the rightmost values are processed.
/// </summary>
[NonParallelizable]
class When_multiple_header_values_are_sent_with_known_proxies : AcceptanceTest
{
ForwardedHeadersTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Partial Headers (Proto Only)
/// When only X-Forwarded-Proto is sent, only scheme should change.
/// </summary>
[NonParallelizable]
class When_only_proto_header_is_sent : AcceptanceTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// When TrustAllProxies is true and X-Forwarded-For contains multiple IPs (proxy chain),
/// the original client IP (first in the chain) should be returned.
/// </summary>
[NonParallelizable]
class When_proxy_chain_headers_are_sent : AcceptanceTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Proxy Chain with Known Proxies (ForwardLimit=1)
/// When TrustAllProxies=false (known proxies configured), ForwardLimit=1, so only the last proxy IP is processed.
/// </summary>
[NonParallelizable]
class When_proxy_chain_headers_are_sent_with_known_proxies : AcceptanceTest
{
ForwardedHeadersTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Direct Access (No Proxy)
/// When no forwarded headers are sent, the request values should remain unchanged.
/// </summary>
[NonParallelizable]
class When_request_has_no_forwarded_headers : AcceptanceTest
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// When TrustAllProxies is explicitly configured via environment variable, headers should be applied.
/// This test verifies the WithTrustAllProxies() configuration method works correctly.
/// </summary>
[NonParallelizable]
class When_trust_all_proxies_is_explicitly_configured : AcceptanceTest
{
ForwardedHeadersTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Unknown Network Rejected
/// When KnownNetworks are configured but the caller IP does NOT fall within, headers should be ignored.
/// </summary>
[NonParallelizable]
class When_unknown_network_sends_headers : AcceptanceTest
{
ForwardedHeadersTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ServiceControl.AcceptanceTests.Security.ForwardedHeaders
/// Unknown Proxy Rejected
/// When KnownProxies are configured but the caller IP does NOT match, headers should be ignored.
/// </summary>
[NonParallelizable]
class When_unknown_proxy_sends_headers : AcceptanceTest
{
ForwardedHeadersTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace ServiceControl.AcceptanceTests.Security.Https
/// In acceptance tests (which run in Development mode), HSTS headers are not sent.
/// This test verifies that HSTS is correctly NOT applied in development mode.
/// </summary>
[NonParallelizable]
class When_hsts_is_configured_in_development_mode : AcceptanceTest
{
HttpsTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ServiceControl.AcceptanceTests.Security.Https
/// HTTPS Redirect Disabled (Default)
/// When RedirectHttpToHttps is false (default), HTTP requests should not be redirected.
/// </summary>
[NonParallelizable]
class When_https_redirect_is_disabled : AcceptanceTest
{
HttpsTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace ServiceControl.AcceptanceTests.Security.Https
/// HTTPS Redirect Enabled
/// When RedirectHttpToHttps is true, HTTP requests should be redirected to HTTPS.
/// </summary>
[NonParallelizable]
class When_https_redirect_is_enabled : AcceptanceTest
{
HttpsTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace ServiceControl.AcceptanceTests.Security.OpenIdConnect
/// When Authentication.Enabled is false (default), all API endpoints should be accessible
/// without authentication. Requests should not require Bearer tokens.
/// </summary>
[NonParallelizable]
class When_authentication_is_disabled : AcceptanceTest
{
OpenIdConnectTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace ServiceControl.AcceptanceTests.Security.OpenIdConnect
/// This test uses a mock OIDC server to provide discovery endpoints and signing keys,
/// allowing full testing of the JWT Bearer authentication flow.
/// </summary>
[NonParallelizable]
class When_authentication_is_enabled : AcceptanceTest
{
OpenIdConnectTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace ServiceControl.AcceptanceTests.Security.OpenIdConnect;
/// It is the per-instance authorization contract ServicePulse consumes: it gates UI on routes it
/// already calls rather than on the server's internal permission vocabulary.
/// </summary>
[NonParallelizable]
class When_my_routes_are_requested : AcceptanceTest
{
OpenIdConnectTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace ServiceControl.AcceptanceTests.Security.OpenIdConnect
/// endpoint should return the overridden authority for ServicePulse to use instead of the
/// main authority URL.
/// </summary>
[NonParallelizable]
class When_service_pulse_authority_override_is_configured : AcceptanceTest
{
OpenIdConnectTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace ServiceControl.AcceptanceTests.Security.OpenIdConnect
/// string returned by the authentication configuration endpoint should omit offline_access,
/// so ServicePulse does not request a scope the identity provider disallows.
/// </summary>
[NonParallelizable]
class When_service_pulse_offline_access_scope_is_disabled : AcceptanceTest
{
OpenIdConnectTestConfiguration configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace ServiceControl.AcceptanceTests
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTesting.Support;
using NUnit.Framework;
using RavenDB;
using ServiceBus.Management.Infrastructure.Settings;
using ServiceControl.AcceptanceTesting.InfrastructureConfig;
using TestSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace ServiceControl.AcceptanceTests.TestSupport
using Microsoft.Extensions.Hosting;
using NServiceBus;
using NServiceBus.AcceptanceTesting.Support;
using RavenDB;
using ServiceBus.Management.Infrastructure.Settings;

class ServiceControlComponentBehavior : IComponentBehavior, IAcceptanceTestInfrastructureProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
using NServiceBus.AcceptanceTesting.Support;
using Particular.ServiceControl;
using Particular.ServiceControl.Hosting;
using Persistence.Tests;
using RavenDB;
using RavenDB.Shared;
using ServiceBus.Management.Infrastructure.Settings;
using ServiceControl.Infrastructure;
Expand All @@ -47,9 +49,13 @@ public ServiceControlComponentRunner(ITransportIntegration transportToUse, Accep
public JsonSerializerOptions SerializerOptions => Infrastructure.WebApi.SerializerOptions.Default;
public IDomainEvents DomainEvents { get; private set; }

public Task Initialize(RunDescriptor run) => InitializeServiceControl(run.ScenarioContext);
public async Task Initialize(RunDescriptor run)
{
using var _ = await AcceptanceTestStorageConfiguration.UseDatabaseLifecycleLock();
await InitializeServiceControlCore(run.ScenarioContext);
}

async Task InitializeServiceControl(ScenarioContext context)
async Task InitializeServiceControlCore(ScenarioContext context)
{
var logPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(logPath);
Expand Down
Loading
Loading