Skip to content

Commit bf6e49f

Browse files
authored
Reconnect On Connect Unit Test (#855)
1 parent 53e876a commit bf6e49f

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

Diff for: src/Tests/IntegrationTests/TestReconnect.cs

+34-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// limitations under the License.
1313

1414
using System;
15-
using NATS.Client;
15+
using System.Collections.Generic;
16+
using System.Diagnostics;
1617
using System.Text;
1718
using System.Threading;
1819
using System.Threading.Tasks;
19-
using System.Diagnostics;
20-
using System.Collections.Generic;
20+
using NATS.Client;
2121
using Xunit;
2222

2323
namespace IntegrationTests
@@ -644,6 +644,37 @@ public void TestReconnectDelayJitterOptions()
644644
Assert.True(opts.ReconnectJitter == Defaults.ReconnectJitter);
645645
Assert.True(opts.ReconnectJitterTLS == Defaults.ReconnectJitterTLS);
646646
}
647+
648+
649+
[Fact]
650+
public void TestMaxReconnectOnConnect()
651+
{
652+
Options opts = Context.GetTestOptions(Context.Server1.Port);
653+
opts.AllowReconnect = true;
654+
opts.MaxReconnect = 60;
655+
656+
CountdownEvent latch = new CountdownEvent(1);
657+
IConnection connection = null;
658+
Thread t = new Thread(() =>
659+
{
660+
Assert.Null(connection);
661+
Thread.Sleep(2000);
662+
Assert.Null(connection);
663+
664+
using (NATSServer s1 = NATSServer.Create(Context.Server1.Port))
665+
{
666+
latch.Wait(2000);
667+
Assert.NotNull(connection);
668+
Assert.Equal(ConnState.CONNECTED, connection.State);
669+
}
670+
});
671+
t.Start();
672+
673+
connection = Context.ConnectionFactory.CreateConnection(opts, true);
674+
latch.Signal();
675+
676+
t.Join(5000);
677+
}
647678
}
648679

649680
public class TestPublishErrorsDuringReconnect : TestSuite<PublishErrorsDuringReconnectSuiteContext>

0 commit comments

Comments
 (0)