public static void EmbargoOnImportedCap(ITestbed testbed) { var impl = new TestMoreStuffImpl2(); using (var main = testbed.ConnectMain <ITestMoreStuff>(impl)) { var cap = new TestCallOrderImpl(); cap.CountToDispose = 6; var earlyCall = main.GetCallSequence(0, default); var echo = main.Echo(cap, default); testbed.MustComplete(echo); using (var pipeline = echo.Result) { var call0 = pipeline.GetCallSequence(0, default); var call1 = pipeline.GetCallSequence(1, default); testbed.MustComplete(earlyCall); impl.EnableEcho(); var call2 = pipeline.GetCallSequence(2, default); testbed.MustComplete(echo); using (var resolved = echo.Result) { var call3 = pipeline.GetCallSequence(3, default); var call4 = pipeline.GetCallSequence(4, default); var call5 = pipeline.GetCallSequence(5, default); try { testbed.MustComplete(call0); testbed.MustComplete(call1); testbed.MustComplete(call2); testbed.MustComplete(call3); testbed.MustComplete(call4); testbed.MustComplete(call5); } catch (System.Exception) { cap.CountToDispose = null; throw; } Assert.AreEqual(0u, call0.Result); Assert.AreEqual(1u, call1.Result); Assert.AreEqual(2u, call2.Result); Assert.AreEqual(3u, call3.Result); Assert.AreEqual(4u, call4.Result); Assert.AreEqual(5u, call5.Result); } } } }
public static void EmbargoOnPromisedAnswer(ITestbed testbed) { var counters = new Counters(); var impl = new TestMoreStuffImpl(counters); using (var main = testbed.ConnectMain <ITestMoreStuff>(impl)) { if (main is IResolvingCapability resolving) { testbed.MustComplete(resolving.WhenResolved.WrappedTask); } var cap = new TestCallOrderImpl(); cap.CountToDispose = 6; var earlyCall = main.GetCallSequence(0, default); var echo = main.Echo(cap, default); testbed.MustComplete(Task.CompletedTask); using (var pipeline = echo.Eager(true)) { var call0 = pipeline.GetCallSequence(0, default); var call1 = pipeline.GetCallSequence(1, default); testbed.MustComplete(earlyCall); impl.EnableEcho(); var call2 = pipeline.GetCallSequence(2, default); testbed.MustComplete(echo); using (var resolved = echo.Result) { var call3 = pipeline.GetCallSequence(3, default); var call4 = pipeline.GetCallSequence(4, default); var call5 = pipeline.GetCallSequence(5, default); testbed.MustComplete(call0); testbed.MustComplete(call1); testbed.MustComplete(call2); testbed.MustComplete(call3); testbed.MustComplete(call4); testbed.MustComplete(call5); Assert.AreEqual(0u, call0.Result); Assert.AreEqual(1u, call1.Result); Assert.AreEqual(2u, call2.Result); Assert.AreEqual(3u, call3.Result); Assert.AreEqual(4u, call4.Result); Assert.AreEqual(5u, call5.Result); Assert.AreEqual(cap.Count, cap.CountToDispose, "counter must have reached number of calls"); } } } }
public static void EmbargoNull(ITestbed testbed) { var counters = new Counters(); var impl = new TestMoreStuffImpl(counters); using (var main = testbed.ConnectMain <ITestMoreStuff>(impl)) { if (main is IResolvingCapability resolving) { testbed.MustComplete(resolving.WhenResolved.WrappedTask); } var promise = main.GetNull(default);
static void ExpectPromiseThrows(this ITestbed testbed, params Task[] tasks) { async Task ExpectPromiseThrowsAsync(Task t) { try { await t; Assert.Fail("Did not throw"); } catch (InvalidOperationException) { // Happens if the call went to the resolution // (thus, locally). In this case, the original // exception is routed here. } catch (InvalidTimeZoneException) { // Happens if the call went to the resolution // (thus, locally). In this case, the original // exception is routed here. } catch (RpcException) { // Happens if the call went to the promise // (thus, remotely). In this case, the original // exception had to be serialized, so we receive // the wrapped version. } catch (TaskCanceledException) { // Also used in some test } catch (System.Exception exception) { Assert.Fail($"Got wrong kind of exception: {exception}"); } } var ftasks = tasks.Select(ExpectPromiseThrowsAsync).ToArray(); testbed.MustComplete(ftasks); foreach (var ftask in ftasks) { ftask.GetAwaiter().GetResult(); // re-throw exception } }
public static void EmbargoError(ITestbed testbed) { var counters = new Counters(); var impl = new TestMoreStuffImpl(counters); using (var main = testbed.ConnectMain <ITestMoreStuff>(impl)) { if (main is IResolvingCapability resolving) { testbed.MustComplete(resolving.WhenResolved.WrappedTask); } var cap = new TaskCompletionSource <ITestCallOrder>(); var earlyCall = main.GetCallSequence(0, default); var echo = main.Echo(cap.Task.Eager(true), default); using (var pipeline = echo.Eager(true)) { var call0 = pipeline.GetCallSequence(0, default); var call1 = pipeline.GetCallSequence(1, default); testbed.MustComplete(earlyCall); impl.EnableEcho(); var call2 = pipeline.GetCallSequence(2, default); testbed.MustComplete(echo); var resolved = echo.Result; var call3 = pipeline.GetCallSequence(3, default); var call4 = pipeline.GetCallSequence(4, default); var call5 = pipeline.GetCallSequence(5, default); cap.SetException(new InvalidTimeZoneException("I'm annoying")); testbed.ExpectPromiseThrows(call0, call1, call2, call3, call4, call5); // Verify that we're still connected (there were no protocol errors). testbed.MustComplete(main.GetCallSequence(1, default)); } } }