using System.IO.Pipes; namespace ZB.MOM.WW.MxGateway.Worker.Tests.TestSupport; /// /// Creates the gateway-side the worker tests connect to, with an /// explicit OS buffer so a test that stops draining the pipe cannot block its own writer forever. /// /// /// The NamedPipeServerStream(string, PipeDirection, int, PipeTransmissionMode, PipeOptions) /// overload passes inBufferSize: 0 and outBufferSize: 0 to CreateNamedPipe, which /// on Windows reserves no buffer at all: a write completes only once the peer reads it. Measured on a /// Windows 10 host, the first 63-byte write to a non-reading peer never completed, against 65 520 /// bytes absorbed by the same pipe declared with 64 KiB buffers. A test-side write with no timeout /// against a stopped reader therefore hangs the test method, and a test method that never returns /// keeps xUnit from raising ITestAssemblyFinished — so testhost never exits even after /// every other test has passed. This suite runs only on Windows, so it has no macOS Unix-domain-socket /// buffer to hide behind. See the matching helper in the gateway test project. /// internal static class TestNamedPipe { /// /// The buffer reserved for each direction. Comfortably larger than any frame volume a test /// pushes at a stopped reader, and the size Windows itself uses for a typical named pipe. /// internal const int BufferBytes = 64 * 1024; /// Creates the gateway-side server pipe for . /// The pipe name the worker under test connects to. /// An asynchronous, byte-mode server pipe with explicit buffers. internal static NamedPipeServerStream CreateServer(string pipeName) { return new NamedPipeServerStream( pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, BufferBytes, BufferBytes); } }