From be10b356aa065d7b1ab992d8fa860bf927e833c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Sun, 5 Apr 2020 22:32:57 +0200 Subject: [PATCH] added test --- .../Mock/TestCapImplementations.cs | 22 ++++++++++--- .../TcpRpcAdvancedStuff.cs | 31 +++++++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Capnp.Net.Runtime.Tests/Mock/TestCapImplementations.cs b/Capnp.Net.Runtime.Tests/Mock/TestCapImplementations.cs index 44e9014..e26b84d 100644 --- a/Capnp.Net.Runtime.Tests/Mock/TestCapImplementations.cs +++ b/Capnp.Net.Runtime.Tests/Mock/TestCapImplementations.cs @@ -958,7 +958,7 @@ namespace Capnp.Net.Runtime.Tests.GenImpls } } - class TestMoreStuffImpl3 : ITestMoreStuff + class TestMoreStuffImpl3 : ITestMoreStuff, ITestCallOrder { readonly TaskCompletionSource _heldCap = new TaskCompletionSource(); @@ -987,9 +987,18 @@ namespace Capnp.Net.Runtime.Tests.GenImpls } } - public Task Echo(ITestCallOrder Cap, CancellationToken cancellationToken_ = default) + int _echoCounter; + + public Task Echo(ITestCallOrder cap, CancellationToken cancellationToken_ = default) { - throw new NotImplementedException(); + if (_echoCounter++ < 20) + { + return Task.FromResult(((Proxy)cap).Cast(true).Echo(cap).Eager()); + } + else + { + return Task.FromResult(cap); + } } public Task ExpectCancel(ITestInterface Cap, CancellationToken cancellationToken_ = default) @@ -997,9 +1006,12 @@ namespace Capnp.Net.Runtime.Tests.GenImpls throw new NotImplementedException(); } - public Task GetCallSequence(uint Expected, CancellationToken cancellationToken_ = default) + uint _counter; + + public Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) { - throw new NotImplementedException(); + Assert.AreEqual(_counter, expected); + return Task.FromResult(_counter++); } public Task GetEnormousString(CancellationToken cancellationToken_ = default) diff --git a/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs b/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs index 3b7eb41..f9483bf 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs @@ -245,5 +245,36 @@ namespace Capnp.Net.Runtime.Tests } } } + + [TestMethod] + public void SalamiTactics() + { + using (var server = SetupServer()) + { + server.Main = new TestMoreStuffImpl3(); + + using (var client = SetupClient()) + { + client.WhenConnected.Wait(); + + using (var main = client.GetMain()) + { + var echoTask = main.Echo(Proxy.Share(main)); + Assert.IsTrue(echoTask.Wait(MediumNonDbgTimeout)); + var echo = echoTask.Result; + var list = new Task[1000]; + 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); + } + } + } + } + } } }