Skip to content

Commit

Permalink
Connect auth test subscriber sync fix (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmk authored Aug 11, 2023
1 parent 920a3ef commit 638e2d3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/NATS.Client.Core.Tests/NatsConnectionTest.Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,23 @@ public async Task UserCredentialAuthTest(string name, string serverConfig, NatsO
var signalComplete1 = new WaitSignal();
var signalComplete2 = new WaitSignal();

var syncCount = 0;
var natsSub = await subConnection.SubscribeAsync<int>(subject);
var register = natsSub.Register(x =>
{
Interlocked.Increment(ref syncCount);
_output.WriteLine($"Received: {x}");
if (x.Data == 1)
signalComplete1.Pulse();
if (x.Data == 2)
signalComplete2.Pulse();
});

await subConnection.PingAsync(); // wait for subscribe complete
var syncCount1 = Volatile.Read(ref syncCount);
await Retry.Until(
"subscribed",
() => syncCount1 != Volatile.Read(ref syncCount),
async () => await pubConnection.PublishAsync(subject, 0));

_output.WriteLine("AUTHENTICATED CONNECTION");
await pubConnection.PublishAsync(subject, 1);
Expand All @@ -146,6 +152,13 @@ public async Task UserCredentialAuthTest(string name, string serverConfig, NatsO
await pubConnection.ConnectAsync(); // wait open again

_output.WriteLine("AUTHENTICATED RE-CONNECTION");

var syncCount2 = Volatile.Read(ref syncCount);
await Retry.Until(
"re-subscribed",
() => syncCount2 != Volatile.Read(ref syncCount),
async () => await pubConnection.PublishAsync(subject, 0));

await pubConnection.PublishAsync(subject, 2);
await signalComplete2;

Expand Down

0 comments on commit 638e2d3

Please sign in to comment.