Skip to content

Commit 07bc7a6

Browse files
committed
added async response types tests to make sure they behave the same as their synchronous counterparts
1 parent de25456 commit 07bc7a6

File tree

4 files changed

+592
-12
lines changed

4 files changed

+592
-12
lines changed

src/Elasticsearch.Net/Connection/Transport.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@ private Task<ElasticsearchResponse<T>> StreamToTypedResponseAsync<T>(Elasticsear
565565

566566
var cs = ElasticsearchResponse.CloneFrom<T>(streamResponse, default(T));
567567

568-
var memoryStream = new MemoryStream();
569568
if (typeof(T) == typeof(VoidResponse))
570569
{
571570
tcs.SetResult(cs);
@@ -574,17 +573,19 @@ private Task<ElasticsearchResponse<T>> StreamToTypedResponseAsync<T>(Elasticsear
574573
return tcs.Task;
575574
}
576575

577-
var type = typeof(T);
578-
if (!(this.Settings.KeepRawResponse || type == typeof(string) || type == typeof(byte[])))
576+
if (!(this.Settings.KeepRawResponse || this.TypeOfResponseCopiesDirectly<T>()))
579577
return _deserializeAsyncToResponse(streamResponse.Response, deserializationState, cs);
580578

579+
var memoryStream = new MemoryStream();
581580
return this.Iterate(this.ReadStreamAsync(streamResponse.Response, memoryStream), memoryStream)
582581
.ContinueWith(t =>
583582
{
584583
var readStream = t.Result;
585584
readStream.Position = 0;
586585
var bytes = readStream.ToArray();
587586
cs.ResponseRaw = this.Settings.KeepRawResponse ? bytes : null;
587+
588+
var type = typeof(T);
588589
if (type == typeof(string))
589590
{
590591
this.SetStringResult(cs as ElasticsearchResponse<string>, bytes);

src/Elasticsearch.Net/Serialization/ElasticsearchDefaultSerializer.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,7 @@ public T Deserialize<T>(Stream stream)
3131
public Task<T> DeserializeAsync<T>(Stream stream)
3232
{
3333
var tcs = new TaskCompletionSource<T>();
34-
T r;
35-
var ms = stream as MemoryStream;
36-
if (ms != null)
37-
{
38-
r = SimpleJson.DeserializeObject<T>(ms.GetBuffer().Utf8String());
39-
tcs.SetResult(r);
40-
return tcs.Task;
41-
}
42-
using (ms = new MemoryStream())
34+
using (var ms = new MemoryStream())
4335
{
4436
// return a task that reads the stream asynchronously
4537
// and finally deserializes the result to T.

0 commit comments

Comments
 (0)