Skip to content

Commit 755acae

Browse files
committed
try to reproduce #1645 to no avail
1 parent 2c82cf1 commit 755acae

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/Tests/Elasticsearch.Net.Tests.Unit/ConnectionPools/Sniffing/SniffingConnectionPoolTests.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,78 @@ public void ShouldRetryOnSniffConnectionException_Async()
443443
}
444444
}
445445

446+
[Test]
447+
public async Task ShouldRetryOnSniffConnectionException_Async_NoSugar()
448+
{
449+
using (var fake = new AutoFake(callsDoNothing: true))
450+
{
451+
var uris = new[]
452+
{
453+
new Uri("http://localhost:9200"),
454+
new Uri("http://localhost:9201"),
455+
new Uri("http://localhost:9202")
456+
};
457+
var connectionPool = new SniffingConnectionPool(uris, randomizeOnStartup: false);
458+
var config = new ConnectionConfiguration(connectionPool)
459+
.SniffOnConnectionFault();
460+
461+
fake.Provide<IConnectionConfigurationValues>(config);
462+
463+
var pingAsyncCall = FakeCalls.PingAtConnectionLevelAsync(fake);
464+
pingAsyncCall.Returns(FakeResponse.OkAsync(config));
465+
466+
//sniffing is always synchronous and in turn will issue synchronous pings
467+
var pingCall = FakeCalls.PingAtConnectionLevel(fake);
468+
pingCall.Returns(FakeResponse.Ok(config));
469+
470+
var sniffCall = FakeCalls.Sniff(fake);
471+
var seenPorts = new List<int>();
472+
sniffCall.ReturnsLazily((Uri u, IRequestConfiguration c) =>
473+
{
474+
seenPorts.Add(u.Port);
475+
throw new Exception("Something bad happened");
476+
});
477+
478+
var getCall = FakeCalls.GetCall(fake);
479+
getCall.Returns(FakeResponse.BadAsync(config));
480+
481+
FakeCalls.ProvideDefaultTransport(fake);
482+
483+
var client = fake.Resolve<ElasticsearchClient>();
484+
485+
MaxRetryException exception = null;
486+
try
487+
{
488+
await client.NodesHotThreadsAsync("nodex");
489+
}
490+
catch (MaxRetryException e)
491+
{
492+
exception = e;
493+
}
494+
495+
//all nodes must be tried to sniff for more information
496+
sniffCall.MustHaveHappened(Repeated.Exactly.Times(uris.Count()));
497+
//make sure we only saw one call to hot threads (the one that failed initially)
498+
getCall.MustHaveHappened(Repeated.Exactly.Once);
499+
500+
//make sure the sniffs actually happened on all the individual nodes
501+
seenPorts.ShouldAllBeEquivalentTo(uris.Select(u=>u.Port));
502+
exception.Should().NotBeNull();
503+
exception.InnerException.Message.Should().Contain("Sniffing known nodes");
504+
505+
ArgumentException ae = null;
506+
try
507+
{
508+
await client.NodesHotThreadsAsync(null);
509+
}
510+
catch (ArgumentException e)
511+
{
512+
ae = e;
513+
}
514+
ae.Should().NotBeNull();
515+
}
516+
}
517+
446518
[Test]
447519
public void ShouldRetryOnSniffConnectionException()
448520
{

0 commit comments

Comments
 (0)