Ports 51 tests from norace_1_test.go and 24 tests from norace_2_test.go
as [SkippableFact] integration tests. Creates test harness infrastructure
(IntegrationTestBase, CheckHelper, NatsTestClient, TestServerHelper,
TestCluster) and tags all tests with [Trait("Category", "NoRace")].
Tests skip unless NATS_INTEGRATION_ENABLED=true is set.
68 lines
2.7 KiB
C#
68 lines
2.7 KiB
C#
// Copyright 2012-2025 The NATS Authors
|
|
// Licensed under the Apache License, Version 2.0
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers;
|
|
|
|
/// <summary>
|
|
/// Stub helper for creating multi-server NATS clusters in integration tests.
|
|
/// In the Go test suite, this corresponds to createJetStreamCluster(t, numServers, name) and
|
|
/// createJetStreamSuperCluster(t, numClusters, numServersPerCluster).
|
|
///
|
|
/// This stub is a placeholder until cluster orchestration is implemented.
|
|
/// Tests using this helper will skip unless NATS_INTEGRATION_ENABLED=true.
|
|
/// </summary>
|
|
public sealed class TestCluster : IDisposable
|
|
{
|
|
private readonly ITestOutputHelper _output;
|
|
|
|
/// <summary>Number of servers in the cluster.</summary>
|
|
public int ServerCount { get; }
|
|
|
|
/// <summary>Cluster name.</summary>
|
|
public string Name { get; }
|
|
|
|
/// <summary>URL of a random server in the cluster (stub returns the default URL).</summary>
|
|
public string RandomServerUrl =>
|
|
Environment.GetEnvironmentVariable("NATS_TEST_SERVER_URL") ?? "nats://localhost:4222";
|
|
|
|
private TestCluster(ITestOutputHelper output, int serverCount, string name)
|
|
{
|
|
_output = output;
|
|
ServerCount = serverCount;
|
|
Name = name;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a stub JetStream cluster. Throws NotSupportedException when integration is disabled.
|
|
/// Corresponds to createJetStreamCluster(t, numServers, name) in Go tests.
|
|
/// </summary>
|
|
public static TestCluster CreateJetStreamCluster(int numServers, string name, ITestOutputHelper output)
|
|
{
|
|
if (!IntegrationTestBase.IntegrationEnabled)
|
|
throw new NotSupportedException(IntegrationTestBase.SkipMessage);
|
|
|
|
output.WriteLine($"Creating JetStream cluster '{name}' with {numServers} servers (stub)");
|
|
return new TestCluster(output, numServers, name);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a stub JetStream super-cluster.
|
|
/// Corresponds to createJetStreamSuperCluster(t, numClusters, numServers) in Go tests.
|
|
/// </summary>
|
|
public static TestCluster CreateJetStreamSuperCluster(int numClusters, int numServersPerCluster, ITestOutputHelper output)
|
|
{
|
|
if (!IntegrationTestBase.IntegrationEnabled)
|
|
throw new NotSupportedException(IntegrationTestBase.SkipMessage);
|
|
|
|
output.WriteLine($"Creating JetStream super-cluster with {numClusters} clusters x {numServersPerCluster} servers (stub)");
|
|
return new TestCluster(output, numClusters * numServersPerCluster, $"SuperCluster({numClusters}x{numServersPerCluster})");
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_output.WriteLine($"Shutting down cluster '{Name}'");
|
|
}
|
|
}
|