From c88c32148bbcab1403457c27149f2d457dada926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darko=20Juri=C4=87?= Date: Sun, 31 Dec 2017 22:18:19 +0100 Subject: [PATCH] Fixing tests. --- Source/WebSocketRPC.Base/RPC.cs | 4 +-- Tests/Program.cs | 1 + Tests/SettingsTests/SettingsTests.cs | 42 ++++++++++++++++++++++++++++ Tests/TimeoutTests/TimeoutTests.cs | 41 --------------------------- 4 files changed, 45 insertions(+), 43 deletions(-) diff --git a/Source/WebSocketRPC.Base/RPC.cs b/Source/WebSocketRPC.Base/RPC.cs index 86626d6..17f7237 100644 --- a/Source/WebSocketRPC.Base/RPC.cs +++ b/Source/WebSocketRPC.Base/RPC.cs @@ -72,10 +72,10 @@ public static void AddConverter(JsonConverter converter) } /// - /// Gets or sets the time after a remote call will be canceled by raising . + /// Gets or sets a delay after a remote call will be canceled by raising . /// Values equal or less than zero (total milliseconds) correspond to an indefinite time period. /// - public static TimeSpan RpcTerminationDelay { get; set; } = TimeSpan.Zero; + public static TimeSpan RpcTerminationDelay { get; set; } = TimeSpan.FromSeconds(10); #endregion diff --git a/Tests/Program.cs b/Tests/Program.cs index 198c5fc..bbd1ca7 100644 --- a/Tests/Program.cs +++ b/Tests/Program.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using WebSocketRPC; namespace Tests { diff --git a/Tests/SettingsTests/SettingsTests.cs b/Tests/SettingsTests/SettingsTests.cs index c2c0074..5d86e8a 100644 --- a/Tests/SettingsTests/SettingsTests.cs +++ b/Tests/SettingsTests/SettingsTests.cs @@ -26,5 +26,47 @@ static Task[] TestMaxMessageSize(CancellationTokenSource cts) return new Task[] { ts, tc }; } + + + class ServiceTimeoutAPI : IServiceTimeoutAPI + { + public async Task LongRunningTask(int a, int b) + { + await Task.Delay(TimeSpan.FromSeconds(5)); + return a + b; + } + } + + interface IServiceTimeoutAPI + { + Task LongRunningTask(int a, int b); + } + + static Task[] TestRpcTimeout(CancellationTokenSource cts) + { + RPC.RpcTerminationDelay = TimeSpan.FromSeconds(3); + + var ts = Server.ListenAsync($"http://{address}", cts.Token, (c, wc) => c.Bind(new ServiceTimeoutAPI())); + var tc = Client.ConnectAsync($"ws://{address}", cts.Token, c => + { + c.Bind(); //should generate an exception: must be an interface + c.OnOpen += async () => + { + try + { + var results = await RPC.For().CallAsync(x => x.LongRunningTask(1, 2)); + } + catch (Exception ex) + { + Console.WriteLine("Error while executing {0}: {1}", nameof(ServiceTimeoutAPI.LongRunningTask), ex.Message); + } + }; + + c.OnError += e => Task.Run(() => Console.WriteLine("Error: " + e.Message)); + }, + reconnectOnError: false); + + return new Task[] { ts, tc }; + } } } diff --git a/Tests/TimeoutTests/TimeoutTests.cs b/Tests/TimeoutTests/TimeoutTests.cs index 8991ff0..9cef409 100644 --- a/Tests/TimeoutTests/TimeoutTests.cs +++ b/Tests/TimeoutTests/TimeoutTests.cs @@ -21,46 +21,5 @@ static Task[] TestConnectionTimeout(CancellationTokenSource cts) return new Task[] { ts, tc }; } - - - - class ServiceTimeoutAPI : IServiceTimeoutAPI - { - public async Task LongRunningTask(int a, int b) - { - await Task.Delay(TimeSpan.FromSeconds(5)); - return a + b; - } - } - - interface IServiceTimeoutAPI - { - Task LongRunningTask(int a, int b); - } - - static Task[] TestRpcTimeout(CancellationTokenSource cts) - { - var ts = Server.ListenAsync($"http://{address}", cts.Token, (c, wc) => c.Bind(new ServiceTimeoutAPI())); - var tc = Client.ConnectAsync($"ws://{address}", cts.Token, c => - { - c.Bind(); //should generate an exception: must be an interface - c.OnOpen += async () => - { - try - { - var results = await RPC.For().CallAsync(x => x.LongRunningTask(1, 2)); - } - catch (Exception ex) - { - Console.WriteLine("Error while executing {0}: {1}", nameof(ServiceTimeoutAPI.LongRunningTask), ex.Message); - } - }; - - c.OnError += e => Task.Run(() => Console.WriteLine("Error: " + e.Message)); - }, - reconnectOnError: false); - - return new Task[] { ts, tc }; - } } }