Skip to content
Snippets Groups Projects
Commit e458d846 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

dont create dedicated threads for async client

parent 26cc1427
No related branches found
No related tags found
No related merge requests found
...@@ -142,8 +142,7 @@ namespace Grpc.IntegrationTesting ...@@ -142,8 +142,7 @@ namespace Grpc.IntegrationTesting
for (int i = 0; i < outstandingRpcsPerChannel; i++) for (int i = 0; i < outstandingRpcsPerChannel; i++)
{ {
var timer = CreateTimer(loadParams, 1.0 / this.channels.Count / outstandingRpcsPerChannel); var timer = CreateTimer(loadParams, 1.0 / this.channels.Count / outstandingRpcsPerChannel);
var threadBody = GetThreadBody(channel, timer); this.runnerTasks.Add(RunClientAsync(channel, timer));
this.runnerTasks.Add(Task.Factory.StartNew(threadBody, TaskCreationOptions.LongRunning));
} }
} }
} }
...@@ -269,38 +268,30 @@ namespace Grpc.IntegrationTesting ...@@ -269,38 +268,30 @@ namespace Grpc.IntegrationTesting
} }
} }
private Action GetThreadBody(Channel channel, IInterarrivalTimer timer) private Task RunClientAsync(Channel channel, IInterarrivalTimer timer)
{ {
if (payloadConfig.PayloadCase == PayloadConfig.PayloadOneofCase.BytebufParams) if (payloadConfig.PayloadCase == PayloadConfig.PayloadOneofCase.BytebufParams)
{ {
GrpcPreconditions.CheckArgument(clientType == ClientType.ASYNC_CLIENT, "Generic client only supports async API"); GrpcPreconditions.CheckArgument(clientType == ClientType.ASYNC_CLIENT, "Generic client only supports async API");
GrpcPreconditions.CheckArgument(rpcType == RpcType.STREAMING, "Generic client only supports streaming calls"); GrpcPreconditions.CheckArgument(rpcType == RpcType.STREAMING, "Generic client only supports streaming calls");
return () => return RunGenericStreamingAsync(channel, timer);
{
RunGenericStreamingAsync(channel, timer).Wait();
};
} }
GrpcPreconditions.CheckNotNull(payloadConfig.SimpleParams); GrpcPreconditions.CheckNotNull(payloadConfig.SimpleParams);
if (clientType == ClientType.SYNC_CLIENT) if (clientType == ClientType.SYNC_CLIENT)
{ {
GrpcPreconditions.CheckArgument(rpcType == RpcType.UNARY, "Sync client can only be used for Unary calls in C#"); GrpcPreconditions.CheckArgument(rpcType == RpcType.UNARY, "Sync client can only be used for Unary calls in C#");
return () => RunUnary(channel, timer); // create a dedicated thread for the synchronous client
return Task.Factory.StartNew(() => RunUnary(channel, timer), TaskCreationOptions.LongRunning);
} }
else if (clientType == ClientType.ASYNC_CLIENT) else if (clientType == ClientType.ASYNC_CLIENT)
{ {
switch (rpcType) switch (rpcType)
{ {
case RpcType.UNARY: case RpcType.UNARY:
return () => return RunUnaryAsync(channel, timer);
{
RunUnaryAsync(channel, timer).Wait();
};
case RpcType.STREAMING: case RpcType.STREAMING:
return () => return RunStreamingPingPongAsync(channel, timer);
{
RunStreamingPingPongAsync(channel, timer).Wait();
};
} }
} }
throw new ArgumentException("Unsupported configuration."); throw new ArgumentException("Unsupported configuration.");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment