Files
zeekay 2aa8261f86 rebrand: complete capnp → ZAP across all C# source/build files
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.
2026-06-19 23:46:57 -07:00

218 lines
6.0 KiB
C#

using Zap.Rpc;
using Zap.Util;
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]
public class General: TestBase
{
[TestMethod]
public void AwaitOrderTest()
{
// This test verifies an execution order assumption about the .NET environment:
// When I register multiple continuations on the same Task, using the await
// keyword, I expect all continuations be executed in the same order they were
// registered. Despite I could not find any official statement on this behavior,
// the Zap.Net.Runtime implementation relies on that assumption. Should that
// assumption turn out to be wrong, you might observe RPCs which are executed in
// a different order than they were requested.
int returnCounter = 0;
async Task ExpectCount(Task task, int count)
{
await task;
Assert.AreEqual(count, returnCounter++);
}
var tcs = new TaskCompletionSource<int>();
var tasks =
from i in Enumerable.Range(0, 100)
select ExpectCount(tcs.Task, i);
tcs.SetResult(0);
Task.WhenAll(tasks).Wait();
}
class PromisedAnswerMock : IPromisedAnswer
{
readonly TaskCompletionSource<DeserializerState> _tcs = new TaskCompletionSource<DeserializerState>();
public PromisedAnswerMock()
{
WhenReturned = _tcs.Task.EnforceAwaitOrder();
}
public StrictlyOrderedAwaitTask<DeserializerState> WhenReturned { get; }
public void Return()
{
_tcs.SetResult(default);
}
public void Cancel()
{
_tcs.SetCanceled();
}
public void Fault()
{
_tcs.SetException(new InvalidOperationException("test fault"));
}
public ConsumedCapability Access(MemberAccessPath access)
{
throw new NotImplementedException();
}
public ConsumedCapability Access(MemberAccessPath access, Task<IDisposable> proxyTask)
{
throw new NotImplementedException();
}
public bool IsTailCall => false;
public void Dispose()
{
}
}
[TestMethod]
public void MakePipelineAwareOnFastPath()
{
var mock = new PromisedAnswerMock();
mock.Return();
for (int i = 0; i < 100; i++)
{
var t = Impatient.MakePipelineAware(mock, _ => (object)null);
Assert.IsTrue(t.IsCompleted);
};
}
[TestMethod]
[TestCategory("Coverage")]
public void SafeJoinCompletedThread()
{
var thread = new Thread(() =>
{
});
thread.Start();
thread.SafeJoin(null, 200);
}
[TestMethod]
//[TestCategory("Coverage")]
public void SafeJoinBusyThread()
{
var thread = new Thread(() =>
{
try
{
while (true) ;
}
catch (ThreadInterruptedException)
{
Console.WriteLine("Interrupted");
}
catch (ThreadAbortException)
{
Console.WriteLine("Aborted");
}
});
thread.Start();
thread.SafeJoin(null, 5);
}
[TestMethod]
[TestCategory("Coverage")]
public void SafeJoinSleepingThread()
{
var thread = new Thread(() =>
{
try
{
Thread.Sleep(Timeout.Infinite);
}
catch (ThreadInterruptedException)
{
Console.WriteLine("Interrupted");
}
catch (ThreadAbortException)
{
Console.WriteLine("Aborted");
}
});
thread.Start();
thread.SafeJoin(null, 5);
}
[TestMethod]
[TestCategory("Coverage")]
public void SafeJoinDeadlockedThread()
{
var lk = new object();
lock (lk)
{
var thread = new Thread(() =>
{
try
{
lock (lk)
{
}
}
catch (ThreadInterruptedException)
{
Console.WriteLine("Interrupted");
}
catch (ThreadAbortException)
{
Console.WriteLine("Aborted");
}
});
thread.Start();
thread.SafeJoin(null, 5);
}
}
[TestMethod]
//[TestCategory("Coverage")]
public void SafeJoinDefensiveThread()
{
var thread = new Thread(() =>
{
for (; ; )
{
try
{
Thread.Sleep(Timeout.Infinite);
}
catch (ThreadInterruptedException)
{
Console.WriteLine("Interrupted");
}
catch (ThreadAbortException)
{
Console.WriteLine("Aborted");
}
}
});
thread.Start();
thread.SafeJoin(null, 5);
}
}
}