test & fix

This commit is contained in:
Christian Köllner 2020-04-16 22:20:42 +02:00
parent af6dcec8f7
commit d2c2f8d657
6 changed files with 76 additions and 4 deletions

View File

@ -188,5 +188,11 @@ namespace Capnp.Net.Runtime.Tests
{ {
NewDtbdctTestbed().RunTest(Testsuite.CallAfterFinish2); NewDtbdctTestbed().RunTest(Testsuite.CallAfterFinish2);
} }
[TestMethod]
public void LegacyAccess()
{
NewDtbdctTestbed().RunTest(Testsuite.LegacyAccess);
}
} }
} }

View File

@ -395,6 +395,44 @@ namespace Capnp.Net.Runtime.Tests
} }
} }
[TestMethod]
public void InterceptClientSideModifyPipelinedCall()
{
var policy = new MyPolicy("a");
(var server, var client) = SetupClientServerPair();
using (server)
using (client)
{
var counters = new Counters();
var impl = new TestMoreStuffImpl(counters);
server.Main = impl;
using (var main = policy.Attach(client.GetMain<ITestMoreStuff>()))
{
var req = main.GetNull().Eager().GetCallSequence(0);
Assert.IsTrue(policy.Calls.TryReceive(out var ccGetNull));
Assert.IsTrue(policy.Calls.TryReceive(out var ccGetCallSequence));
ccGetNull.ForwardToBob();
Assert.IsTrue(policy.Returns.ReceiveAsync().Wait(MediumNonDbgTimeout));
ccGetNull.ReturnToAlice();
ccGetCallSequence.Bob = Proxy.Share<ITestMoreStuff>(impl);
ccGetCallSequence.ForwardToBob();
Assert.IsTrue(policy.Returns.ReceiveAsync().Wait(MediumNonDbgTimeout));
ccGetCallSequence.ReturnToAlice();
Assert.IsTrue(req.IsCompleted && !req.IsFaulted && !req.IsCanceled);
Assert.AreEqual(0u, req.Result);
}
}
}
[TestMethod] [TestMethod]
public void InterfaceAndMethodId() public void InterfaceAndMethodId()
{ {

View File

@ -140,6 +140,12 @@ namespace Capnp.Net.Runtime.Tests
NewLocalTestbed().RunTest(Testsuite.Ownership3); NewLocalTestbed().RunTest(Testsuite.Ownership3);
} }
[TestMethod]
public void LegacyAccess()
{
NewLocalTestbed().RunTest(Testsuite.LegacyAccess);
}
[TestMethod] [TestMethod]
public void EagerRace() public void EagerRace()
{ {

View File

@ -855,5 +855,23 @@ namespace Capnp.Net.Runtime.Tests
} }
} }
} }
public static void LegacyAccess(ITestbed testbed)
{
var impl = new TestMoreStuffImpl(new Counters());
using (var main = testbed.ConnectMain<ITestMoreStuff>(impl))
{
var task = main.Echo(new TestCallOrderImpl());
var answer = Impatient.TryGetAnswer(task);
Assert.IsNotNull(answer);
var cap = answer.Access(new MemberAccessPath(0));
using (var proxy = (ITestCallOrder)CapabilityReflection.CreateProxy<ITestCallOrder>(cap))
{
var seq = proxy.GetCallSequence(0);
testbed.MustComplete(seq);
Assert.AreEqual(0u, seq.Result);
}
}
}
} }
} }

View File

@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net.Sockets;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -160,9 +161,12 @@ namespace Capnp
} }
} }
} }
catch (EndOfStreamException) catch (Exception exception) when (exception is EndOfStreamException ||
exception is IOException ioex &&
ioex.InnerException is SocketException sockex &&
sockex.SocketErrorCode == SocketError.Interrupted)
{ {
Logger.LogWarning("Encountered End of Stream"); Logger.LogInformation("Encountered end of stream");
} }
catch (InvalidDataException e) catch (InvalidDataException e)
{ {

View File

@ -27,13 +27,13 @@ namespace Capnp.Rpc.Interception
public ConsumedCapability Access(MemberAccessPath access) public ConsumedCapability Access(MemberAccessPath access)
{ {
return new LocalAnswerCapability(_futureResult.Task, access); return _callContext._censorCapability.Policy.Attach<ConsumedCapability>(new LocalAnswerCapability(_futureResult.Task, access));
} }
public ConsumedCapability Access(MemberAccessPath _, Task<IDisposable?> task) public ConsumedCapability Access(MemberAccessPath _, Task<IDisposable?> task)
{ {
var proxyTask = task.AsProxyTask(); var proxyTask = task.AsProxyTask();
return new LocalAnswerCapability(proxyTask); return _callContext._censorCapability.Policy.Attach<ConsumedCapability>(new LocalAnswerCapability(proxyTask));
} }
public void Dispose() public void Dispose()