2019-06-12 21:56:55 +02:00
|
|
|
|
using Capnp.Net.Runtime.Tests.GenImpls;
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using Capnp.Net.Runtime.Tests.Util;
|
2019-06-12 21:56:55 +02:00
|
|
|
|
using Capnp.Rpc;
|
|
|
|
|
using Capnproto_test.Capnp.Test;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Capnp.Net.Runtime.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2020-02-25 21:46:15 +01:00
|
|
|
|
[TestCategory("Coverage")]
|
2019-07-07 17:12:49 +02:00
|
|
|
|
public class TcpRpcAdvancedStuff : TestBase
|
2019-06-12 21:56:55 +02:00
|
|
|
|
{
|
2020-03-29 00:07:16 +01:00
|
|
|
|
[TestMethod]
|
2019-06-12 21:56:55 +02:00
|
|
|
|
public void MultiConnect()
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
using (var server = SetupServer(addr, port))
|
2019-06-12 21:56:55 +02:00
|
|
|
|
{
|
|
|
|
|
var counters = new Counters();
|
|
|
|
|
var tcs = new TaskCompletionSource<int>();
|
|
|
|
|
server.Main = new TestInterfaceImpl(counters, tcs);
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= 10; i++)
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client = SetupClient(addr, port))
|
2019-06-12 21:56:55 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//client.WhenConnected.Wait();
|
2019-06-12 21:56:55 +02:00
|
|
|
|
|
|
|
|
|
using (var main = client.GetMain<ITestInterface>())
|
|
|
|
|
{
|
|
|
|
|
var request1 = main.Foo(123, true, default);
|
|
|
|
|
var request3 = Assert.ThrowsExceptionAsync<RpcException>(() => main.Bar(default));
|
|
|
|
|
var s = new TestAllTypes();
|
|
|
|
|
Common.InitTestMessage(s);
|
|
|
|
|
var request2 = main.Baz(s, default);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(request1.Wait(MediumNonDbgTimeout));
|
|
|
|
|
Assert.IsTrue(request2.Wait(MediumNonDbgTimeout));
|
|
|
|
|
Assert.IsTrue(request3.Wait(MediumNonDbgTimeout));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("foo", request1.Result);
|
|
|
|
|
Assert.AreEqual(2 * i, counters.CallCount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bootstrap capability must not be disposed
|
|
|
|
|
Assert.IsFalse(tcs.Task.IsCompleted);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 00:07:16 +01:00
|
|
|
|
[TestMethod]
|
2019-06-12 21:56:55 +02:00
|
|
|
|
public void TwoClients()
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
using (var server = SetupServer(addr, port))
|
2019-06-12 21:56:55 +02:00
|
|
|
|
{
|
|
|
|
|
var counters = new Counters();
|
|
|
|
|
server.Main = new TestMoreStuffImpl(counters);
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client1 = SetupClient(addr, port))
|
|
|
|
|
using (var client2 = SetupClient(addr, port))
|
2019-06-12 21:56:55 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//Assert.IsTrue(client1.WhenConnected.Wait(MediumNonDbgTimeout));
|
|
|
|
|
//Assert.IsTrue(client2.WhenConnected.Wait(MediumNonDbgTimeout));
|
2019-06-12 21:56:55 +02:00
|
|
|
|
|
|
|
|
|
using (var main = client1.GetMain<ITestMoreStuff>())
|
|
|
|
|
{
|
|
|
|
|
Assert.IsTrue(main.Hold(new TestInterfaceImpl(counters)).Wait(MediumNonDbgTimeout));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var main = client2.GetMain<ITestMoreStuff>())
|
|
|
|
|
{
|
|
|
|
|
Assert.IsTrue(main.CallHeld().Wait(MediumNonDbgTimeout));
|
|
|
|
|
var getHeld = main.GetHeld();
|
|
|
|
|
Assert.IsTrue(getHeld.Wait(MediumNonDbgTimeout));
|
|
|
|
|
var foo = getHeld.Result.Foo(123, true);
|
|
|
|
|
Assert.IsTrue(foo.Wait(MediumNonDbgTimeout));
|
|
|
|
|
Assert.AreEqual("foo", foo.Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client1.Dispose();
|
|
|
|
|
|
|
|
|
|
using (var main = client2.GetMain<ITestMoreStuff>())
|
|
|
|
|
{
|
|
|
|
|
ExpectPromiseThrows(main.CallHeld());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-07 17:12:49 +02:00
|
|
|
|
|
2020-03-29 00:07:16 +01:00
|
|
|
|
[TestMethod]
|
2019-07-07 17:12:49 +02:00
|
|
|
|
public void ClosingServerWhileRequestingBootstrap()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
var server = SetupServer(addr, port);
|
2019-07-07 17:12:49 +02:00
|
|
|
|
var counters = new Counters();
|
|
|
|
|
var tcs = new TaskCompletionSource<int>();
|
|
|
|
|
server.Main = new TestInterfaceImpl(counters, tcs);
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client = SetupClient(addr, port))
|
2019-07-07 17:12:49 +02:00
|
|
|
|
{
|
2019-07-07 19:59:31 +02:00
|
|
|
|
client.WhenConnected.Wait();
|
2019-07-07 17:12:49 +02:00
|
|
|
|
|
|
|
|
|
using (var main = client.GetMain<ITestInterface>())
|
|
|
|
|
{
|
|
|
|
|
server.Dispose();
|
|
|
|
|
|
|
|
|
|
// Resolution must either succeed or be cancelled. A hanging resolution would be inacceptable.
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-04-23 22:34:45 +02:00
|
|
|
|
Assert.IsTrue(((IResolvingCapability)main).WhenResolved.WrappedTask.Wait(MediumNonDbgTimeout));
|
2019-07-07 17:12:49 +02:00
|
|
|
|
}
|
|
|
|
|
catch (AggregateException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-19 13:52:16 +02:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void InheritFromGenericInterface()
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
using (var server = SetupServer(addr, port))
|
2019-10-19 13:52:16 +02:00
|
|
|
|
{
|
|
|
|
|
var counters = new Counters();
|
|
|
|
|
server.Main = new B2Impl();
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client = SetupClient(addr, port))
|
2019-10-19 13:52:16 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//client.WhenConnected.Wait();
|
2019-10-19 13:52:16 +02:00
|
|
|
|
|
|
|
|
|
using (var main = client.GetMain<CapnpGen.IB2>())
|
|
|
|
|
{
|
|
|
|
|
Assert.IsTrue(main.MethodA("42").Wait(MediumNonDbgTimeout));
|
|
|
|
|
var b = main.MethodB(123);
|
|
|
|
|
Assert.IsTrue(b.Wait(MediumNonDbgTimeout));
|
|
|
|
|
Assert.AreEqual("42", b.Result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-25 19:29:44 +02:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Issue25()
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
using (var server = SetupServer(addr, port))
|
2019-10-25 19:29:44 +02:00
|
|
|
|
{
|
|
|
|
|
server.Main = new Issue25BImpl();
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client = SetupClient(addr, port))
|
2019-10-25 19:29:44 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//client.WhenConnected.Wait();
|
2019-10-25 19:29:44 +02:00
|
|
|
|
|
|
|
|
|
using (var main = client.GetMain<CapnpGen.IIssue25B>())
|
|
|
|
|
{
|
|
|
|
|
var capholderAPT = main.GetAinCapHolderAnyPointer();
|
|
|
|
|
Assert.IsTrue(capholderAPT.Wait(MediumNonDbgTimeout));
|
|
|
|
|
var capholderAP = capholderAPT.Result;
|
|
|
|
|
var capAPT = capholderAP.Cap();
|
|
|
|
|
Assert.IsTrue(capAPT.Wait(MediumNonDbgTimeout));
|
|
|
|
|
using (var a = ((BareProxy)capAPT.Result).Cast<CapnpGen.IIssue25A>(true))
|
|
|
|
|
{
|
|
|
|
|
var r = a.MethodA();
|
|
|
|
|
Assert.IsTrue(r.Wait(MediumNonDbgTimeout));
|
|
|
|
|
Assert.AreEqual(123L, r.Result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-05 16:53:40 +02:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ExportCapToThirdParty()
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
using (var server = SetupServer(addr, port))
|
2020-04-05 16:53:40 +02:00
|
|
|
|
{
|
|
|
|
|
var counters = new Counters();
|
|
|
|
|
server.Main = new TestMoreStuffImpl3();
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client = SetupClient(addr, port))
|
2020-04-05 16:53:40 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//Assert.IsTrue(client.WhenConnected.Wait(MediumNonDbgTimeout));
|
2020-04-05 16:53:40 +02:00
|
|
|
|
|
|
|
|
|
using (var main = client.GetMain<ITestMoreStuff>())
|
|
|
|
|
{
|
|
|
|
|
var held = main.GetHeld().Eager();
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(addr, port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
|
|
|
|
|
using (var server2 = SetupServer(addr, port))
|
2020-04-05 16:53:40 +02:00
|
|
|
|
{
|
|
|
|
|
server2.Main = new TestMoreStuffImpl2();
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client2 = SetupClient(addr, port))
|
2020-04-05 16:53:40 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//Assert.IsTrue(client2.WhenConnected.Wait(MediumNonDbgTimeout));
|
2020-04-05 16:53:40 +02:00
|
|
|
|
|
|
|
|
|
using (var main2 = client2.GetMain<ITestMoreStuff>())
|
|
|
|
|
{
|
|
|
|
|
var fooTask = main2.CallFoo(held);
|
|
|
|
|
Assert.IsTrue(main.Hold(new TestInterfaceImpl(new Counters())).Wait(MediumNonDbgTimeout));
|
|
|
|
|
Assert.IsTrue(fooTask.Wait(MediumNonDbgTimeout));
|
|
|
|
|
Assert.AreEqual("bar", fooTask.Result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ExportTailCallCapToThirdParty()
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
using (var server = SetupServer(addr, port))
|
2020-04-05 16:53:40 +02:00
|
|
|
|
{
|
|
|
|
|
server.Main = new TestTailCallerImpl2();
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client = SetupClient(addr, port))
|
2020-04-05 16:53:40 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//Assert.IsTrue(client.WhenConnected.Wait(MediumNonDbgTimeout));
|
2020-04-05 16:53:40 +02:00
|
|
|
|
|
|
|
|
|
using (var main = client.GetMain<ITestTailCaller>())
|
|
|
|
|
{
|
|
|
|
|
var callee = new TestTailCalleeImpl(new Counters());
|
|
|
|
|
var fooTask = main.Foo(123, callee);
|
|
|
|
|
Assert.IsTrue(fooTask.Wait(MediumNonDbgTimeout));
|
|
|
|
|
|
|
|
|
|
using (var c = fooTask.Result.C)
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client2 = SetupClient(addr, port))
|
2020-04-05 16:53:40 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//Assert.IsTrue(client2.WhenConnected.Wait(MediumNonDbgTimeout));
|
2020-04-05 16:53:40 +02:00
|
|
|
|
|
|
|
|
|
using (var main2 = client2.GetMain<ITestTailCaller>())
|
|
|
|
|
{
|
|
|
|
|
var fooTask2 = main2.Foo(123, null);
|
|
|
|
|
Assert.IsTrue(fooTask2.Wait(MediumNonDbgTimeout));
|
2020-04-20 08:14:02 +02:00
|
|
|
|
Assert.IsTrue(fooTask2.C().GetCallSequence(0).Wait(MediumNonDbgTimeout));
|
2020-04-05 16:53:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-05 22:32:57 +02:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void SalamiTactics()
|
|
|
|
|
{
|
2020-04-20 21:22:12 +02:00
|
|
|
|
(var addr, int port) = TcpManager.Instance.GetLocalAddressAndPort();
|
|
|
|
|
using (var server = SetupServer(addr, port))
|
2020-04-05 22:32:57 +02:00
|
|
|
|
{
|
|
|
|
|
server.Main = new TestMoreStuffImpl3();
|
|
|
|
|
|
2020-04-20 21:22:12 +02:00
|
|
|
|
using (var client = SetupClient(addr, port))
|
2020-04-05 22:32:57 +02:00
|
|
|
|
{
|
2020-04-11 15:48:02 +02:00
|
|
|
|
//client.WhenConnected.Wait();
|
2020-04-05 22:32:57 +02:00
|
|
|
|
|
|
|
|
|
using (var main = client.GetMain<ITestMoreStuff>())
|
|
|
|
|
{
|
|
|
|
|
var echoTask = main.Echo(Proxy.Share<ITestCallOrder>(main));
|
|
|
|
|
Assert.IsTrue(echoTask.Wait(MediumNonDbgTimeout));
|
2020-04-10 00:01:12 +02:00
|
|
|
|
using (var echo = echoTask.Result)
|
2020-04-05 22:32:57 +02:00
|
|
|
|
{
|
2020-04-15 22:19:45 +02:00
|
|
|
|
var list = new Task<uint>[200];
|
2020-04-10 00:01:12 +02:00
|
|
|
|
for (uint i = 0; i < list.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
list[i] = echo.GetCallSequence(i);
|
|
|
|
|
}
|
|
|
|
|
Assert.IsTrue(Task.WaitAll(list, MediumNonDbgTimeout));
|
|
|
|
|
for (uint i = 0; i < list.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(i, list[i].Result);
|
|
|
|
|
}
|
2020-04-05 22:32:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-10 00:01:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void NoTailCallMt()
|
|
|
|
|
{
|
|
|
|
|
NewLocalhostTcpTestbed().RunTest(Testsuite.NoTailCallMt);
|
|
|
|
|
}
|
2020-04-13 20:22:52 +02:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void CallAfterFinish1()
|
|
|
|
|
{
|
|
|
|
|
NewLocalhostTcpTestbed().RunTest(Testsuite.CallAfterFinish1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void CallAfterFinish2()
|
|
|
|
|
{
|
|
|
|
|
NewLocalhostTcpTestbed().RunTest(Testsuite.CallAfterFinish2);
|
|
|
|
|
}
|
2019-06-12 21:56:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|