Skip to content

Commit 30be383

Browse files
committed
post #2753 backport fixes of cancellationtoken being on request data, also backported Node equals fixes from master/5.x
1 parent 95a787c commit 30be383

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

src/Elasticsearch.Net/Auditing/AuditEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public enum AuditEvent
1818

1919
MaxTimeoutReached,
2020
MaxRetriesReached,
21-
BadRequest
21+
BadRequest,
2222
CancellationRequested,
2323
}
2424
}

src/Elasticsearch.Net/Connection/HttpConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public virtual async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(
191191
try
192192
{
193193
var request = this.CreateHttpWebRequest(requestData);
194-
cancellationToken.Register(()=>request.Abort());
194+
requestData.CancellationToken.Register(()=>request.Abort());
195195
var data = requestData.PostData;
196196

197197
if (data != null)

src/Elasticsearch.Net/ConnectionPool/Node.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ public Node Clone() =>
8484
HttpEnabled = this.HttpEnabled
8585
};
8686

87+
public static bool operator ==(Node left, Node right) =>
88+
ReferenceEquals(left, null) ? ReferenceEquals(right, null) : left.Equals(right);
8789

88-
// ReSharper disable once PossibleNullReferenceException
89-
public static bool operator ==(Node left, Node right) => left.Equals(right);
90-
91-
// ReSharper disable once PossibleNullReferenceException
92-
public static bool operator !=(Node left, Node right) => !left.Equals(right);
90+
public static bool operator !=(Node left, Node right) => !(left == right);
9391

9492
public static implicit operator Node(Uri uri) => new Node(uri);
9593

@@ -110,5 +108,6 @@ public override bool Equals(object obj)
110108
}
111109

112110
public override int GetHashCode() => this.Uri.GetHashCode();
111+
113112
}
114113
}

src/Elasticsearch.Net/Transport/Transport.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace Elasticsearch.Net
88
public class Transport<TConnectionSettings> : ITransport<TConnectionSettings>
99
where TConnectionSettings : IConnectionConfigurationValues
1010
{
11-
//TODO should all of these be public?
11+
//TODO should all of these be public?
1212
public TConnectionSettings Settings { get; }
13-
public IDateTimeProvider DateTimeProvider { get; }
14-
public IMemoryStreamFactory MemoryStreamFactory { get; }
15-
public IRequestPipelineFactory PipelineProvider { get; }
13+
public IDateTimeProvider DateTimeProvider { get; }
14+
public IMemoryStreamFactory MemoryStreamFactory { get; }
15+
public IRequestPipelineFactory PipelineProvider { get; }
1616

1717
/// <summary>
1818
/// Transport coordinates the client requests over the connection pool nodes and is in charge of falling over on different nodes
@@ -152,11 +152,11 @@ public async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(HttpMeth
152152
AuditTrail = pipeline.AuditTrail
153153
};
154154
}
155-
if (cancellationToken.IsCancellationRequested)
156-
{
157-
pipeline.AuditCancellationRequested();
158-
break;
159-
}
155+
if (requestData.CancellationToken.IsCancellationRequested)
156+
{
157+
pipeline.AuditCancellationRequested();
158+
break;
159+
}
160160
if (response == null || !response.SuccessOrKnownError) continue;
161161
pipeline.MarkAlive(node);
162162
break;

src/Tests/Reproduce/GithubIssue2751.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class GithubIssue2751: IClusterFixture<ReadOnlyCluster>
2424
* the response from /project/project/_search to 5 seconds. See this issue's accompanying PR.
2525
*/
2626

27-
//[I]
27+
[I]
2828
public async Task TimeoutOfRequestReturnsResponse()
2929
{
3030
var client = TestClient.GetClient(modifySettings: c => c.RequestTimeout(TimeSpan.FromSeconds(2)));
@@ -52,7 +52,7 @@ public async Task TimeoutOfRequestReturnsResponse()
5252
//cancelling an async request should behave differently
5353
stopwatch.Restart();
5454
var ctx = new CancellationTokenSource();
55-
var task = client.SearchAsync<Project>(s=>s, ctx.Token);
55+
var task = client.SearchAsync<Project>(s=>s.RequestConfiguration(r=>r.CancellationToken(ctx.Token)));
5656
await Task.Delay(100);
5757
ctx.Cancel();
5858
response = await task;
@@ -67,7 +67,7 @@ public async Task TimeoutOfRequestReturnsResponse()
6767
response.ApiCall.AuditTrail.Should().Contain(a=> a.Event == AuditEvent.CancellationRequested);
6868
}
6969

70-
//[I]
70+
[I]
7171
public async Task UserCancellationDoesNotCauseFailOverToNextNode()
7272
{
7373
//this tests assumes only a single node is running under 9200 and fiddler is set up to artificially delay results
@@ -76,7 +76,7 @@ public async Task UserCancellationDoesNotCauseFailOverToNextNode()
7676
modifySettings: c => c.RequestTimeout(TimeSpan.FromSeconds(2)));
7777

7878
var ctx = new CancellationTokenSource();
79-
var task = client.SearchAsync<Project>(s=>s, ctx.Token);
79+
var task = client.SearchAsync<Project>(s=>s.RequestConfiguration(r=>r.CancellationToken(ctx.Token)));
8080
await Task.Delay(100);
8181
ctx.Cancel();
8282
var response = await task;

0 commit comments

Comments
 (0)