작업자 스트림 프로토콜 독립 회귀 검사 추가
- 작성자
- 코노모리 카논
- 작성 시각
- 커밋
23a7d6ec0e7b40298f4e302fae774cb5edaa7cd8- 부모
- 260428e
변경된 파일 8개
+1,056-0| @@ -0,0 +1,421 @@ | ||
| 1 | 추가: using System.Buffers.Binary; | |
| 2 | 추가: using Zipelo.Runtime.Streaming; | |
| 3 | 추가: | |
| 4 | 추가: namespace Zipelo.StreamProtocolTests; | |
| 5 | 추가: | |
| 6 | 추가: internal static class ChannelTests | |
| 7 | 추가: { | |
| 8 | 추가: private static readonly TimeSpan Guard = TimeSpan.FromSeconds(4); | |
| 9 | 추가: | |
| 10 | 추가: public static async Task RoundTrip(int[] sizes, int fragment = int.MaxValue) | |
| 11 | 추가: { | |
| 12 | 추가: var frames = Wire.JobFrames(sizes); | |
| 13 | 추가: using var output = new ControlledStream(); | |
| 14 | 추가: using (var writer = new WorkerStreamChannel(output, WorkerStreamDirection.Write, Wire.Job)) | |
| 15 | 추가: { | |
| 16 | 추가: foreach (var frame in frames) { await Wire.Write(writer, frame); } | |
| 17 | 추가: Check.Equal(WorkerStreamPhase.Terminal, writer.Phase); | |
| 18 | 추가: Check.Equal((long)sizes.Sum(), writer.TotalDataBytes); | |
| 19 | 추가: Check.Equal(frames.Length, writer.FramesAccepted); | |
| 20 | 추가: Check.Equal((long)output.Written.Length, writer.TotalWireBytes); | |
| 21 | 추가: } | |
| 22 | 추가: Check.That(output.CanWrite, "채널이 호출자 스트림을 닫음"); | |
| 23 | 추가: Check.Bytes(Wire.Join(frames.Select(Wire.Encode).ToArray()), output.Written); | |
| 24 | 추가: using var input = new ControlledStream(output.Written) { ReadFragment = fragment }; | |
| 25 | 추가: using var reader = new WorkerStreamChannel(input, WorkerStreamDirection.Read, Wire.Job); | |
| 26 | 추가: foreach (var expected in frames) | |
| 27 | 추가: { | |
| 28 | 추가: var actual = await reader.ReadAsync() ?? throw new InvalidOperationException("조기 EOF임"); | |
| 29 | 추가: Check.Equal(expected.Header, actual.Header); | |
| 30 | 추가: Check.Bytes(expected.Payload.Span, actual.Payload.Span); | |
| 31 | 추가: } | |
| 32 | 추가: Check.Equal(WorkerStreamPhase.Terminal, reader.Phase); | |
| 33 | 추가: Check.That(await reader.ReadAsync() is null, "종료 후 EOF 확인에 실패함"); | |
| 34 | 추가: Check.Equal(WorkerStreamPhase.InputCompleted, reader.Phase); | |
| 35 | 추가: Check.Equal<WorkerStreamTerminalStatus?>(WorkerStreamTerminalStatus.Completed, reader.TerminalStatus); | |
| 36 | 추가: var calls = input.ReadCalls; | |
| 37 | 추가: Check.That(await reader.ReadAsync() is null, "완료된 수신을 재개함"); | |
| 38 | 추가: Check.Equal(calls, input.ReadCalls); | |
| 39 | 추가: Check.Equal((long)sizes.Sum(), reader.TotalDataBytes); | |
| 40 | 추가: Check.Equal((long)output.Written.Length, reader.TotalWireBytes); | |
| 41 | 추가: Check.That(input.LargestReadRequest <= 65536, "청크 상한보다 큰 읽기를 요청함"); | |
| 42 | 추가: } | |
| 43 | 추가: | |
| 44 | 추가: public static async Task GoldenHeader() | |
| 45 | 추가: { | |
| 46 | 추가: Check.Equal(64, WorkerStreamChannel.HeaderBytes); | |
| 47 | 추가: Check.Equal(65536, WorkerStreamChannel.MaxChunkBytes); | |
| 48 | 추가: Check.Equal((ushort)2, WorkerStreamChannel.Version); | |
| 49 | 추가: var expected = Convert.FromHexString( | |
| 50 | 추가: "5A49503202000100000000000000000033221100554477668899AABBCCDDEEFF" + new string('0', 64)); | |
| 51 | 추가: using var stream = new ControlledStream(); | |
| 52 | 추가: using var writer = new WorkerStreamChannel(stream, WorkerStreamDirection.Write, Wire.Job); | |
| 53 | 추가: await Wire.Write(writer, Wire.Begin); | |
| 54 | 추가: Check.Bytes(expected, stream.Written); | |
| 55 | 추가: Check.Bytes(expected, Wire.Encode(Wire.Begin)); | |
| 56 | 추가: } | |
| 57 | 추가: | |
| 58 | 추가: private static async Task Reject(byte[] bytes, int accepted, WorkerStreamError error, long? ceiling = null) | |
| 59 | 추가: { | |
| 60 | 추가: using var stream = new ControlledStream(bytes) { ReadCeiling = ceiling ?? long.MaxValue }; | |
| 61 | 추가: using var reader = new WorkerStreamChannel(stream, WorkerStreamDirection.Read, Wire.Job); | |
| 62 | 추가: for (var index = 0; index < accepted; index++) | |
| 63 | 추가: { | |
| 64 | 추가: Check.That(await reader.ReadAsync() is not null, "정상 접두 프레임이 거절됨"); | |
| 65 | 추가: } | |
| 66 | 추가: var allocatedBefore = GC.GetAllocatedBytesForCurrentThread(); | |
| 67 | 추가: var rejected = reader.ReadAsync().AsTask(); | |
| 68 | 추가: Check.That(rejected.IsCompleted, "메모리 입력 검사가 예기치 않게 대기함"); | |
| 69 | 추가: await Check.Error(error, async () => { await rejected; }); | |
| 70 | 추가: var allocated = GC.GetAllocatedBytesForCurrentThread() - allocatedBefore; | |
| 71 | 추가: Check.That(allocated >= 0 && allocated < 1024 * 1024, "작은 오류 프레임에 1 MiB 이상 할당함"); | |
| 72 | 추가: Check.Equal(WorkerStreamPhase.Faulted, reader.Phase); | |
| 73 | 추가: Check.Equal<WorkerStreamTerminalStatus?>(null, reader.TerminalStatus); | |
| 74 | 추가: await Check.Error(WorkerStreamError.Faulted, async () => { await reader.ReadAsync(); }); | |
| 75 | 추가: if (ceiling is not null) { Check.Equal(ceiling.Value, stream.BytesRead); } | |
| 76 | 추가: Check.That(stream.LargestReadRequest <= 65536, "큰 본문 읽기를 요청함"); | |
| 77 | 추가: } | |
| 78 | 추가: | |
| 79 | 추가: public static async Task TruncatedHeaders() | |
| 80 | 추가: { | |
| 81 | 추가: var bytes = Wire.Encode(Wire.Begin); | |
| 82 | 추가: for (var cut = 0; cut < 64; cut++) { await Reject(bytes[..cut], 0, WorkerStreamError.Truncated); } | |
| 83 | 추가: } | |
| 84 | 추가: | |
| 85 | 추가: public static async Task TruncatedBodies() | |
| 86 | 추가: { | |
| 87 | 추가: var item = Wire.Encode(Wire.Frame(WorkerStreamFrameKind.BeginItem, 1, Wire.Length(8), Wire.Item)); | |
| 88 | 추가: for (var cut = 0; cut < 8; cut++) | |
| 89 | 추가: { | |
| 90 | 추가: await Reject(Wire.Join(Wire.Encode(Wire.Begin), item[..(64 + cut)]), 1, WorkerStreamError.Truncated); | |
| 91 | 추가: } | |
| 92 | 추가: var frames = Wire.JobFrames(8); | |
| 93 | 추가: var data = Wire.Encode(frames[2]); | |
| 94 | 추가: for (var cut = 0; cut < 8; cut++) | |
| 95 | 추가: { | |
| 96 | 추가: await Reject(Wire.Join(Wire.Encode(frames[0]), Wire.Encode(frames[1]), data[..(64 + cut)]), | |
| 97 | 추가: 2, WorkerStreamError.Truncated); | |
| 98 | 추가: } | |
| 99 | 추가: } | |
| 100 | 추가: | |
| 101 | 추가: public static async Task FixedFields() | |
| 102 | 추가: { | |
| 103 | 추가: foreach (var offset in new[] { 0, 3, 4, 5, 12, 13, 14, 15, 56, 57, 58, 59, 60, 61, 62, 63 }) | |
| 104 | 추가: { | |
| 105 | 추가: var bytes = Wire.Encode(Wire.Begin); | |
| 106 | 추가: bytes[offset] ^= 0x80; | |
| 107 | 추가: await Reject(bytes, 0, WorkerStreamError.InvalidHeader, 64); | |
| 108 | 추가: } | |
| 109 | 추가: } | |
| 110 | 추가: | |
| 111 | 추가: public static async Task KindsAndLengths() | |
| 112 | 추가: { | |
| 113 | 추가: foreach (var kind in new ushort[] { 0, 6, ushort.MaxValue }) | |
| 114 | 추가: { | |
| 115 | 추가: var bytes = Wire.Encode(Wire.Begin); | |
| 116 | 추가: BinaryPrimitives.WriteUInt16LittleEndian(bytes.AsSpan(6), kind); | |
| 117 | 추가: await Reject(bytes, 0, WorkerStreamError.InvalidLength, 64); | |
| 118 | 추가: } | |
| 119 | 추가: foreach (var (kind, length) in new (ushort, uint)[] | |
| 120 | 추가: { | |
| 121 | 추가: (1, 1), (2, 0), (2, 7), (2, 9), (3, 0), (3, 65537), | |
| 122 | 추가: (3, int.MaxValue), (3, uint.MaxValue), (4, 0), (4, 9), (5, 0), (5, 2) | |
| 123 | 추가: }) | |
| 124 | 추가: { | |
| 125 | 추가: var bytes = Wire.Encode(Wire.Begin); | |
| 126 | 추가: BinaryPrimitives.WriteUInt16LittleEndian(bytes.AsSpan(6), kind); | |
| 127 | 추가: BinaryPrimitives.WriteUInt32LittleEndian(bytes.AsSpan(8), length); | |
| 128 | 추가: await Reject(bytes, 0, WorkerStreamError.InvalidLength, 64); | |
| 129 | 추가: } | |
| 130 | 추가: } | |
| 131 | 추가: | |
| 132 | 추가: public static async Task HugeDeclarations() | |
| 133 | 추가: { | |
| 134 | 추가: foreach (var length in new ulong[] { 16777217, int.MaxValue, (ulong)long.MaxValue, ulong.MaxValue }) | |
| 135 | 추가: { | |
| 136 | 추가: var beginItem = Wire.Frame(WorkerStreamFrameKind.BeginItem, 1, Wire.Length(length), Wire.Item); | |
| 137 | 추가: await Reject(Wire.Join(Wire.Encode(Wire.Begin), Wire.Encode(beginItem)), 1, | |
| 138 | 추가: WorkerStreamError.BudgetExceeded, 136); | |
| 139 | 추가: } | |
| 140 | 추가: var limitedItem = Wire.Frame(WorkerStreamFrameKind.BeginItem, 1, Wire.Length(0), Wire.Item); | |
| 141 | 추가: using var stream = new ControlledStream(Wire.Join(Wire.Encode(Wire.Begin), Wire.Encode(limitedItem))) | |
| 142 | 추가: { | |
| 143 | 추가: ReadCeiling = 128 | |
| 144 | 추가: }; | |
| 145 | 추가: using var reader = new WorkerStreamChannel(stream, WorkerStreamDirection.Read, Wire.Job, | |
| 146 | 추가: new() { MaxWireBytes = 129 }); | |
| 147 | 추가: await reader.ReadAsync(); | |
| 148 | 추가: await Check.Error(WorkerStreamError.BudgetExceeded, async () => { await reader.ReadAsync(); }); | |
| 149 | 추가: Check.Equal(128L, stream.BytesRead); | |
| 150 | 추가: Check.Equal(WorkerStreamPhase.Faulted, reader.Phase); | |
| 151 | 추가: } | |
| 152 | 추가: | |
| 153 | 추가: public static async Task EarlyEof() | |
| 154 | 추가: { | |
| 155 | 추가: var frames = Wire.JobFrames(1); | |
| 156 | 추가: for (var count = 0; count < frames.Length; count++) | |
| 157 | 추가: { | |
| 158 | 추가: await Reject(Wire.Join(frames.Take(count).Select(Wire.Encode).ToArray()), | |
| 159 | 추가: count, WorkerStreamError.Truncated); | |
| 160 | 추가: } | |
| 161 | 추가: } | |
| 162 | 추가: | |
| 163 | 추가: public static async Task TrailingData() | |
| 164 | 추가: { | |
| 165 | 추가: var frames = Wire.JobFrames(); | |
| 166 | 추가: var complete = Wire.Join(frames.Select(Wire.Encode).ToArray()); | |
| 167 | 추가: foreach (var suffix in new[] { new byte[] { 0 }, Wire.Encode(Wire.End(2)) }) | |
| 168 | 추가: { | |
| 169 | 추가: await Reject(Wire.Join(complete, suffix), 2, WorkerStreamError.TrailingData); | |
| 170 | 추가: } | |
| 171 | 추가: } | |
| 172 | 추가: | |
| 173 | 추가: public static async Task FailedTerminals() | |
| 174 | 추가: { | |
| 175 | 추가: foreach (var status in new byte[] { 2, 3 }) | |
| 176 | 추가: { | |
| 177 | 추가: var frames = new[] { Wire.Begin, | |
| 178 | 추가: Wire.Frame(WorkerStreamFrameKind.BeginItem, 1, Wire.Length(10), Wire.Item), Wire.End(2, status) }; | |
| 179 | 추가: using var stream = new ControlledStream(Wire.Join(frames.Select(Wire.Encode).ToArray())); | |
| 180 | 추가: using var reader = new WorkerStreamChannel(stream, WorkerStreamDirection.Read, Wire.Job); | |
| 181 | 추가: foreach (var unused in frames) { Check.That(await reader.ReadAsync() is not null, "조기 종료임"); } | |
| 182 | 추가: Check.That(await reader.ReadAsync() is null, "EOF가 아님"); | |
| 183 | 추가: Check.Equal(WorkerStreamPhase.InputCompleted, reader.Phase); | |
| 184 | 추가: Check.Equal<WorkerStreamTerminalStatus?>((WorkerStreamTerminalStatus)status, reader.TerminalStatus); | |
| 185 | 추가: } | |
| 186 | 추가: } | |
| 187 | 추가: | |
| 188 | 추가: public static async Task PreCancelled() | |
| 189 | 추가: { | |
| 190 | 추가: foreach (var direction in new[] { WorkerStreamDirection.Read, WorkerStreamDirection.Write }) | |
| 191 | 추가: { | |
| 192 | 추가: using var stream = new ControlledStream(); | |
| 193 | 추가: using var channel = new WorkerStreamChannel(stream, direction, Wire.Job); | |
| 194 | 추가: using var cancellation = new CancellationTokenSource(); | |
| 195 | 추가: cancellation.Cancel(); | |
| 196 | 추가: await Check.ThrowsAsync<OperationCanceledException>(() => direction == WorkerStreamDirection.Read | |
| 197 | 추가: ? Read(channel, cancellation.Token) : Wire.Write(channel, Wire.Begin, cancellation.Token)); | |
| 198 | 추가: Check.Equal(0, stream.ReadCalls + stream.WriteCalls); | |
| 199 | 추가: Check.Equal(WorkerStreamPhase.Faulted, channel.Phase); | |
| 200 | 추가: await Check.Error(WorkerStreamError.Faulted, () => direction == WorkerStreamDirection.Read | |
| 201 | 추가: ? Read(channel, default) : Wire.Write(channel, Wire.Begin)); | |
| 202 | 추가: } | |
| 203 | 추가: } | |
| 204 | 추가: | |
| 205 | 추가: private static async Task Read(WorkerStreamChannel channel, CancellationToken token) => | |
| 206 | 추가: _ = await channel.ReadAsync(token); | |
| 207 | 추가: | |
| 208 | 추가: public static async Task BlockedRead(bool body, bool deadline, bool resume = false) | |
| 209 | 추가: { | |
| 210 | 추가: var frames = Wire.JobFrames(8); | |
| 211 | 추가: using var stream = new ControlledStream(Wire.Join(frames.Select(Wire.Encode).ToArray())); | |
| 212 | 추가: using var channel = new WorkerStreamChannel(stream, WorkerStreamDirection.Read, Wire.Job, | |
| 213 | 추가: new() { MaxDuration = deadline ? TimeSpan.FromMilliseconds(180) : TimeSpan.FromSeconds(10) }); | |
| 214 | 추가: await channel.ReadAsync(); | |
| 215 | 추가: await channel.ReadAsync(); | |
| 216 | 추가: stream.BlockRead = stream.ReadCalls + (body ? 3 : 1); | |
| 217 | 추가: using var cancellation = new CancellationTokenSource(); | |
| 218 | 추가: var pending = channel.ReadAsync(cancellation.Token).AsTask(); | |
| 219 | 추가: try | |
| 220 | 추가: { | |
| 221 | 추가: await stream.Entered.Task.WaitAsync(Guard); | |
| 222 | 추가: Check.That(!pending.IsCompleted, "생산자를 기다리지 않고 읽기를 완료함"); | |
| 223 | 추가: Check.Equal(2, channel.FramesAccepted); | |
| 224 | 추가: if (resume) | |
| 225 | 추가: { | |
| 226 | 추가: stream.Release.TrySetResult(); | |
| 227 | 추가: var frame = await pending.WaitAsync(Guard) ?? throw new InvalidOperationException(); | |
| 228 | 추가: Check.Bytes(frames[2].Payload.Span, frame.Payload.Span); | |
| 229 | 추가: return; | |
| 230 | 추가: } | |
| 231 | 추가: if (!deadline) { cancellation.Cancel(); } | |
| 232 | 추가: if (deadline) { await Check.Error(WorkerStreamError.BudgetExceeded, async () => { await pending.WaitAsync(Guard); }); } | |
| 233 | 추가: else { await Check.ThrowsAsync<OperationCanceledException>(async () => { await pending.WaitAsync(Guard); }); } | |
| 234 | 추가: Check.Equal(WorkerStreamPhase.Faulted, channel.Phase); | |
| 235 | 추가: Check.Equal<WorkerStreamTerminalStatus?>(null, channel.TerminalStatus); | |
| 236 | 추가: if (!deadline) { await Check.Error(WorkerStreamError.Faulted, () => Read(channel, default)); } | |
| 237 | 추가: } | |
| 238 | 추가: finally | |
| 239 | 추가: { | |
| 240 | 추가: cancellation.Cancel(); | |
| 241 | 추가: try { await pending.WaitAsync(Guard); } | |
| 242 | 추가: catch (OperationCanceledException) { } | |
| 243 | 추가: catch (WorkerStreamException) { } | |
| 244 | 추가: } | |
| 245 | 추가: } | |
| 246 | 추가: | |
| 247 | 추가: public static async Task BlockedWrite(string stage, bool deadline, bool resume = false) | |
| 248 | 추가: { | |
| 249 | 추가: using var stream = new ControlledStream(); | |
| 250 | 추가: using var channel = new WorkerStreamChannel(stream, WorkerStreamDirection.Write, Wire.Job, | |
| 251 | 추가: new() { MaxDuration = deadline ? TimeSpan.FromMilliseconds(180) : TimeSpan.FromSeconds(10) }); | |
| 252 | 추가: await Wire.Write(channel, Wire.Begin); | |
| 253 | 추가: await Wire.Write(channel, Wire.Frame(WorkerStreamFrameKind.BeginItem, 1, Wire.Length(3), Wire.Item)); | |
| 254 | 추가: if (stage == "header") { stream.BlockWrite = stream.WriteCalls + 1; } | |
| 255 | 추가: if (stage == "body") { stream.BlockWrite = stream.WriteCalls + 2; } | |
| 256 | 추가: if (stage == "flush") { stream.BlockFlush = stream.FlushCalls + 1; } | |
| 257 | 추가: byte[] payload = [1, 2, 3]; | |
| 258 | 추가: var frame = Wire.Frame(WorkerStreamFrameKind.Data, 2, payload, Wire.Item); | |
| 259 | 추가: using var cancellation = new CancellationTokenSource(); | |
| 260 | 추가: var pending = Wire.Write(channel, frame, cancellation.Token); | |
| 261 | 추가: try | |
| 262 | 추가: { | |
| 263 | 추가: await stream.Entered.Task.WaitAsync(Guard); | |
| 264 | 추가: Check.That(!pending.IsCompleted, "소비자나 Flush를 기다리지 않고 완료함"); | |
| 265 | 추가: if (resume) | |
| 266 | 추가: { | |
| 267 | 추가: payload.AsSpan().Fill(99); | |
| 268 | 추가: stream.Release.TrySetResult(); | |
| 269 | 추가: await pending.WaitAsync(Guard); | |
| 270 | 추가: Check.Bytes(new byte[] { 1, 2, 3 }, stream.Written.AsSpan(200, 3)); | |
| 271 | 추가: Check.Equal(3L, channel.TotalDataBytes); | |
| 272 | 추가: return; | |
| 273 | 추가: } | |
| 274 | 추가: if (!deadline) { cancellation.Cancel(); } | |
| 275 | 추가: if (deadline) { await Check.Error(WorkerStreamError.BudgetExceeded, () => pending.WaitAsync(Guard)); } | |
| 276 | 추가: else { await Check.ThrowsAsync<OperationCanceledException>(() => pending.WaitAsync(Guard)); } | |
| 277 | 추가: Check.Equal(WorkerStreamPhase.Faulted, channel.Phase); | |
| 278 | 추가: Check.Equal<WorkerStreamTerminalStatus?>(null, channel.TerminalStatus); | |
| 279 | 추가: if (!deadline) { await Check.Error(WorkerStreamError.Faulted, () => Wire.Write(channel, Wire.Begin)); } | |
| 280 | 추가: } | |
| 281 | 추가: finally | |
| 282 | 추가: { | |
| 283 | 추가: cancellation.Cancel(); | |
| 284 | 추가: try { await pending.WaitAsync(Guard); } | |
| 285 | 추가: catch (OperationCanceledException) { } | |
| 286 | 추가: catch (WorkerStreamException) { } | |
| 287 | 추가: } | |
| 288 | 추가: } | |
| 289 | 추가: | |
| 290 | 추가: public static async Task MissingEof() | |
| 291 | 추가: { | |
| 292 | 추가: using var stream = new ControlledStream(Wire.Join(Wire.Encode(Wire.Begin), Wire.Encode(Wire.End(1)))); | |
| 293 | 추가: using var channel = new WorkerStreamChannel(stream, WorkerStreamDirection.Read, Wire.Job, | |
| 294 | 추가: new() { MaxDuration = TimeSpan.FromMilliseconds(180) }); | |
| 295 | 추가: await channel.ReadAsync(); | |
| 296 | 추가: await channel.ReadAsync(); | |
| 297 | 추가: stream.BlockRead = stream.ReadCalls + 1; | |
| 298 | 추가: await Check.Error(WorkerStreamError.BudgetExceeded, async () => { await channel.ReadAsync().AsTask().WaitAsync(Guard); }); | |
| 299 | 추가: Check.Equal(WorkerStreamPhase.Faulted, channel.Phase); | |
| 300 | 추가: Check.Equal<WorkerStreamTerminalStatus?>(null, channel.TerminalStatus); | |
| 301 | 추가: } | |
| 302 | 추가: | |
| 303 | 추가: public static async Task FinalStatePriority() | |
| 304 | 추가: { | |
| 305 | 추가: foreach (var status in new byte[] { 1, 2, 3 }) | |
| 306 | 추가: { | |
| 307 | 추가: using var stream = new ControlledStream(Wire.Join(Wire.Encode(Wire.Begin), Wire.Encode(Wire.End(1, status)))); | |
| 308 | 추가: using var reader = new WorkerStreamChannel(stream, WorkerStreamDirection.Read, Wire.Job, | |
| 309 | 추가: new() { MaxDuration = TimeSpan.FromMilliseconds(250) }); | |
| 310 | 추가: await reader.ReadAsync(); | |
| 311 | 추가: await reader.ReadAsync(); | |
| 312 | 추가: Check.That(await reader.ReadAsync() is null, "종료 EOF가 아님"); | |
| 313 | 추가: var calls = stream.ReadCalls; | |
| 314 | 추가: using var cancelled = new CancellationTokenSource(); | |
| 315 | 추가: cancelled.Cancel(); | |
| 316 | 추가: Check.That(await reader.ReadAsync(cancelled.Token) is null, "확정 EOF를 취소가 바꿈"); | |
| 317 | 추가: await Task.Delay(400); | |
| 318 | 추가: Check.That(await reader.ReadAsync() is null, "확정 EOF를 기한이 바꿈"); | |
| 319 | 추가: Check.Equal(WorkerStreamPhase.InputCompleted, reader.Phase); | |
| 320 | 추가: Check.Equal<WorkerStreamTerminalStatus?>((WorkerStreamTerminalStatus)status, reader.TerminalStatus); | |
| 321 | 추가: Check.Equal(calls, stream.ReadCalls); | |
| 322 | 추가: } | |
| 323 | 추가: | |
| 324 | 추가: var bytes = Wire.Encode(Wire.Begin); | |
| 325 | 추가: bytes[0] = 0; | |
| 326 | 추가: using var input = new ControlledStream(bytes); | |
| 327 | 추가: using var faulted = new WorkerStreamChannel(input, WorkerStreamDirection.Read, Wire.Job, | |
| 328 | 추가: new() { MaxDuration = TimeSpan.FromMilliseconds(250) }); | |
| 329 | 추가: await Check.Error(WorkerStreamError.InvalidHeader, () => Read(faulted, default)); | |
| 330 | 추가: var reads = input.ReadCalls; | |
| 331 | 추가: using var cancellation = new CancellationTokenSource(); | |
| 332 | 추가: cancellation.Cancel(); | |
| 333 | 추가: await Check.Error(WorkerStreamError.Faulted, () => Read(faulted, cancellation.Token)); | |
| 334 | 추가: await Task.Delay(400); | |
| 335 | 추가: await Check.Error(WorkerStreamError.Faulted, () => Read(faulted, default)); | |
| 336 | 추가: Check.Equal(WorkerStreamPhase.Faulted, faulted.Phase); | |
| 337 | 추가: Check.Equal<WorkerStreamTerminalStatus?>(null, faulted.TerminalStatus); | |
| 338 | 추가: Check.Equal(reads, input.ReadCalls); | |
| 339 | 추가: } | |
| 340 | 추가: | |
| 341 | 추가: public static async Task BetweenCallsDeadline() | |
| 342 | 추가: { | |
| 343 | 추가: using var stream = new ControlledStream(); | |
| 344 | 추가: using var channel = new WorkerStreamChannel(stream, WorkerStreamDirection.Write, Wire.Job, | |
| 345 | 추가: new() { MaxDuration = TimeSpan.FromMilliseconds(40) }); | |
| 346 | 추가: await Task.Delay(100); | |
| 347 | 추가: await Check.Error(WorkerStreamError.BudgetExceeded, () => Wire.Write(channel, Wire.Begin)); | |
| 348 | 추가: Check.Equal(0, stream.WriteCalls); | |
| 349 | 추가: Check.Equal(WorkerStreamPhase.Faulted, channel.Phase); | |
| 350 | 추가: } | |
| 351 | 추가: | |
| 352 | 추가: public static async Task IoFailure(bool read) | |
| 353 | 추가: { | |
| 354 | 추가: using var stream = new ControlledStream(read ? Wire.Encode(Wire.Begin) : null) | |
| 355 | 추가: { | |
| 356 | 추가: FailRead = read ? 2 : -1, FailWrite = read ? -1 : 2 | |
| 357 | 추가: }; | |
| 358 | 추가: using var channel = new WorkerStreamChannel(stream, | |
| 359 | 추가: read ? WorkerStreamDirection.Read : WorkerStreamDirection.Write, Wire.Job); | |
| 360 | 추가: var exception = await Check.ThrowsAsync<IOException>(() => read | |
| 361 | 추가: ? Read(channel, default) : Wire.Write(channel, Wire.Begin)); | |
| 362 | 추가: Check.That(ReferenceEquals(stream.Failure, exception), "원래 I/O 오류를 바꿈"); | |
| 363 | 추가: Check.Equal(WorkerStreamPhase.Faulted, channel.Phase); | |
| 364 | 추가: await Check.Error(WorkerStreamError.Faulted, () => read | |
| 365 | 추가: ? Read(channel, default) : Wire.Write(channel, Wire.Begin)); | |
| 366 | 추가: } | |
| 367 | 추가: | |
| 368 | 추가: public static async Task ConcurrentCalls() | |
| 369 | 추가: { | |
| 370 | 추가: using var stream = new ControlledStream(Wire.Encode(Wire.Begin)) { BlockRead = 1 }; | |
| 371 | 추가: using var channel = new WorkerStreamChannel(stream, WorkerStreamDirection.Read, Wire.Job); | |
| 372 | 추가: using var cancellation = new CancellationTokenSource(); | |
| 373 | 추가: var pending = channel.ReadAsync(cancellation.Token).AsTask(); | |
| 374 | 추가: try | |
| 375 | 추가: { | |
| 376 | 추가: await stream.Entered.Task.WaitAsync(Guard); | |
| 377 | 추가: await Check.ThrowsAsync<InvalidOperationException>(() => Read(channel, default)); | |
| 378 | 추가: Check.Throws<InvalidOperationException>(channel.Dispose); | |
| 379 | 추가: Check.Equal(WorkerStreamPhase.Ready, channel.Phase); | |
| 380 | 추가: stream.Release.TrySetResult(); | |
| 381 | 추가: Check.Equal(Wire.Begin.Header, (await pending.WaitAsync(Guard))!.Header); | |
| 382 | 추가: } | |
| 383 | 추가: finally | |
| 384 | 추가: { | |
| 385 | 추가: cancellation.Cancel(); | |
| 386 | 추가: try { await pending.WaitAsync(Guard); } | |
| 387 | 추가: catch (OperationCanceledException) { } | |
| 388 | 추가: } | |
| 389 | 추가: } | |
| 390 | 추가: | |
| 391 | 추가: public static async Task DirectionAndLifetime() | |
| 392 | 추가: { | |
| 393 | 추가: using var stream = new ControlledStream(); | |
| 394 | 추가: using var channel = new WorkerStreamChannel(stream, WorkerStreamDirection.Write, Wire.Job); | |
| 395 | 추가: await Check.ThrowsAsync<InvalidOperationException>(() => Read(channel, default)); | |
| 396 | 추가: Check.Equal(WorkerStreamPhase.Ready, channel.Phase); | |
| 397 | 추가: await Wire.Write(channel, Wire.Begin); | |
| 398 | 추가: channel.Dispose(); | |
| 399 | 추가: channel.Dispose(); | |
| 400 | 추가: Check.That(stream.CanWrite, "호출자 스트림을 닫음"); | |
| 401 | 추가: await Check.ThrowsAsync<ObjectDisposedException>(() => Wire.Write(channel, Wire.End(1))); | |
| 402 | 추가: } | |
| 403 | 추가: | |
| 404 | 추가: public static async Task InvalidWrite() | |
| 405 | 추가: { | |
| 406 | 추가: foreach (var length in new[] { -1, 1, 65537, int.MaxValue }) | |
| 407 | 추가: { | |
| 408 | 추가: using var stream = new ControlledStream(); | |
| 409 | 추가: using var writer = new WorkerStreamChannel(stream, WorkerStreamDirection.Write, Wire.Job); | |
| 410 | 추가: var frame = Wire.Begin with { Header = Wire.Begin.Header with { PayloadLength = length } }; | |
| 411 | 추가: await Check.Error(WorkerStreamError.InvalidLength, () => Wire.Write(writer, frame)); | |
| 412 | 추가: Check.Equal(0, stream.WriteCalls); | |
| 413 | 추가: Check.Equal(WorkerStreamPhase.Faulted, writer.Phase); | |
| 414 | 추가: } | |
| 415 | 추가: using var output = new ControlledStream(); | |
| 416 | 추가: using var channel = new WorkerStreamChannel(output, WorkerStreamDirection.Write, Wire.Job); | |
| 417 | 추가: await Check.Error(WorkerStreamError.InvalidLength, | |
| 418 | 추가: () => channel.WriteAsync(Wire.Begin.Header, new byte[] { 1 }).AsTask()); | |
| 419 | 추가: Check.Equal(0, output.WriteCalls); | |
| 420 | 추가: } | |
| 421 | 추가: } |
| @@ -0,0 +1,77 @@ | ||
| 1 | 추가: namespace Zipelo.StreamProtocolTests; | |
| 2 | 추가: | |
| 3 | 추가: // 작은 메모리 입력과 취소 가능한 한 개의 장벽만 사용하는 I/O 대역임. | |
| 4 | 추가: internal sealed class ControlledStream(byte[]? input = null) : Stream | |
| 5 | 추가: { | |
| 6 | 추가: private readonly MemoryStream inner = input is null ? new() : new(input, false); | |
| 7 | 추가: public TaskCompletionSource Entered { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously); | |
| 8 | 추가: public TaskCompletionSource Release { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously); | |
| 9 | 추가: public int ReadCalls { get; private set; } | |
| 10 | 추가: public int WriteCalls { get; private set; } | |
| 11 | 추가: public int FlushCalls { get; private set; } | |
| 12 | 추가: public long BytesRead { get; private set; } | |
| 13 | 추가: public int LargestReadRequest { get; private set; } | |
| 14 | 추가: public int ReadFragment { get; init; } = int.MaxValue; | |
| 15 | 추가: public int BlockRead { get; set; } = -1; | |
| 16 | 추가: public int BlockWrite { get; set; } = -1; | |
| 17 | 추가: public int BlockFlush { get; set; } = -1; | |
| 18 | 추가: public int FailRead { get; set; } = -1; | |
| 19 | 추가: public int FailWrite { get; set; } = -1; | |
| 20 | 추가: public long ReadCeiling { get; set; } = long.MaxValue; | |
| 21 | 추가: public IOException Failure { get; } = new("테스트 I/O 실패"); | |
| 22 | 추가: public byte[] Written => inner.ToArray(); | |
| 23 | 추가: | |
| 24 | 추가: private async Task Wait(CancellationToken token) | |
| 25 | 추가: { | |
| 26 | 추가: Entered.TrySetResult(); | |
| 27 | 추가: await Release.Task.WaitAsync(token); | |
| 28 | 추가: } | |
| 29 | 추가: | |
| 30 | 추가: public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken token = default) | |
| 31 | 추가: { | |
| 32 | 추가: ReadCalls++; | |
| 33 | 추가: LargestReadRequest = Math.Max(LargestReadRequest, buffer.Length); | |
| 34 | 추가: if (ReadCalls == FailRead) { throw Failure; } | |
| 35 | 추가: if (ReadCalls == BlockRead) { await Wait(token); } | |
| 36 | 추가: token.ThrowIfCancellationRequested(); | |
| 37 | 추가: if (buffer.Length != 0 && inner.Position >= ReadCeiling) | |
| 38 | 추가: { | |
| 39 | 추가: throw new InvalidOperationException("거절해야 할 본문에 접근함"); | |
| 40 | 추가: } | |
| 41 | 추가: var count = await inner.ReadAsync(buffer[..Math.Min(buffer.Length, ReadFragment)], token); | |
| 42 | 추가: BytesRead += count; | |
| 43 | 추가: return count; | |
| 44 | 추가: } | |
| 45 | 추가: | |
| 46 | 추가: public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken token = default) | |
| 47 | 추가: { | |
| 48 | 추가: WriteCalls++; | |
| 49 | 추가: if (WriteCalls == FailWrite) { throw Failure; } | |
| 50 | 추가: if (WriteCalls == BlockWrite) { await Wait(token); } | |
| 51 | 추가: await inner.WriteAsync(buffer, token); | |
| 52 | 추가: } | |
| 53 | 추가: | |
| 54 | 추가: public override async Task FlushAsync(CancellationToken token) | |
| 55 | 추가: { | |
| 56 | 추가: FlushCalls++; | |
| 57 | 추가: if (FlushCalls == BlockFlush) { await Wait(token); } | |
| 58 | 추가: token.ThrowIfCancellationRequested(); | |
| 59 | 추가: } | |
| 60 | 추가: | |
| 61 | 추가: protected override void Dispose(bool disposing) | |
| 62 | 추가: { | |
| 63 | 추가: if (disposing) { inner.Dispose(); } | |
| 64 | 추가: base.Dispose(disposing); | |
| 65 | 추가: } | |
| 66 | 추가: | |
| 67 | 추가: public override bool CanRead => inner.CanRead; | |
| 68 | 추가: public override bool CanWrite => inner.CanWrite; | |
| 69 | 추가: public override bool CanSeek => false; | |
| 70 | 추가: public override long Length => inner.Length; | |
| 71 | 추가: public override long Position { get => inner.Position; set => throw new NotSupportedException(); } | |
| 72 | 추가: public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException(); | |
| 73 | 추가: public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); | |
| 74 | 추가: public override void Flush() => throw new NotSupportedException(); | |
| 75 | 추가: public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); | |
| 76 | 추가: public override void SetLength(long value) => throw new NotSupportedException(); | |
| 77 | 추가: } |
| @@ -0,0 +1,6 @@ | ||
| 1 | 추가: <?xml version="1.0" encoding="utf-8"?> | |
| 2 | 추가: <configuration> | |
| 3 | 추가: <packageSources> | |
| 4 | 추가: <clear /> | |
| 5 | 추가: </packageSources> | |
| 6 | 추가: </configuration> |
| @@ -0,0 +1,89 @@ | ||
| 1 | 추가: namespace Zipelo.StreamProtocolTests; | |
| 2 | 추가: | |
| 3 | 추가: internal static class Program | |
| 4 | 추가: { | |
| 5 | 추가: private static readonly (string Name, Func<Task> Run)[] Cases = | |
| 6 | 추가: [ | |
| 7 | 추가: ("wire.empty_job", () => ChannelTests.RoundTrip([])), | |
| 8 | 추가: ("wire.empty_item", () => ChannelTests.RoundTrip([0])), | |
| 9 | 추가: ("wire.one_byte", () => ChannelTests.RoundTrip([1])), | |
| 10 | 추가: ("wire.chunk_boundaries", () => ChannelTests.RoundTrip([65535, 65536])), | |
| 11 | 추가: ("wire.fragmented_reads", () => ChannelTests.RoundTrip([1, 7, 1024], 3)), | |
| 12 | 추가: ("wire.golden_64_byte_header", () => ChannelTests.GoldenHeader()), | |
| 13 | 추가: ("wire.all_header_truncations", () => ChannelTests.TruncatedHeaders()), | |
| 14 | 추가: ("wire.metadata_and_data_truncations", () => ChannelTests.TruncatedBodies()), | |
| 15 | 추가: ("wire.magic_version_reserved", () => ChannelTests.FixedFields()), | |
| 16 | 추가: ("wire.kind_length_and_uint_overflow", () => ChannelTests.KindsAndLengths()), | |
| 17 | 추가: ("wire.huge_declaration_allocation_bound", () => ChannelTests.HugeDeclarations()), | |
| 18 | 추가: ("state.job_and_item_ids", () => ValidatorTests.Identifiers()), | |
| 19 | 추가: ("state.sequence_duplicate_gap_overflow", () => ValidatorTests.Sequences()), | |
| 20 | 추가: ("state.missing_and_nested_transitions", () => ValidatorTests.Transitions()), | |
| 21 | 추가: ("state.duplicate_item_id", () => ValidatorTests.DuplicateItem()), | |
| 22 | 추가: ("state.actual_declared_end_lengths", () => ValidatorTests.ItemLengths()), | |
| 23 | 추가: ("state.status_and_open_item", () => ValidatorTests.TerminalStatus()), | |
| 24 | 추가: ("state.failed_cancelled_eof", () => ChannelTests.FailedTerminals()), | |
| 25 | 추가: ("state.eof_before_terminal", () => ChannelTests.EarlyEof()), | |
| 26 | 추가: ("state.trailing_byte_duplicate_end", () => ChannelTests.TrailingData()), | |
| 27 | 추가: ("state.terminal_without_eof_deadline", () => ChannelTests.MissingEof()), | |
| 28 | 추가: ("state.final_status_over_cancel_and_deadline", () => ChannelTests.FinalStatePriority()), | |
| 29 | 추가: ("budget.invalid_limits", () => ValidatorTests.Limits()), | |
| 30 | 추가: ("budget.validate_header_does_not_spend", () => ValidatorTests.HeaderValidationDoesNotSpend()), | |
| 31 | 추가: ("budget.wire_exact_and_one_short", () => ValidatorTests.WireBudget()), | |
| 32 | 추가: ("budget.data_cumulative_16mib", () => ValidatorTests.DataBudget()), | |
| 33 | 추가: ("budget.small_chunk_frame_count", () => ValidatorTests.FrameBudget()), | |
| 34 | 추가: ("budget.empty_item_count", () => ValidatorTests.ItemBudget()), | |
| 35 | 추가: ("budget.signed_and_payload_lengths", () => ValidatorTests.ArithmeticLengths()), | |
| 36 | 추가: ("cancel.before_io", () => ChannelTests.PreCancelled()), | |
| 37 | 추가: ("cancel.read_header", () => ChannelTests.BlockedRead(false, false)), | |
| 38 | 추가: ("cancel.read_body", () => ChannelTests.BlockedRead(true, false)), | |
| 39 | 추가: ("cancel.write_header", () => ChannelTests.BlockedWrite("header", false)), | |
| 40 | 추가: ("cancel.write_body", () => ChannelTests.BlockedWrite("body", false)), | |
| 41 | 추가: ("cancel.write_flush", () => ChannelTests.BlockedWrite("flush", false)), | |
| 42 | 추가: ("deadline.read_wait", () => ChannelTests.BlockedRead(true, true)), | |
| 43 | 추가: ("deadline.write_wait", () => ChannelTests.BlockedWrite("body", true)), | |
| 44 | 추가: ("deadline.between_calls", () => ChannelTests.BetweenCallsDeadline()), | |
| 45 | 추가: ("flow.slow_producer", () => ChannelTests.BlockedRead(true, false, true)), | |
| 46 | 추가: ("flow.slow_consumer_snapshot", () => ChannelTests.BlockedWrite("body", false, true)), | |
| 47 | 추가: ("flow.flush_completion", () => ChannelTests.BlockedWrite("flush", false, true)), | |
| 48 | 추가: ("fault.read_io_and_reuse", () => ChannelTests.IoFailure(true)), | |
| 49 | 추가: ("fault.write_io_and_reuse", () => ChannelTests.IoFailure(false)), | |
| 50 | 추가: ("api.concurrent_call_and_dispose", () => ChannelTests.ConcurrentCalls()), | |
| 51 | 추가: ("api.direction_stream_lifetime", () => ChannelTests.DirectionAndLifetime()), | |
| 52 | 추가: ("api.invalid_write_before_output", () => ChannelTests.InvalidWrite()), | |
| 53 | 추가: ]; | |
| 54 | 추가: | |
| 55 | 추가: public static async Task<int> Main(string[] arguments) | |
| 56 | 추가: { | |
| 57 | 추가: if (arguments is ["--list"]) | |
| 58 | 추가: { | |
| 59 | 추가: foreach (var item in Cases) { Console.WriteLine(item.Name); } | |
| 60 | 추가: Console.WriteLine($"등록: {Cases.Length}"); | |
| 61 | 추가: return 0; | |
| 62 | 추가: } | |
| 63 | 추가: if (arguments.Length != 0) { return 2; } | |
| 64 | 추가: var passed = 0; | |
| 65 | 추가: var failed = 0; | |
| 66 | 추가: foreach (var (name, run) in Cases) | |
| 67 | 추가: { | |
| 68 | 추가: try | |
| 69 | 추가: { | |
| 70 | 추가: await run().WaitAsync(TimeSpan.FromSeconds(8)); | |
| 71 | 추가: Console.WriteLine($"PASS {name}"); | |
| 72 | 추가: passed++; | |
| 73 | 추가: } | |
| 74 | 추가: catch (TimeoutException) | |
| 75 | 추가: { | |
| 76 | 추가: Console.Error.WriteLine($"FAIL {name}: 검사 제한 시간 초과"); | |
| 77 | 추가: Console.WriteLine($"등록 {Cases.Length}, 통과 {passed}, 실패 {failed + 1}, 미실행 {Cases.Length - passed - failed - 1}"); | |
| 78 | 추가: return 124; | |
| 79 | 추가: } | |
| 80 | 추가: catch (Exception exception) | |
| 81 | 추가: { | |
| 82 | 추가: Console.Error.WriteLine($"FAIL {name}: {exception.GetType().Name}: {exception.Message}"); | |
| 83 | 추가: failed++; | |
| 84 | 추가: } | |
| 85 | 추가: } | |
| 86 | 추가: Console.WriteLine($"등록 {Cases.Length}, 통과 {passed}, 실패 {failed}, SKIP 0"); | |
| 87 | 추가: return failed == 0 ? 0 : 1; | |
| 88 | 추가: } | |
| 89 | 추가: } |
| @@ -0,0 +1,117 @@ | ||
| 1 | 추가: using System.Buffers.Binary; | |
| 2 | 추가: using Zipelo.Runtime.Streaming; | |
| 3 | 추가: | |
| 4 | 추가: namespace Zipelo.StreamProtocolTests; | |
| 5 | 추가: | |
| 6 | 추가: internal static class Check | |
| 7 | 추가: { | |
| 8 | 추가: public static void That(bool condition, string message) | |
| 9 | 추가: { | |
| 10 | 추가: if (!condition) { throw new InvalidOperationException(message); } | |
| 11 | 추가: } | |
| 12 | 추가: | |
| 13 | 추가: public static void Equal<T>(T expected, T actual) => | |
| 14 | 추가: That(EqualityComparer<T>.Default.Equals(expected, actual), $"기대값 {expected}, 실제값 {actual}"); | |
| 15 | 추가: | |
| 16 | 추가: public static void Bytes(ReadOnlySpan<byte> expected, ReadOnlySpan<byte> actual) => | |
| 17 | 추가: That(expected.SequenceEqual(actual), "전송 바이트가 다름"); | |
| 18 | 추가: | |
| 19 | 추가: public static T Throws<T>(Action run) where T : Exception | |
| 20 | 추가: { | |
| 21 | 추가: try { run(); } | |
| 22 | 추가: catch (T exception) { return exception; } | |
| 23 | 추가: throw new InvalidOperationException($"예상 예외가 없음: {typeof(T).Name}"); | |
| 24 | 추가: } | |
| 25 | 추가: | |
| 26 | 추가: public static async Task<T> ThrowsAsync<T>(Func<Task> run) where T : Exception | |
| 27 | 추가: { | |
| 28 | 추가: try { await run(); } | |
| 29 | 추가: catch (T exception) { return exception; } | |
| 30 | 추가: throw new InvalidOperationException($"예상 예외가 없음: {typeof(T).Name}"); | |
| 31 | 추가: } | |
| 32 | 추가: | |
| 33 | 추가: public static async Task Error(WorkerStreamError expected, Func<Task> run) => | |
| 34 | 추가: Equal(expected, (await ThrowsAsync<WorkerStreamException>(run)).Error); | |
| 35 | 추가: } | |
| 36 | 추가: | |
| 37 | 추가: internal static class Wire | |
| 38 | 추가: { | |
| 39 | 추가: public static readonly Guid Job = new("00112233-4455-6677-8899-aabbccddeeff"); | |
| 40 | 추가: public static readonly Guid Item = new("10213243-5465-7687-98a9-bacbdcedfe0f"); | |
| 41 | 추가: public static readonly Guid OtherItem = new("20314253-6475-8697-a8b9-cadbecfd0e1f"); | |
| 42 | 추가: | |
| 43 | 추가: public static byte[] Length(ulong value) | |
| 44 | 추가: { | |
| 45 | 추가: var result = new byte[8]; | |
| 46 | 추가: BinaryPrimitives.WriteUInt64LittleEndian(result, value); | |
| 47 | 추가: return result; | |
| 48 | 추가: } | |
| 49 | 추가: | |
| 50 | 추가: public static WorkerStreamFrame Frame(WorkerStreamFrameKind kind, ulong sequence, | |
| 51 | 추가: byte[]? payload = null, Guid? item = null, Guid? job = null) | |
| 52 | 추가: { | |
| 53 | 추가: var bytes = payload ?? []; | |
| 54 | 추가: return new(new(kind, job ?? Job, item ?? Guid.Empty, sequence, bytes.Length), bytes); | |
| 55 | 추가: } | |
| 56 | 추가: | |
| 57 | 추가: public static WorkerStreamFrame Begin => Frame(WorkerStreamFrameKind.BeginJob, 0); | |
| 58 | 추가: public static WorkerStreamFrame End(ulong sequence, byte status = 1) => | |
| 59 | 추가: Frame(WorkerStreamFrameKind.EndJob, sequence, [status]); | |
| 60 | 추가: | |
| 61 | 추가: // 제품 인코더를 호출하지 않는 문서 기준 바이트 픽스처임. | |
| 62 | 추가: public static byte[] Encode(WorkerStreamHeader header, ReadOnlySpan<byte> payload) | |
| 63 | 추가: { | |
| 64 | 추가: var bytes = new byte[64 + payload.Length]; | |
| 65 | 추가: "ZIP2"u8.CopyTo(bytes); | |
| 66 | 추가: BinaryPrimitives.WriteUInt16LittleEndian(bytes.AsSpan(4), 2); | |
| 67 | 추가: BinaryPrimitives.WriteUInt16LittleEndian(bytes.AsSpan(6), (ushort)header.Kind); | |
| 68 | 추가: BinaryPrimitives.WriteUInt32LittleEndian(bytes.AsSpan(8), unchecked((uint)header.PayloadLength)); | |
| 69 | 추가: header.JobId.TryWriteBytes(bytes.AsSpan(16, 16)); | |
| 70 | 추가: header.ItemId.TryWriteBytes(bytes.AsSpan(32, 16)); | |
| 71 | 추가: BinaryPrimitives.WriteUInt64LittleEndian(bytes.AsSpan(48), header.Sequence); | |
| 72 | 추가: payload.CopyTo(bytes.AsSpan(64)); | |
| 73 | 추가: return bytes; | |
| 74 | 추가: } | |
| 75 | 추가: | |
| 76 | 추가: public static byte[] Encode(WorkerStreamFrame frame) => Encode(frame.Header, frame.Payload.Span); | |
| 77 | 추가: | |
| 78 | 추가: public static byte[] Join(params byte[][] parts) | |
| 79 | 추가: { | |
| 80 | 추가: using var stream = new MemoryStream(); | |
| 81 | 추가: foreach (var part in parts) { stream.Write(part); } | |
| 82 | 추가: return stream.ToArray(); | |
| 83 | 추가: } | |
| 84 | 추가: | |
| 85 | 추가: public static WorkerStreamFrame[] JobFrames(params int[] sizes) | |
| 86 | 추가: { | |
| 87 | 추가: var frames = new List<WorkerStreamFrame> { Begin }; | |
| 88 | 추가: if (sizes.Length != 0) | |
| 89 | 추가: { | |
| 90 | 추가: var length = (ulong)sizes.Sum(); | |
| 91 | 추가: frames.Add(Frame(WorkerStreamFrameKind.BeginItem, 1, Length(length), Item)); | |
| 92 | 추가: foreach (var size in sizes) | |
| 93 | 추가: { | |
| 94 | 추가: if (size == 0) { continue; } | |
| 95 | 추가: var payload = Enumerable.Range(0, size).Select(index => (byte)(index % 251)).ToArray(); | |
| 96 | 추가: frames.Add(Frame(WorkerStreamFrameKind.Data, (ulong)frames.Count, payload, Item)); | |
| 97 | 추가: } | |
| 98 | 추가: frames.Add(Frame(WorkerStreamFrameKind.EndItem, (ulong)frames.Count, Length(length), Item)); | |
| 99 | 추가: } | |
| 100 | 추가: frames.Add(End((ulong)frames.Count)); | |
| 101 | 추가: return frames.ToArray(); | |
| 102 | 추가: } | |
| 103 | 추가: | |
| 104 | 추가: public static WorkerStreamValidator Active(ulong length = 1, WorkerStreamLimits? limits = null) | |
| 105 | 추가: { | |
| 106 | 추가: var validator = new WorkerStreamValidator(Job, limits); | |
| 107 | 추가: Accept(validator, Begin); | |
| 108 | 추가: Accept(validator, Frame(WorkerStreamFrameKind.BeginItem, 1, Length(length), Item)); | |
| 109 | 추가: return validator; | |
| 110 | 추가: } | |
| 111 | 추가: | |
| 112 | 추가: public static void Accept(WorkerStreamValidator validator, WorkerStreamFrame frame) => | |
| 113 | 추가: validator.Accept(frame.Header, frame.Payload.Span); | |
| 114 | 추가: | |
| 115 | 추가: public static async Task Write(WorkerStreamChannel channel, WorkerStreamFrame frame, | |
| 116 | 추가: CancellationToken token = default) => await channel.WriteAsync(frame.Header, frame.Payload, token); | |
| 117 | 추가: } |
| @@ -0,0 +1,225 @@ | ||
| 1 | 추가: using Zipelo.Runtime.Streaming; | |
| 2 | 추가: | |
| 3 | 추가: namespace Zipelo.StreamProtocolTests; | |
| 4 | 추가: | |
| 5 | 추가: internal static class ValidatorTests | |
| 6 | 추가: { | |
| 7 | 추가: private static void Reject(WorkerStreamValidator validator, WorkerStreamFrame frame, WorkerStreamError error) | |
| 8 | 추가: { | |
| 9 | 추가: Check.Equal(error, Check.Throws<WorkerStreamException>(() => Wire.Accept(validator, frame)).Error); | |
| 10 | 추가: Check.Equal(WorkerStreamPhase.Faulted, validator.Phase); | |
| 11 | 추가: Check.Equal<WorkerStreamTerminalStatus?>(null, validator.TerminalStatus); | |
| 12 | 추가: Check.Equal(WorkerStreamError.Faulted, | |
| 13 | 추가: Check.Throws<WorkerStreamException>(() => Wire.Accept(validator, Wire.Begin)).Error); | |
| 14 | 추가: } | |
| 15 | 추가: | |
| 16 | 추가: public static Task Identifiers() | |
| 17 | 추가: { | |
| 18 | 추가: var wrongJob = Wire.Begin with { Header = Wire.Begin.Header with { JobId = Wire.Item } }; | |
| 19 | 추가: Reject(new(Wire.Job), wrongJob, WorkerStreamError.IdMismatch); | |
| 20 | 추가: Reject(new(Wire.Job), Wire.Frame(WorkerStreamFrameKind.BeginJob, 0, item: Wire.Item), | |
| 21 | 추가: WorkerStreamError.IdMismatch); | |
| 22 | 추가: foreach (var kind in new[] { WorkerStreamFrameKind.Data, WorkerStreamFrameKind.EndItem }) | |
| 23 | 추가: { | |
| 24 | 추가: var payload = kind == WorkerStreamFrameKind.Data ? new byte[] { 1 } : Wire.Length(0); | |
| 25 | 추가: Reject(Wire.Active(), Wire.Frame(kind, 2, payload, Wire.OtherItem), WorkerStreamError.IdMismatch); | |
| 26 | 추가: } | |
| 27 | 추가: var between = new WorkerStreamValidator(Wire.Job); | |
| 28 | 추가: Wire.Accept(between, Wire.Begin); | |
| 29 | 추가: Reject(between, Wire.Frame(WorkerStreamFrameKind.BeginItem, 1, Wire.Length(0)), WorkerStreamError.IdMismatch); | |
| 30 | 추가: Reject(Wire.Active(), Wire.Frame(WorkerStreamFrameKind.EndJob, 2, [2], Wire.Item), WorkerStreamError.IdMismatch); | |
| 31 | 추가: return Task.CompletedTask; | |
| 32 | 추가: } | |
| 33 | 추가: | |
| 34 | 추가: public static Task Sequences() | |
| 35 | 추가: { | |
| 36 | 추가: foreach (var sequence in new ulong[] { 0, 1, 3, ulong.MaxValue }) | |
| 37 | 추가: { | |
| 38 | 추가: Reject(Wire.Active(), Wire.Frame(WorkerStreamFrameKind.Data, sequence, [7], Wire.Item), | |
| 39 | 추가: WorkerStreamError.SequenceMismatch); | |
| 40 | 추가: } | |
| 41 | 추가: return Task.CompletedTask; | |
| 42 | 추가: } | |
| 43 | 추가: | |
| 44 | 추가: public static Task Transitions() | |
| 45 | 추가: { | |
| 46 | 추가: Reject(new(Wire.Job), Wire.End(0), WorkerStreamError.UnexpectedFrame); | |
| 47 | 추가: Reject(new(Wire.Job), Wire.Frame(WorkerStreamFrameKind.BeginItem, 0, Wire.Length(0), Wire.Item), | |
| 48 | 추가: WorkerStreamError.UnexpectedFrame); | |
| 49 | 추가: var between = new WorkerStreamValidator(Wire.Job); | |
| 50 | 추가: Wire.Accept(between, Wire.Begin); | |
| 51 | 추가: Reject(between, Wire.Frame(WorkerStreamFrameKind.Data, 1, [1], Wire.Item), | |
| 52 | 추가: WorkerStreamError.UnexpectedFrame); | |
| 53 | 추가: Reject(Wire.Active(), Wire.Frame(WorkerStreamFrameKind.BeginItem, 2, Wire.Length(0), Wire.OtherItem), | |
| 54 | 추가: WorkerStreamError.UnexpectedFrame); | |
| 55 | 추가: Reject(Wire.Active(), Wire.Frame(WorkerStreamFrameKind.BeginJob, 2), WorkerStreamError.UnexpectedFrame); | |
| 56 | 추가: return Task.CompletedTask; | |
| 57 | 추가: } | |
| 58 | 추가: | |
| 59 | 추가: public static Task DuplicateItem() | |
| 60 | 추가: { | |
| 61 | 추가: var validator = Wire.Active(0); | |
| 62 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.EndItem, 2, Wire.Length(0), Wire.Item)); | |
| 63 | 추가: Reject(validator, Wire.Frame(WorkerStreamFrameKind.BeginItem, 3, Wire.Length(0), Wire.Item), | |
| 64 | 추가: WorkerStreamError.IdMismatch); | |
| 65 | 추가: return Task.CompletedTask; | |
| 66 | 추가: } | |
| 67 | 추가: | |
| 68 | 추가: public static Task ItemLengths() | |
| 69 | 추가: { | |
| 70 | 추가: Reject(Wire.Active(1), Wire.Frame(WorkerStreamFrameKind.EndItem, 2, Wire.Length(0), Wire.Item), | |
| 71 | 추가: WorkerStreamError.InvalidLength); | |
| 72 | 추가: var validator = Wire.Active(1); | |
| 73 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.Data, 2, [1], Wire.Item)); | |
| 74 | 추가: Reject(validator, Wire.Frame(WorkerStreamFrameKind.EndItem, 3, Wire.Length(ulong.MaxValue), Wire.Item), | |
| 75 | 추가: WorkerStreamError.InvalidLength); | |
| 76 | 추가: Reject(Wire.Active(0), Wire.Frame(WorkerStreamFrameKind.Data, 2, [1], Wire.Item), | |
| 77 | 추가: WorkerStreamError.BudgetExceeded); | |
| 78 | 추가: return Task.CompletedTask; | |
| 79 | 추가: } | |
| 80 | 추가: | |
| 81 | 추가: public static Task TerminalStatus() | |
| 82 | 추가: { | |
| 83 | 추가: Reject(Wire.Active(), Wire.End(2), WorkerStreamError.UnexpectedFrame); | |
| 84 | 추가: foreach (var status in new byte[] { 0, 4, 255 }) | |
| 85 | 추가: { | |
| 86 | 추가: Reject(Wire.Active(), Wire.End(2, status), WorkerStreamError.UnexpectedFrame); | |
| 87 | 추가: } | |
| 88 | 추가: foreach (var status in new byte[] { 2, 3 }) | |
| 89 | 추가: { | |
| 90 | 추가: var validator = Wire.Active(1); | |
| 91 | 추가: Wire.Accept(validator, Wire.End(2, status)); | |
| 92 | 추가: Check.Equal(WorkerStreamPhase.Terminal, validator.Phase); | |
| 93 | 추가: validator.CompleteInput(); | |
| 94 | 추가: Check.Equal(WorkerStreamPhase.InputCompleted, validator.Phase); | |
| 95 | 추가: Check.Equal<WorkerStreamTerminalStatus?>((WorkerStreamTerminalStatus)status, validator.TerminalStatus); | |
| 96 | 추가: } | |
| 97 | 추가: return Task.CompletedTask; | |
| 98 | 추가: } | |
| 99 | 추가: | |
| 100 | 추가: public static Task Limits() | |
| 101 | 추가: { | |
| 102 | 추가: var defaults = new WorkerStreamLimits(); | |
| 103 | 추가: foreach (var value in new[] | |
| 104 | 추가: { | |
| 105 | 추가: defaults with { MaxDataBytes = -1 }, defaults with { MaxDataBytes = long.MaxValue }, | |
| 106 | 추가: defaults with { MaxWireBytes = 128 }, defaults with { MaxWireBytes = long.MaxValue }, | |
| 107 | 추가: defaults with { MaxItems = -1 }, defaults with { MaxItems = int.MaxValue }, | |
| 108 | 추가: defaults with { MaxFrames = 1 }, defaults with { MaxFrames = int.MaxValue }, | |
| 109 | 추가: defaults with { MaxDuration = TimeSpan.Zero }, defaults with { MaxDuration = TimeSpan.MaxValue } | |
| 110 | 추가: }) | |
| 111 | 추가: { | |
| 112 | 추가: Check.Throws<ArgumentOutOfRangeException>(() => new WorkerStreamValidator(Wire.Job, value)); | |
| 113 | 추가: } | |
| 114 | 추가: Check.Throws<ArgumentException>(() => new WorkerStreamValidator(Guid.Empty)); | |
| 115 | 추가: var minimal = new WorkerStreamValidator(Wire.Job, defaults with | |
| 116 | 추가: { | |
| 117 | 추가: MaxDataBytes = 0, MaxItems = 0, MaxFrames = 2, MaxWireBytes = 129 | |
| 118 | 추가: }); | |
| 119 | 추가: Wire.Accept(minimal, Wire.Begin); | |
| 120 | 추가: Wire.Accept(minimal, Wire.End(1)); | |
| 121 | 추가: minimal.CompleteInput(); | |
| 122 | 추가: Check.Equal(129L, minimal.TotalWireBytes); | |
| 123 | 추가: return Task.CompletedTask; | |
| 124 | 추가: } | |
| 125 | 추가: | |
| 126 | 추가: public static Task HeaderValidationDoesNotSpend() | |
| 127 | 추가: { | |
| 128 | 추가: var validator = new WorkerStreamValidator(Wire.Job); | |
| 129 | 추가: validator.ValidateHeader(Wire.Begin.Header); | |
| 130 | 추가: validator.ValidateHeader(Wire.Begin.Header); | |
| 131 | 추가: Check.Equal(0, validator.FramesAccepted); | |
| 132 | 추가: Check.Equal(0L, validator.TotalWireBytes); | |
| 133 | 추가: Wire.Accept(validator, Wire.Begin); | |
| 134 | 추가: Check.Equal(1, validator.FramesAccepted); | |
| 135 | 추가: Check.Equal(64L, validator.TotalWireBytes); | |
| 136 | 추가: return Task.CompletedTask; | |
| 137 | 추가: } | |
| 138 | 추가: | |
| 139 | 추가: public static Task WireBudget() | |
| 140 | 추가: { | |
| 141 | 추가: foreach (var budget in new long[] { 129, 273 }) | |
| 142 | 추가: { | |
| 143 | 추가: var validator = new WorkerStreamValidator(Wire.Job, new() { MaxWireBytes = budget }); | |
| 144 | 추가: Wire.Accept(validator, Wire.Begin); | |
| 145 | 추가: if (budget == 273) | |
| 146 | 추가: { | |
| 147 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.BeginItem, 1, Wire.Length(0), Wire.Item)); | |
| 148 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.EndItem, 2, Wire.Length(0), Wire.Item)); | |
| 149 | 추가: } | |
| 150 | 추가: Wire.Accept(validator, Wire.End((ulong)validator.FramesAccepted)); | |
| 151 | 추가: Check.Equal(budget, validator.TotalWireBytes); | |
| 152 | 추가: } | |
| 153 | 추가: var insufficient = new WorkerStreamValidator(Wire.Job, new() { MaxWireBytes = 272 }); | |
| 154 | 추가: Wire.Accept(insufficient, Wire.Begin); | |
| 155 | 추가: Wire.Accept(insufficient, Wire.Frame(WorkerStreamFrameKind.BeginItem, 1, Wire.Length(0), Wire.Item)); | |
| 156 | 추가: Wire.Accept(insufficient, Wire.Frame(WorkerStreamFrameKind.EndItem, 2, Wire.Length(0), Wire.Item)); | |
| 157 | 추가: Reject(insufficient, Wire.End(3), WorkerStreamError.BudgetExceeded); | |
| 158 | 추가: return Task.CompletedTask; | |
| 159 | 추가: } | |
| 160 | 추가: | |
| 161 | 추가: public static Task DataBudget() | |
| 162 | 추가: { | |
| 163 | 추가: // 64 KiB 버퍼 하나를 재사용해 16 MiB 누적 경계만 검사함. | |
| 164 | 추가: var validator = new WorkerStreamValidator(Wire.Job); | |
| 165 | 추가: Wire.Accept(validator, Wire.Begin); | |
| 166 | 추가: var chunk = new byte[65536]; | |
| 167 | 추가: foreach (var id in new[] { Wire.Item, Wire.OtherItem }) | |
| 168 | 추가: { | |
| 169 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.BeginItem, | |
| 170 | 추가: (ulong)validator.FramesAccepted, Wire.Length(8 * 1024 * 1024), id)); | |
| 171 | 추가: for (var index = 0; index < 128; index++) | |
| 172 | 추가: { | |
| 173 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.Data, | |
| 174 | 추가: (ulong)validator.FramesAccepted, chunk, id)); | |
| 175 | 추가: } | |
| 176 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.EndItem, | |
| 177 | 추가: (ulong)validator.FramesAccepted, Wire.Length(8 * 1024 * 1024), id)); | |
| 178 | 추가: } | |
| 179 | 추가: Check.Equal(16L * 1024 * 1024, validator.TotalDataBytes); | |
| 180 | 추가: Wire.Accept(validator, Wire.End((ulong)validator.FramesAccepted)); | |
| 181 | 추가: validator.CompleteInput(); | |
| 182 | 추가: | |
| 183 | 추가: var limited = Wire.Active(1, new() { MaxDataBytes = 1 }); | |
| 184 | 추가: Wire.Accept(limited, Wire.Frame(WorkerStreamFrameKind.Data, 2, [1], Wire.Item)); | |
| 185 | 추가: Wire.Accept(limited, Wire.Frame(WorkerStreamFrameKind.EndItem, 3, Wire.Length(1), Wire.Item)); | |
| 186 | 추가: Reject(limited, Wire.Frame(WorkerStreamFrameKind.BeginItem, 4, Wire.Length(1), Wire.OtherItem), | |
| 187 | 추가: WorkerStreamError.BudgetExceeded); | |
| 188 | 추가: return Task.CompletedTask; | |
| 189 | 추가: } | |
| 190 | 추가: | |
| 191 | 추가: public static Task FrameBudget() | |
| 192 | 추가: { | |
| 193 | 추가: var validator = Wire.Active(2, new() { MaxFrames = 5 }); | |
| 194 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.Data, 2, [1], Wire.Item)); | |
| 195 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.Data, 3, [2], Wire.Item)); | |
| 196 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.EndItem, 4, Wire.Length(2), Wire.Item)); | |
| 197 | 추가: Check.Equal(5, validator.FramesAccepted); | |
| 198 | 추가: Reject(validator, Wire.End(5), WorkerStreamError.BudgetExceeded); | |
| 199 | 추가: return Task.CompletedTask; | |
| 200 | 추가: } | |
| 201 | 추가: | |
| 202 | 추가: public static Task ItemBudget() | |
| 203 | 추가: { | |
| 204 | 추가: var validator = Wire.Active(0, new() { MaxItems = 1 }); | |
| 205 | 추가: Wire.Accept(validator, Wire.Frame(WorkerStreamFrameKind.EndItem, 2, Wire.Length(0), Wire.Item)); | |
| 206 | 추가: Check.Equal(1, validator.ItemsAccepted); | |
| 207 | 추가: Reject(validator, Wire.Frame(WorkerStreamFrameKind.BeginItem, 3, Wire.Length(0), Wire.OtherItem), | |
| 208 | 추가: WorkerStreamError.BudgetExceeded); | |
| 209 | 추가: return Task.CompletedTask; | |
| 210 | 추가: } | |
| 211 | 추가: | |
| 212 | 추가: public static Task ArithmeticLengths() | |
| 213 | 추가: { | |
| 214 | 추가: foreach (var length in new[] { int.MinValue, -1, 0, 65537, int.MaxValue }) | |
| 215 | 추가: { | |
| 216 | 추가: var frame = Wire.Frame(WorkerStreamFrameKind.Data, 2, [1], Wire.Item); | |
| 217 | 추가: Reject(Wire.Active(), frame with { Header = frame.Header with { PayloadLength = length } }, | |
| 218 | 추가: WorkerStreamError.InvalidLength); | |
| 219 | 추가: } | |
| 220 | 추가: var validator = Wire.Active(); | |
| 221 | 추가: var mismatched = Wire.Frame(WorkerStreamFrameKind.Data, 2, [1], Wire.Item) with { Payload = new byte[2] }; | |
| 222 | 추가: Reject(validator, mismatched, WorkerStreamError.InvalidLength); | |
| 223 | 추가: return Task.CompletedTask; | |
| 224 | 추가: } | |
| 225 | 추가: } |
| @@ -0,0 +1,18 @@ | ||
| 1 | 추가: <Project Sdk="Microsoft.NET.Sdk"> | |
| 2 | 추가: <PropertyGroup> | |
| 3 | 추가: <OutputType>Exe</OutputType> | |
| 4 | 추가: <TargetFramework>net10.0</TargetFramework> | |
| 5 | 추가: <Nullable>enable</Nullable> | |
| 6 | 추가: <ImplicitUsings>enable</ImplicitUsings> | |
| 7 | 추가: <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | |
| 8 | 추가: <EnableDefaultCompileItems>false</EnableDefaultCompileItems> | |
| 9 | 추가: </PropertyGroup> | |
| 10 | 추가: <ItemGroup> | |
| 11 | 추가: <Compile Include="Program.cs" /> | |
| 12 | 추가: <Compile Include="TestSupport.cs" /> | |
| 13 | 추가: <Compile Include="ControlledStream.cs" /> | |
| 14 | 추가: <Compile Include="ChannelTests.cs" /> | |
| 15 | 추가: <Compile Include="ValidatorTests.cs" /> | |
| 16 | 추가: <ProjectReference Include="../../src/Zipelo.Runtime/Zipelo.Runtime.csproj" /> | |
| 17 | 추가: </ItemGroup> | |
| 18 | 추가: </Project> |
| @@ -0,0 +1,103 @@ | ||
| 1 | 추가: { | |
| 2 | 추가: "schema_version": 1, | |
| 3 | 추가: "base_commit": "260428ec8836bf122589d995c7526468a09e190d", | |
| 4 | 추가: "dependency": { | |
| 5 | 추가: "pr": "https://github.com/Team-LJY/zipelo/pull/7", | |
| 6 | 추가: "head": "6fe660aa914dec9e4d2f4c8f85e8ff3932a805a6", | |
| 7 | 추가: "files": { | |
| 8 | 추가: "src/Zipelo.Runtime/Streaming/WorkerStreamContract.cs": "0e8e8c21478224d6ed861e50a5ec310dce8b6af522ce3d66e4f899a926cf7a94", | |
| 9 | 추가: "src/Zipelo.Runtime/Streaming/WorkerStreamValidator.cs": "933e93fc4d4cae7ac9e1bc0621ed0598994ff057ff0c320c7dc5f7cc59ada09a", | |
| 10 | 추가: "src/Zipelo.Runtime/Streaming/WorkerStreamChannel.cs": "4109e345138763df3ecec0368755660b5891349567908ac7ddb996b38ca94046" | |
| 11 | 추가: }, | |
| 12 | 추가: "original_requested_head": "1235f8e2f3bf0d505ed7e7c9dffc74332827f2bf", | |
| 13 | 추가: "update": "종료 상태 우선순위 수정이 작업 중 추가됨. InputCompleted 재읽기와 Faulted 재읽기는 취소/만료 기한보다 먼저 확정 상태를 처리함. 새 회귀 사례는 이전 1235f8e2의 재읽기 결함을 통과로 완화하지 않음" | |
| 14 | 추가: }, | |
| 15 | 추가: "registered_cases": [ | |
| 16 | 추가: "wire.empty_job", | |
| 17 | 추가: "wire.empty_item", | |
| 18 | 추가: "wire.one_byte", | |
| 19 | 추가: "wire.chunk_boundaries", | |
| 20 | 추가: "wire.fragmented_reads", | |
| 21 | 추가: "wire.golden_64_byte_header", | |
| 22 | 추가: "wire.all_header_truncations", | |
| 23 | 추가: "wire.metadata_and_data_truncations", | |
| 24 | 추가: "wire.magic_version_reserved", | |
| 25 | 추가: "wire.kind_length_and_uint_overflow", | |
| 26 | 추가: "wire.huge_declaration_allocation_bound", | |
| 27 | 추가: "state.job_and_item_ids", | |
| 28 | 추가: "state.sequence_duplicate_gap_overflow", | |
| 29 | 추가: "state.missing_and_nested_transitions", | |
| 30 | 추가: "state.duplicate_item_id", | |
| 31 | 추가: "state.actual_declared_end_lengths", | |
| 32 | 추가: "state.status_and_open_item", | |
| 33 | 추가: "state.failed_cancelled_eof", | |
| 34 | 추가: "state.eof_before_terminal", | |
| 35 | 추가: "state.trailing_byte_duplicate_end", | |
| 36 | 추가: "state.terminal_without_eof_deadline", | |
| 37 | 추가: "state.final_status_over_cancel_and_deadline", | |
| 38 | 추가: "budget.invalid_limits", | |
| 39 | 추가: "budget.validate_header_does_not_spend", | |
| 40 | 추가: "budget.wire_exact_and_one_short", | |
| 41 | 추가: "budget.data_cumulative_16mib", | |
| 42 | 추가: "budget.small_chunk_frame_count", | |
| 43 | 추가: "budget.empty_item_count", | |
| 44 | 추가: "budget.signed_and_payload_lengths", | |
| 45 | 추가: "cancel.before_io", | |
| 46 | 추가: "cancel.read_header", | |
| 47 | 추가: "cancel.read_body", | |
| 48 | 추가: "cancel.write_header", | |
| 49 | 추가: "cancel.write_body", | |
| 50 | 추가: "cancel.write_flush", | |
| 51 | 추가: "deadline.read_wait", | |
| 52 | 추가: "deadline.write_wait", | |
| 53 | 추가: "deadline.between_calls", | |
| 54 | 추가: "flow.slow_producer", | |
| 55 | 추가: "flow.slow_consumer_snapshot", | |
| 56 | 추가: "flow.flush_completion", | |
| 57 | 추가: "fault.read_io_and_reuse", | |
| 58 | 추가: "fault.write_io_and_reuse", | |
| 59 | 추가: "api.concurrent_call_and_dispose", | |
| 60 | 추가: "api.direction_stream_lifetime", | |
| 61 | 추가: "api.invalid_write_before_output" | |
| 62 | 추가: ], | |
| 63 | 추가: "registered_count": 46, | |
| 64 | 추가: "commands": { | |
| 65 | 추가: "build": "dotnet build tests/stream-protocol/Zipelo.StreamProtocolTests.csproj -c Release --configfile tests/stream-protocol/NuGet.Config --artifacts-path tests/stream-protocol/.work/artifacts -o tests/stream-protocol/.work/bin -p:UseAppHost=false --disable-build-servers", | |
| 66 | 추가: "list": "dotnet tests/stream-protocol/.work/bin/Zipelo.StreamProtocolTests.dll --list", | |
| 67 | 추가: "run": "dotnet tests/stream-protocol/.work/bin/Zipelo.StreamProtocolTests.dll", | |
| 68 | 추가: "self_contained": "중앙 SDK 환경에서 같은 프로젝트를 OS별 RID와 --self-contained true로 별도 tests/stream-protocol/.work 출력에 게시한 뒤 Zipelo.StreamProtocolTests 앱호스트를 무인수 실행함. Windows만 .exe를 붙임" | |
| 69 | 추가: }, | |
| 70 | 추가: "scope": "기존 98개, PR #6, v1 실행 경로와 16 MiB 상한은 변경하지 않음. 이 프로젝트는 파일을 열거나 Worker 프로세스를 시작하지 않는 메모리 전송 계약 검사임", | |
| 71 | 추가: "bounds": { | |
| 72 | 추가: "header_bytes": 64, | |
| 73 | 추가: "chunk_bytes": 65536, | |
| 74 | 추가: "default_data_bytes": 16777216, | |
| 75 | 추가: "default_wire_bytes": 22020096, | |
| 76 | 추가: "large_cumulative_test": "64 KiB 배열 하나를 두 항목에서 256번 재사용함. 16 MiB 실제 파일이나 전체 결과 배열을 생성하지 않음", | |
| 77 | 추가: "roundtrip": "최대 정상 왕복 페이로드 합계 131071바이트. 프레임 및 출력 복사는 이 작은 입력 크기로 제한됨", | |
| 78 | 추가: "hostile_lengths": "고정 64바이트 헤더 또는 8바이트 선언만 제공함. 거절 시 본문 접근 금지와 동일 스레드의 동기 완료 호출당 1 MiB 미만 할당을 요구함. 이는 프로세스 최대 메모리/성능 측정이 아님", | |
| 79 | 추가: "waiting": "게이트 1개와 협조적 취소를 사용함. 대기 진입 확인 4초, 사례별 8초 상한. 전체 기한 검사는 40/180/250ms 제한을 사용함. 매우 느린 검증 환경의 실패는 로그를 보고 분리해야 함" | |
| 80 | 추가: }, | |
| 81 | 추가: "validation": { | |
| 82 | 추가: "static": "passed: XML/JSON, 46 unique registrations, 5 explicit compile items, dependency SHA-256, golden header size, formatting and delimiter inspection; not C# compilation", | |
| 83 | 추가: "compile": "not_run: local SDK absent", | |
| 84 | 추가: "windows": "not_run", | |
| 85 | 추가: "ubuntu": "not_run" | |
| 86 | 추가: }, | |
| 87 | 추가: "limitations": [ | |
| 88 | 추가: "실제 stdin/stdout 파이프와 Worker 프로세스 통합은 PR #7 범위 밖이며 미검증", | |
| 89 | 추가: "취소를 무시하는 Stream의 강제 중단, 디스크 게시/CRC/경로, 양방향 예산은 검증하지 않음", | |
| 90 | 추가: "큰 실제 파일의 처리량과 최대 메모리 개선을 주장하지 않음", | |
| 91 | 추가: "반환 프레임을 호출자가 무제한 보관하는 상황은 다루지 않음" | |
| 92 | 추가: ], | |
| 93 | 추가: "files": [ | |
| 94 | 추가: "tests/stream-protocol/ChannelTests.cs", | |
| 95 | 추가: "tests/stream-protocol/ControlledStream.cs", | |
| 96 | 추가: "tests/stream-protocol/NuGet.Config", | |
| 97 | 추가: "tests/stream-protocol/Program.cs", | |
| 98 | 추가: "tests/stream-protocol/TestSupport.cs", | |
| 99 | 추가: "tests/stream-protocol/ValidatorTests.cs", | |
| 100 | 추가: "tests/stream-protocol/Zipelo.StreamProtocolTests.csproj", | |
| 101 | 추가: "tests/stream-protocol/contract.json" | |
| 102 | 추가: ] | |
| 103 | 추가: } |