Files
natsdotnet/tests/NATS.E2E.Tests/GatewayTests.cs
Joseph Doherty 338f44b07b test: add E2E gateway tests (cross-gateway messaging, interest-only)
- GatewayFixture: polls /gatewayz monitoring endpoint until both servers
  report num_gateways >= 1, replacing Task.Delay with proper synchronization
- GatewayTests: two tests covering cross-gateway delivery and interest-only
  no-delivery behaviour, using double PingAsync() instead of Task.Delay
- LeafNodeTests: replace Task.Delay(500) with sub.PingAsync()+pub.PingAsync()
  to properly fence subscription propagation without timing dependencies
- Fix GatewayManager.StartAsync to read remotes from RemoteGateways (config-
  parsed) in addition to the legacy Remotes list, enabling config-file-driven
  outbound gateway connections
2026-03-12 19:45:54 -04:00

51 lines
1.8 KiB
C#

using NATS.Client.Core;
using NATS.E2E.Tests.Infrastructure;
namespace NATS.E2E.Tests;
[Collection("E2E-Gateway")]
public class GatewayTests(GatewayFixture fixture)
{
[Fact]
public async Task Gateway_MessageCrossesGateway()
{
await using var pub = fixture.CreateClientA();
await using var sub = fixture.CreateClientB();
await pub.ConnectAsync();
await sub.ConnectAsync();
await using var subscription = await sub.SubscribeCoreAsync<string>("e2e.gw.cross");
// Ping both sides: subscriber's ping flushes the SUB to server B,
// publisher's ping ensures server A has received the propagated interest.
await sub.PingAsync();
await pub.PingAsync();
await pub.PublishAsync("e2e.gw.cross", "gateway-msg");
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var msg = await subscription.Msgs.ReadAsync(cts.Token);
msg.Data.ShouldBe("gateway-msg");
}
[Fact]
public async Task Gateway_NoInterest_NoDelivery()
{
await using var pub = fixture.CreateClientA();
await using var sub = fixture.CreateClientB();
await pub.ConnectAsync();
await sub.ConnectAsync();
await using var subscription = await sub.SubscribeCoreAsync<string>("e2e.gw.listen");
// Ping both sides to ensure subscription interest has propagated before publishing.
await sub.PingAsync();
await pub.PingAsync();
await pub.PublishAsync("e2e.gw.nolisten", "should-not-arrive");
await pub.PublishAsync("e2e.gw.listen", "should-arrive");
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
var msg = await subscription.Msgs.ReadAsync(cts.Token);
msg.Data.ShouldBe("should-arrive");
}
}