phase 5 part 5: cs algorithms, network-os, web-security topics with tested examples; all 43 stacks pass --strict
This commit is contained in:
1 parent
f695bbd7cc
commit
691f738f5f
22 files changed
+1955
-37
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import random
|
||||
|
||||
import pytest
|
||||
|
||||
from framing import FrameDecoder, encode
|
||||
|
||||
|
||||
def test_any_split_restores_messages():
|
||||
msgs = [{"seq": i, "text": "你好" * i} for i in range(20)]
|
||||
stream = b"".join(encode(m) for m in msgs)
|
||||
rng = random.Random(42)
|
||||
for _ in range(100): # 随机切分 100 种方式
|
||||
dec, out, i = FrameDecoder(), [], 0
|
||||
while i < len(stream):
|
||||
j = i + rng.randint(1, 17)
|
||||
out += dec.feed(stream[i:j])
|
||||
i = j
|
||||
assert out == msgs
|
||||
|
||||
|
||||
def test_rejects_oversized_frame():
|
||||
with pytest.raises(ValueError):
|
||||
FrameDecoder(max_frame=10).feed(encode({"text": "x" * 100}))
|
||||
Reference in new issue
Block a user