test(batch50): port 118 JetStream cluster 1 integration tests
Ports the first 118 tests from golang/nats-server/server/jetstream_cluster_1_test.go to C# integration tests in JetStream/JetStreamCluster1Tests.cs. Adds the Helpers/ scaffold (IntegrationTestBase, TestCluster, NatsTestClient, CheckHelper, ConfigHelper) and Xunit.SkippableFact package; tests skip automatically unless NATS_INTEGRATION_TESTS=true is set.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// Copyright 2020-2025 The NATS Authors
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
|
||||
namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Provides polling-based check utilities for integration tests,
|
||||
/// mirroring the Go <c>checkFor</c> pattern.
|
||||
/// </summary>
|
||||
public static class CheckHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Polls <paramref name="check"/> every <paramref name="interval"/> until it returns
|
||||
/// <c>null</c> (success) or <paramref name="timeout"/> elapses. Throws on timeout.
|
||||
/// </summary>
|
||||
public static void CheckFor(TimeSpan timeout, TimeSpan interval, Func<string?> check)
|
||||
{
|
||||
var deadline = DateTime.UtcNow + timeout;
|
||||
string? lastError = null;
|
||||
while (DateTime.UtcNow < deadline)
|
||||
{
|
||||
lastError = check();
|
||||
if (lastError is null)
|
||||
return;
|
||||
Thread.Sleep(interval);
|
||||
}
|
||||
throw new TimeoutException($"CheckFor timed out after {timeout}: {lastError}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Async variant of <see cref="CheckFor"/>.
|
||||
/// </summary>
|
||||
public static async Task CheckForAsync(TimeSpan timeout, TimeSpan interval, Func<Task<string?>> check)
|
||||
{
|
||||
var deadline = DateTime.UtcNow + timeout;
|
||||
string? lastError = null;
|
||||
while (DateTime.UtcNow < deadline)
|
||||
{
|
||||
lastError = await check();
|
||||
if (lastError is null)
|
||||
return;
|
||||
await Task.Delay(interval);
|
||||
}
|
||||
throw new TimeoutException($"CheckFor timed out after {timeout}: {lastError}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user