Refactoring test server/client to use async/await more consistently
diff --git a/test/netstd/Server/Program.cs b/test/netstd/Server/Program.cs
index 8f1f36d..a319b22 100644
--- a/test/netstd/Server/Program.cs
+++ b/test/netstd/Server/Program.cs
@@ -20,12 +20,13 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using ThriftTest;
+using System.Threading.Tasks;
namespace Server
{
public class Program
{
- public static int Main(string[] args)
+ static async Task<int> Main(string[] args)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -46,12 +47,12 @@
case "server": // crosstest wants to pass this, so just emit a hint and ignore
Console.WriteLine("Hint: The 'server' argument is no longer required.");
argslist.RemoveAt(0);
- return TestServer.Execute(argslist);
+ return await TestServer.Execute(argslist);
case "--help":
PrintHelp();
return 0;
default:
- return TestServer.Execute(argslist);
+ return await TestServer.Execute(argslist);
}
}
diff --git a/test/netstd/Server/TestServer.cs b/test/netstd/Server/TestServer.cs
index 471d6c8..65458d6 100644
--- a/test/netstd/Server/TestServer.cs
+++ b/test/netstd/Server/TestServer.cs
@@ -500,13 +500,11 @@
return Task.FromResult(result);
}
- public Task testOneway(int secondsToSleep, CancellationToken cancellationToken)
+ public async Task testOneway(int secondsToSleep, CancellationToken cancellationToken)
{
logger.Invoke("testOneway({0}), sleeping...", secondsToSleep);
- Task.Delay(secondsToSleep * 1000, cancellationToken).GetAwaiter().GetResult();
+ await Task.Delay(secondsToSleep * 1000, cancellationToken);
logger.Invoke("testOneway finished");
-
- return Task.CompletedTask;
}
}
@@ -543,7 +541,7 @@
return cert;
}
- public static int Execute(List<string> args)
+ public static async Task<int> Execute(List<string> args)
{
using (var loggerFactory = new LoggerFactory()) //.AddConsole().AddDebug();
{
@@ -648,7 +646,7 @@
(param.protocol == ProtocolChoice.Compact ? " with compact protocol" : "") +
(param.protocol == ProtocolChoice.Json ? " with json protocol" : "") +
"...");
- serverEngine.ServeAsync(CancellationToken.None).GetAwaiter().GetResult();
+ await serverEngine.ServeAsync(CancellationToken.None);
Console.ReadLine();
}
catch (Exception x)