Exemplo n.º 1
0
        public void InterceptClientSideModifyCall()
        {
            var policy = new MyPolicy("a");

            (var server, var client) = SetupClientServerPair();

            using (server)
                using (client)
                {
                    client.WhenConnected.Wait();

                    var counters = new Counters();
                    server.Main = new TestInterfaceImpl(counters);
                    using (var main = policy.Attach(client.GetMain <ITestInterface>()))
                    {
                        var request1 = main.Foo(321, false, default);
                        Assert.IsTrue(policy.Calls.TryReceive(out var cc));

                        Assert.AreEqual(InterceptionState.RequestedFromAlice, cc.State);

                        var pr = new Capnproto_test.Capnp.Test.TestInterface.Params_foo.READER(cc.InArgs);
                        Assert.AreEqual(321u, pr.I);
                        Assert.AreEqual(false, pr.J);

                        var pw = cc.InArgs.Rewrap <Capnproto_test.Capnp.Test.TestInterface.Params_foo.WRITER>();
                        pw.I = 123u;
                        pw.J = true;

                        cc.ForwardToBob();

                        var rx = policy.Returns.ReceiveAsync();

                        // Racing against Bob's answer
                        Assert.IsTrue(cc.State == InterceptionState.ForwardedToBob || rx.IsCompleted);

                        Assert.IsTrue(rx.Wait(MediumNonDbgTimeout));
                        var rr = new Capnproto_test.Capnp.Test.TestInterface.Result_foo.READER(cc.OutArgs);
                        Assert.AreEqual("foo", rr.X);

                        Assert.IsFalse(request1.IsCompleted);

                        var rw = ((DynamicSerializerState)cc.OutArgs).Rewrap <Capnproto_test.Capnp.Test.TestInterface.Result_foo.WRITER>();
                        rw.X       = "bar";
                        cc.OutArgs = rw;

                        Assert.AreEqual(InterceptionState.ReturnedFromBob, cc.State);
                        cc.ReturnToAlice();
                        Assert.AreEqual(InterceptionState.ReturnedToAlice, cc.State);

                        Assert.IsTrue(request1.IsCompleted);

                        Assert.AreEqual("bar", request1.Result);
                    }
                }
        }
Exemplo n.º 2
0
        public void InterceptServerSideObserveCall()
        {
            var policy = new MyPolicy("a");

            (var server, var client) = SetupClientServerPair();

            using (server)
                using (client)
                {
                    client.WhenConnected.Wait();

                    var counters = new Counters();
                    server.Main = policy.Attach <ITestInterface>(new TestInterfaceImpl(counters));
                    using (var main = client.GetMain <ITestInterface>())
                    {
                        var request1 = main.Foo(123, true, default);
                        var fcc      = policy.Calls.ReceiveAsync();
                        Assert.IsTrue(fcc.Wait(MediumNonDbgTimeout));
                        var cc = fcc.Result;

                        var pr = new Capnproto_test.Capnp.Test.TestInterface.Params_foo.READER(cc.InArgs);
                        Assert.AreEqual(123u, pr.I);

                        cc.ForwardToBob();

                        Assert.IsTrue(policy.Returns.ReceiveAsync().Wait(MediumNonDbgTimeout));
                        var rr = new Capnproto_test.Capnp.Test.TestInterface.Result_foo.READER(cc.OutArgs);
                        Assert.AreEqual("foo", rr.X);

                        cc.ReturnToAlice();

                        Assert.IsTrue(request1.Wait(MediumNonDbgTimeout));

                        Assert.AreEqual("foo", request1.Result);
                    }
                }
        }