22 lines
533 B
Python
22 lines
533 B
Python
"""trace.py 单测(A1)。"""
|
|||
|
|
|
||
|
|
from app.utils.trace import current_trace, new_trace
|
||
|
|
|
||
|
|
|
||
|
|
def test_new_trace_generates_and_binds():
|
||
|
|
tid = new_trace()
|
||
|
|
assert tid.startswith("trc-")
|
||
|
|
assert len(tid) == 20 # trc- + 16 hex
|
||
|
|
assert current_trace() == tid
|
||
|
|
|
||
|
|
|
||
|
|
def test_new_trace_accepts_external_id():
|
||
|
|
tid = new_trace("trc-external-0001")
|
||
|
|
assert current_trace() == "trc-external-0001"
|
||
|
|
assert tid == "trc-external-0001"
|
||
|
|
|
||
|
|
|
||
|
|
def test_uniqueness():
|
||
|
|
ids = {new_trace() for _ in range(100)}
|
||
|
|
assert len(ids) == 100
|