Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Commit

Permalink
Fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dajuric committed Dec 31, 2017
1 parent f8e6d47 commit c88c321
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Source/WebSocketRPC.Base/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public static void AddConverter(JsonConverter converter)
}

/// <summary>
/// Gets or sets the time after a remote call will be canceled by raising <see cref="OperationCanceledException"/>.
/// Gets or sets a delay after a remote call will be canceled by raising <see cref="OperationCanceledException"/>.
/// <para>Values equal or less than zero (total milliseconds) correspond to an indefinite time period.</para>
/// </summary>
public static TimeSpan RpcTerminationDelay { get; set; } = TimeSpan.Zero;
public static TimeSpan RpcTerminationDelay { get; set; } = TimeSpan.FromSeconds(10);

#endregion

Expand Down
1 change: 1 addition & 0 deletions Tests/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using WebSocketRPC;

namespace Tests
{
Expand Down
42 changes: 42 additions & 0 deletions Tests/SettingsTests/SettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,47 @@ static Task[] TestMaxMessageSize(CancellationTokenSource cts)

return new Task[] { ts, tc };
}


class ServiceTimeoutAPI : IServiceTimeoutAPI
{
public async Task<int> LongRunningTask(int a, int b)
{
await Task.Delay(TimeSpan.FromSeconds(5));
return a + b;
}
}

interface IServiceTimeoutAPI
{
Task<int> 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<IServiceTimeoutAPI>(); //should generate an exception: must be an interface
c.OnOpen += async () =>
{
try
{
var results = await RPC.For<IServiceTimeoutAPI>().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 };
}
}
}
41 changes: 0 additions & 41 deletions Tests/TimeoutTests/TimeoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,5 @@ static Task[] TestConnectionTimeout(CancellationTokenSource cts)

return new Task[] { ts, tc };
}



class ServiceTimeoutAPI : IServiceTimeoutAPI
{
public async Task<int> LongRunningTask(int a, int b)
{
await Task.Delay(TimeSpan.FromSeconds(5));
return a + b;
}
}

interface IServiceTimeoutAPI
{
Task<int> 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<IServiceTimeoutAPI>(); //should generate an exception: must be an interface
c.OnOpen += async () =>
{
try
{
var results = await RPC.For<IServiceTimeoutAPI>().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 };
}
}
}

0 comments on commit c88c321

Please sign in to comment.