189 lines
5.2 KiB
C#
Raw Normal View History

2019-06-12 21:56:55 +02:00
using System;
using System.Diagnostics;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Capnp.Rpc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Capnp.Net.Runtime.Tests.GenImpls;
using Capnproto_test.Capnp.Test;
2019-08-24 00:29:42 +02:00
using Microsoft.Extensions.Logging;
2019-06-12 21:56:55 +02:00
namespace Capnp.Net.Runtime.Tests
{
2019-06-12 21:56:55 +02:00
[TestClass]
2020-02-25 21:46:15 +01:00
[TestCategory("Coverage")]
2019-06-12 21:56:55 +02:00
public class TcpRpcPorted: TestBase
{
[TestMethod]
public void Basic()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.Basic);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void Pipeline()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.Pipeline);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void Release()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.Release);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void ReleaseOnCancel()
{
(var server, var client) = SetupClientServerPair();
using (server)
using (client)
{
client.WhenConnected.Wait();
2019-06-12 21:56:55 +02:00
var counters = new Counters();
server.Main = new TestMoreStuffImpl(counters);
using (var main = client.GetMain<ITestMoreStuff>())
{
((Proxy)main).WhenResolved.Wait(MediumNonDbgTimeout);
// Since we have a threaded model, there is no way to deterministically provoke the situation
// where Cancel and Finish message cross paths. Instead, we'll do a lot of such requests and
// later on verify that the handle count is 0.
for (int i = 0; i < 1000; i++)
{
var cts = new CancellationTokenSource();
var task = main.GetHandle(cts.Token);
cts.Cancel();
task.ContinueWith(t =>
{
try
{
t.Result.Dispose();
}
catch (AggregateException ex) when (ex.InnerException is TaskCanceledException)
{
}
2019-06-12 21:56:55 +02:00
cts.Dispose();
});
}
Thread.Sleep(ShortTimeout);
Assert.IsTrue(SpinWait.SpinUntil(() => counters.HandleCount == 0, MediumNonDbgTimeout));
}
}
}
[TestMethod]
public void TailCall()
2019-06-12 21:56:55 +02:00
{
NewLocalhostTcpTestbed().RunTest(Testsuite.TailCall);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void Cancelation()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.Cancelation);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void PromiseResolve()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.PromiseResolve);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void RetainAndRelease()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.RetainAndRelease);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void Cancel()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.Cancel);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void SendTwice()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.SendTwice);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void Embargo()
{
2020-03-29 00:07:16 +01:00
NewLocalhostTcpTestbed().RunTest(Testsuite.EmbargoOnPromisedAnswer);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void EmbargoError()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.EmbargoError);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void EmbargoNull()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.EmbargoNull);
2019-06-12 21:56:55 +02:00
}
[TestMethod]
public void CallBrokenPromise()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.CallBrokenPromise);
2019-06-12 21:56:55 +02:00
}
2020-03-22 00:12:50 +01:00
[TestMethod]
public void BootstrapReuse()
{
(var server, var client) = SetupClientServerPair();
var counters = new Counters();
var impl = new TestInterfaceImpl(counters);
using (server)
using (client)
{
client.WhenConnected.Wait();
server.Main = impl;
for (int i = 0; i < 10; i++)
{
using (var main = client.GetMain<ITestMoreStuff>())
{
((Proxy)main).WhenResolved.Wait(MediumNonDbgTimeout);
}
Assert.IsFalse(impl.IsDisposed);
}
}
Assert.IsTrue(impl.IsDisposed);
}
2020-03-22 13:57:02 +01:00
[TestMethod]
public void Ownership1()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.Ownership1);
}
[TestMethod]
public void Ownership2()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.Ownership2);
}
[TestMethod]
public void Ownership3()
{
NewLocalhostTcpTestbed().RunTest(Testsuite.Ownership3);
}
2019-06-12 21:56:55 +02:00
}
}