diff --git a/Capnp.Net.Runtime.Tests/EdgeCaseHandling.cs b/Capnp.Net.Runtime.Tests/EdgeCaseHandling.cs index 5ec303d..1cace55 100644 --- a/Capnp.Net.Runtime.Tests/EdgeCaseHandling.cs +++ b/Capnp.Net.Runtime.Tests/EdgeCaseHandling.cs @@ -1282,5 +1282,70 @@ namespace Capnp.Net.Runtime.Tests Assert.IsTrue(proxy.WhenResolved.IsFaulted); tester.ExpectAbort(); } + + [TestMethod] + public void ReturnToWrongSide2() + { + var tester = new RpcEngineTester(); + + tester.Engine.Main = new TestTailCallerImpl(new Counters()); + + tester.Send(_ => { + _.which = Message.WHICH.Bootstrap; + _.Bootstrap.QuestionId = 0; + }); + uint bootstrapId = 0; + tester.Recv(_ => { + Assert.AreEqual(Message.WHICH.Return, _.which); + Assert.AreEqual(Return.WHICH.Results, _.Return.which); + Assert.AreEqual(CapDescriptor.WHICH.SenderHosted, _.Return.Results.CapTable[0].which); + bootstrapId = _.Return.Results.CapTable[0].SenderHosted; + }); + tester.Send(_ => + { + _.which = Message.WHICH.Call; + _.Call.Target.which = MessageTarget.WHICH.ImportedCap; + _.Call.Target.ImportedCap = 0; + _.Call.SendResultsTo.which = Call.sendResultsTo.WHICH.Caller; + _.Call.InterfaceId = new TestTailCaller_Skeleton().InterfaceId; + _.Call.MethodId = 0; + _.Call.QuestionId = 1; + var a = _.Call.Params.Content.Rewrap(); + a.Callee = new TestTailCalleeImpl(new Counters()); + _.Call.Params.CapTable.Init(1); + _.Call.Params.CapTable[0].which = CapDescriptor.WHICH.SenderHosted; + _.Call.Params.CapTable[0].SenderHosted = 0; + }); + uint q = 0; + tester.Recv(_ => { + Assert.AreEqual(Message.WHICH.Call, _.which); + Assert.AreEqual(Call.sendResultsTo.WHICH.Yourself, _.Call.SendResultsTo.which); + q = _.Call.QuestionId; + }); + tester.Recv(_ => { + Assert.AreEqual(Message.WHICH.Release, _.which); + }); + tester.Recv(_ => { + Assert.AreEqual(Message.WHICH.Return, _.which); + Assert.AreEqual(Return.WHICH.TakeFromOtherQuestion, _.Return.which); + }); + tester.Send(_ => + { + _.which = Message.WHICH.Return; + _.Return.which = Return.WHICH.Results; + _.Return.AnswerId = q; + var wr = _.Return.Results.Content.Rewrap(); + wr.C = new TestCallOrderImpl(); + wr.I = 0; + wr.T = "test"; + _.Return.Results.CapTable.Init(1); + _.Return.Results.CapTable[0].which = CapDescriptor.WHICH.SenderHosted; + _.Return.Results.CapTable[0].SenderHosted = 1; + }); + tester.Recv(_ => { + Assert.AreEqual(Message.WHICH.Finish, _.which); + }); + tester.ExpectAbort(); + } } } diff --git a/Capnp.Net.Runtime.Tests/Interception.cs b/Capnp.Net.Runtime.Tests/Interception.cs index c1c7e50..49aa040 100644 --- a/Capnp.Net.Runtime.Tests/Interception.cs +++ b/Capnp.Net.Runtime.Tests/Interception.cs @@ -400,7 +400,7 @@ namespace Capnp.Net.Runtime.Tests { var policy = new MyPolicy("a"); - (var server, var client) = SetupClientServerPair(); + (var server, var client) = SetupClientServerPair(true); using (server) using (client) diff --git a/Capnp.Net.Runtime.Tests/Util/TestBase.cs b/Capnp.Net.Runtime.Tests/Util/TestBase.cs index 6b089b5..c44df31 100644 --- a/Capnp.Net.Runtime.Tests/Util/TestBase.cs +++ b/Capnp.Net.Runtime.Tests/Util/TestBase.cs @@ -345,10 +345,12 @@ namespace Capnp.Net.Runtime.Tests protected ILogger Logger { get; set; } - protected static TcpRpcClient SetupClient() + protected static TcpRpcClient SetupClient(bool withTracer = false) { var client = new TcpRpcClient(); client.AddBuffering(); + if (withTracer) + client.AttachTracer(new FrameTracing.RpcFrameTracer(Console.Out, false)); client.Connect("localhost", TcpPort); return client; } @@ -379,10 +381,10 @@ namespace Capnp.Net.Runtime.Tests } } - protected static (TcpRpcServer, TcpRpcClient) SetupClientServerPair() + protected static (TcpRpcServer, TcpRpcClient) SetupClientServerPair(bool withClientTracer = false) { var server = SetupServer(); - var client = SetupClient(); + var client = SetupClient(withClientTracer); return (server, client); }