mirror of
https://github.com/zap-proto/cs.git
synced 2026-10-30 15:05:32 +00:00
Finishes the in-flight capnp→ZAP rebrand on this branch. The prior commits
renamed identifiers/namespaces/files/projects (Capnp.Net.Runtime→Zap.Net.Runtime,
CapnpC→ZapC, .capnp→.zap) but left the human-readable brand name "Cap'n Proto"
throughout doc-comments, .csproj/.nuspec descriptions, README, MSBuild .xaml
rule display names, and the generated XML doc. This completes brand neutrality:
- Replace 154 "Cap'n Proto" / 4 "Cap'n-Proto" / 1 "Cap'n'p" prose occurrences
with "ZAP" across 32 first-party files (runtime, generator, zapc-csharp,
MSBuild integration, chocolatey nuspecs, README, docs, XML doc).
- Revert the LICENSE provenance URL to the real upstream fork
(c80k/capnproto-dotnetcore) — upstream-fork license headers must stay.
- Canonicalize project/repo URLs to github.com/zap-proto/cs (were fabricated
c80k/zap-dotnetcore) in csproj/nuspec/VERIFICATION/README badges.
- Canonicalize docs URLs zap-protocol(.github.io|/zap-cs|/zap-cpp-core)
→ zap-proto.dev / github.com/zap-proto/{cs,cpp-core}.
- Collapse redundant "zap \"ZAP\"" PackageTags to "zap".
Verified consistent (no toolchain on host): every .sln/.csproj ProjectReference
resolves; all namespaces are Zap*/ZapC*; MSBuild task chain
(GenerateZapFileCodeBehindTask, ZapFiles ItemGroup, _ZapcCsharp_TaskAssembly)
is uniformly renamed; props/targets/xaml/coverage/chocolatey carry no capnp.
Deliberately preserved as upstream-derived test data (not first-party source):
upstream Cap'n Proto schema fixtures (rpc.zap, rpc-twoparty.zap, json.zap,
rpc-csharp.zap), golden compiler-error outputs (errors.txt), and the
machine-generated DO-NOT-EDIT test.zap.{c++,h}. Their "Cap'n Proto" strings are
the literal output of the external schema compiler the compat test matches.
254 lines
7.1 KiB
C#
254 lines
7.1 KiB
C#
using Zap.Net.Runtime.Tests.GenImpls;
|
|
using Zap.Rpc;
|
|
using Zap_test.Zap.Test;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks.Dataflow;
|
|
|
|
namespace Zap.Net.Runtime.Tests
|
|
{
|
|
[TestClass]
|
|
[TestCategory("Coverage")]
|
|
public class LocalRpc: TestBase
|
|
{
|
|
[TestMethod]
|
|
public void DeferredLocalAnswer()
|
|
{
|
|
var tcs = new TaskCompletionSource<int>();
|
|
var impl = new TestPipelineImpl2(tcs.Task);
|
|
var bproxy = BareProxy.FromImpl(impl);
|
|
using (var proxy = bproxy.Cast<ITestPipeline>(true))
|
|
using (var cap = proxy.GetCap(0, null).OutBox_Cap())
|
|
{
|
|
var foo = cap.Foo(123, true);
|
|
tcs.SetResult(0);
|
|
Assert.IsTrue(foo.Wait(TestBase.MediumNonDbgTimeout));
|
|
Assert.AreEqual("bar", foo.Result);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Embargo()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.EmbargoOnPromisedAnswer);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void EmbargoError()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.EmbargoError);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void EmbargoNull()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.EmbargoNull);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CallBrokenPromise()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.CallBrokenPromise);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TailCall()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.TailCall);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SendTwice()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.SendTwice);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Cancel()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Cancel);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RetainAndRelease()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.RetainAndRelease);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void PromiseResolve()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.PromiseResolve);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Cancelation()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Cancelation);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ReleaseOnCancel()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.ReleaseOnCancel);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Release()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Release);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Pipeline()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Pipeline);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Basic()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Basic);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Ownership1()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Ownership1);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Ownership2()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Ownership2);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Ownership3()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Ownership3);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ImportReceiverAnswer()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.Ownership3);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LegacyAccess()
|
|
{
|
|
NewLocalTestbed().RunTest(Testsuite.LegacyAccess);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void EagerRace()
|
|
{
|
|
var impl = new TestMoreStuffImpl(new Counters());
|
|
var tcs = new TaskCompletionSource<ITestMoreStuff>();
|
|
using (var promise = tcs.Task.Eager(true))
|
|
using (var cts = new CancellationTokenSource())
|
|
{
|
|
var bb = new BufferBlock<Task<uint>>();
|
|
int counter = 0;
|
|
|
|
void Generator()
|
|
{
|
|
while (!cts.IsCancellationRequested)
|
|
{
|
|
bb.Post(promise.GetCallSequence((uint)Volatile.Read(ref counter)));
|
|
Interlocked.Increment(ref counter);
|
|
}
|
|
|
|
bb.Complete();
|
|
}
|
|
|
|
async Task Verifier()
|
|
{
|
|
uint i = 0;
|
|
while (true)
|
|
{
|
|
Task<uint> t;
|
|
|
|
try
|
|
{
|
|
t = await bb.ReceiveAsync();
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
break;
|
|
}
|
|
|
|
uint j = await t;
|
|
Assert.AreEqual(i, j);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
var genTask = Task.Run(() => Generator());
|
|
var verTask = Verifier();
|
|
SpinWait.SpinUntil(() => Volatile.Read(ref counter) >= 100);
|
|
Task.Run(() => tcs.SetResult(impl));
|
|
cts.Cancel();
|
|
Assert.IsTrue(genTask.Wait(MediumNonDbgTimeout));
|
|
Assert.IsTrue(verTask.Wait(MediumNonDbgTimeout));
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void AwaitNoDeadlock()
|
|
{
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
var tcs1 = new TaskCompletionSource<int>();
|
|
var tcs2 = new TaskCompletionSource<int>();
|
|
|
|
var t1 = Zap.Util.StrictlyOrderedTaskExtensions.EnforceAwaitOrder(tcs1.Task);
|
|
var t2 = Zap.Util.StrictlyOrderedTaskExtensions.EnforceAwaitOrder(tcs2.Task);
|
|
|
|
async Task Wait1()
|
|
{
|
|
await t1;
|
|
await t2;
|
|
}
|
|
|
|
async Task Wait2()
|
|
{
|
|
await t2;
|
|
await t1;
|
|
}
|
|
|
|
var w1 = Wait1();
|
|
var w2 = Wait2();
|
|
|
|
Task.Run(() => tcs1.SetResult(0));
|
|
Task.Run(() => tcs2.SetResult(0));
|
|
|
|
Assert.IsTrue(Task.WaitAll(new Task[] { w1, w2 }, MediumNonDbgTimeout));
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void DisposedProxy()
|
|
{
|
|
var b = new BareProxy();
|
|
Assert.ThrowsException<ArgumentNullException>(() => b.Bind(null));
|
|
var impl = new TestInterfaceImpl2();
|
|
var proxy = Proxy.Share<ITestInterface>(impl);
|
|
var p = (Proxy)proxy;
|
|
Assert.ThrowsException<InvalidOperationException>(() => p.Bind(p.ConsumedCap));
|
|
Assert.IsFalse(p.IsDisposed);
|
|
proxy.Dispose();
|
|
Assert.IsTrue(p.IsDisposed);
|
|
Assert.ThrowsException<ObjectDisposedException>(() => p.ConsumedCap);
|
|
var t = proxy.Foo(123, true);
|
|
Assert.IsTrue(Assert.ThrowsExceptionAsync<ObjectDisposedException>(() => t).Wait(MediumNonDbgTimeout));
|
|
}
|
|
}
|
|
}
|