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.
47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
// Copyright 2012-2025 The NATS Authors
|
|
// Licensed under the Apache License, Version 2.0
|
|
|
|
using NATS.Client.Core;
|
|
|
|
namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers;
|
|
|
|
/// <summary>
|
|
/// Helper for creating NATS client connections in integration tests.
|
|
/// Wraps NATS.Client.Core connection setup.
|
|
/// </summary>
|
|
public sealed class NatsTestClient : IAsyncDisposable
|
|
{
|
|
private readonly NatsConnection _connection;
|
|
|
|
private NatsTestClient(NatsConnection connection)
|
|
{
|
|
_connection = connection;
|
|
}
|
|
|
|
public NatsConnection Connection => _connection;
|
|
|
|
/// <summary>
|
|
/// Connects to a NATS server at the given URL.
|
|
/// </summary>
|
|
public static async Task<NatsTestClient> Connect(string url)
|
|
{
|
|
var opts = new NatsOpts { Url = url };
|
|
var conn = new NatsConnection(opts);
|
|
await conn.ConnectAsync();
|
|
return new NatsTestClient(conn);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Connects to the local NATS server at its default port (for stub tests).
|
|
/// </summary>
|
|
public static async Task<NatsTestClient> ConnectToServer(string serverUrl)
|
|
{
|
|
return await Connect(serverUrl);
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
await _connection.DisposeAsync();
|
|
}
|
|
}
|