Add trace_agg.py/tests/test_core.py
This commit is contained in:
parent
7345fde6da
commit
ea0ba6784c
1 changed files with 40 additions and 0 deletions
40
trace_agg.py/tests/test_core.py
Normal file
40
trace_agg.py/tests/test_core.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import pytest
|
||||
from trace_agg.core import analyze_trace, TraceData
|
||||
|
||||
@pytest.fixture
|
||||
def sample_trace():
|
||||
return [
|
||||
TraceData(corr_id=1, event_type='write_pre', timestamp=0.0),
|
||||
TraceData(corr_id=1, event_type='read_between_steps', timestamp=0.5),
|
||||
TraceData(corr_id=1, event_type='write_post', timestamp=1.0),
|
||||
TraceData(corr_id=2, event_type='write_pre', timestamp=2.0),
|
||||
TraceData(corr_id=2, event_type='write_post', timestamp=2.2),
|
||||
TraceData(corr_id=2, event_type='read_between_steps', timestamp=3.0)
|
||||
]
|
||||
|
||||
def test_analyze_trace_basic(sample_trace):
|
||||
result = analyze_trace(sample_trace)
|
||||
assert isinstance(result, dict)
|
||||
assert all(isinstance(k, int) for k in result.keys())
|
||||
assert 1 in result and 2 in result
|
||||
|
||||
def test_analyze_trace_contains_expected_metrics(sample_trace):
|
||||
result = analyze_trace(sample_trace)
|
||||
metrics = result[1]
|
||||
assert 'window_duration' in metrics
|
||||
assert 'retry_free_reads' in metrics
|
||||
assert 'sequence_distance' in metrics
|
||||
|
||||
def test_trace_data_structure_validation():
|
||||
trace = TraceData(corr_id=7, event_type='write_pre', timestamp=0.1234)
|
||||
assert trace.corr_id == 7
|
||||
assert trace.event_type == 'write_pre'
|
||||
assert isinstance(trace.timestamp, float)
|
||||
|
||||
def test_analyze_trace_handles_empty_input():
|
||||
result = analyze_trace([])
|
||||
assert result == {} or isinstance(result, dict)
|
||||
|
||||
def test_analyze_trace_invalid_input_type():
|
||||
with pytest.raises(Exception):
|
||||
analyze_trace([{'corr_id': 1, 'event_type': 'write_pre', 'timestamp': 0.0}])
|
||||
Loading…
Reference in a new issue