Skip to content

Commit

Permalink
Reconnect On Connect Unit Test (#855)
Browse files Browse the repository at this point in the history
scottf authored Jan 16, 2024
1 parent 53e876a commit bf6e49f
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/Tests/IntegrationTests/TestReconnect.cs
Original file line number Diff line number Diff line change
@@ -12,12 +12,12 @@
// limitations under the License.

using System;
using NATS.Client;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Collections.Generic;
using NATS.Client;
using Xunit;

namespace IntegrationTests
@@ -644,6 +644,37 @@ public void TestReconnectDelayJitterOptions()
Assert.True(opts.ReconnectJitter == Defaults.ReconnectJitter);
Assert.True(opts.ReconnectJitterTLS == Defaults.ReconnectJitterTLS);
}


[Fact]
public void TestMaxReconnectOnConnect()
{
Options opts = Context.GetTestOptions(Context.Server1.Port);
opts.AllowReconnect = true;
opts.MaxReconnect = 60;

CountdownEvent latch = new CountdownEvent(1);
IConnection connection = null;
Thread t = new Thread(() =>
{
Assert.Null(connection);
Thread.Sleep(2000);
Assert.Null(connection);

using (NATSServer s1 = NATSServer.Create(Context.Server1.Port))
{
latch.Wait(2000);
Assert.NotNull(connection);
Assert.Equal(ConnState.CONNECTED, connection.State);
}
});
t.Start();

connection = Context.ConnectionFactory.CreateConnection(opts, true);
latch.Signal();

t.Join(5000);
}
}

public class TestPublishErrorsDuringReconnect : TestSuite<PublishErrorsDuringReconnectSuiteContext>

0 comments on commit bf6e49f

Please sign in to comment.