Skip to content

Commit

Permalink
Add fix for void async batches
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 29, 2015
1 parent a642c1f commit 5fea7da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ServiceStack/Host/Handlers/ServiceStackHandlerBase.cs
Expand Up @@ -84,7 +84,9 @@ public Task HandleResponse(object response, Func<object, Task> callback, Func<Ex
return callback(new object[0]);
var firstResponse = taskResults[0].GetResult();
var batchedResponses = (object[])Array.CreateInstance(firstResponse.GetType(), taskResults.Length);
var batchedResponses = firstResponse != null
? (object[])Array.CreateInstance(firstResponse.GetType(), taskResults.Length)
: new object[taskResults.Length];
batchedResponses[0] = firstResponse;
for (var i = 1; i < taskResults.Length; i++)
{
Expand Down
30 changes: 29 additions & 1 deletion tests/ServiceStack.WebHost.Endpoints.Tests/ReplyAllTests.cs
Expand Up @@ -43,7 +43,7 @@ public override void Execute(IRequest req, IResponse res, object requestDto)

public static void AssertSingleDto(object dto)
{
if (!(dto is BatchThrows || dto is BatchThrowsAsync || dto is NoRepeat || dto is HelloAll || dto is HelloAllAsync || dto is HelloAllVoid || dto is HelloGet || dto is HelloAllCustom || dto is HelloAllTransaction || dto is Request))
if (!(dto is BatchThrows || dto is BatchThrowsAsync || dto is NoRepeat || dto is HelloAll || dto is HelloAllAsync || dto is HelloAllVoid || dto is HelloAllVoidAsync || dto is HelloGet || dto is HelloAllCustom || dto is HelloAllTransaction || dto is Request))
throw new Exception("Invalid " + dto.GetType().Name);
}
}
Expand Down Expand Up @@ -99,6 +99,13 @@ public class HelloAllVoid : IReturnVoid
public string Name { get; set; }
}

public class HelloAllVoidAsync : IReturnVoid
{
public static int Counter;

public string Name { get; set; }
}

public class HelloGet : IReturn<HelloAllResponse>
{
public string Name { get; set; }
Expand Down Expand Up @@ -164,6 +171,12 @@ public void Any(HelloAllVoid request)
HelloAllVoid.Counter++;
}

public async Task Any(HelloAllVoidAsync request)
{
HelloAllVoidAsync.Counter++;
await Task.FromResult(0);
}

[ReplyAllRequest]
[ReplyAllResponse]
public object Any(HelloAllCustom request)
Expand Down Expand Up @@ -439,6 +452,21 @@ public void Can_send_multi_HelloAllVoid()
client.SendAllOneWay(requests);
}

[Test]
public void Can_send_multi_HelloAllVoidAsync()
{
var client = CreateClient(Config.AbsoluteBaseUri);

var requests = new[]
{
new HelloAllVoidAsync { Name = "Foo" },
new HelloAllVoidAsync { Name = "Bar" },
new HelloAllVoidAsync { Name = "Baz" },
};

client.SendAllOneWay(requests);
}

[Test]
public void Can_send_single_HelloAllCustom_request()
{
Expand Down

0 comments on commit 5fea7da

Please sign in to comment.