Skip to content

Commit 75ffee6

Browse files
committed
Address feedback
1 parent 1e5900a commit 75ffee6

File tree

2 files changed

+29
-40
lines changed

2 files changed

+29
-40
lines changed

tests/integration/test_mooncake_trace.py

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def test_basic_mooncake_trace_with_input_length(
4444
--input-file {trace_file} \
4545
--custom-dataset-type mooncake_trace \
4646
--request-count {request_count} \
47-
--concurrency {defaults.concurrency} \
47+
--fixed-schedule \
4848
--workers-max {defaults.workers_max} \
4949
--ui {defaults.ui}
5050
"""
@@ -60,14 +60,16 @@ async def test_mooncake_trace_with_text_input(
6060
tmp_path: Path,
6161
):
6262
"""Test Mooncake trace with literal text inputs instead of input_length."""
63+
# Each trace is a single-turn conversation; timestamp required for --fixed-schedule
6364
traces = [
64-
{"text_input": "What is the capital of France?", "output_length": 20},
65-
{"text_input": "Explain quantum computing briefly.", "output_length": 30},
66-
{"text_input": "Write a haiku about programming.", "output_length": 25},
67-
{"text_input": "What is machine learning?", "output_length": 40},
68-
{"text_input": "Describe the solar system.", "output_length": 35},
69-
]
65+
{"timestamp": 0, "text_input": "What is the capital of France?", "output_length": 20},
66+
{"timestamp": 100, "text_input": "Explain quantum computing briefly.", "output_length": 30},
67+
{"timestamp": 200, "text_input": "Write a haiku about programming.", "output_length": 25},
68+
{"timestamp": 300, "text_input": "What is machine learning?", "output_length": 40},
69+
{"timestamp": 400, "text_input": "Describe the solar system.", "output_length": 35},
70+
] # fmt: skip
7071
trace_file = create_mooncake_trace_file(tmp_path, traces)
72+
request_count = len(traces)
7173

7274
result = await cli.run(
7375
f"""
@@ -77,14 +79,14 @@ async def test_mooncake_trace_with_text_input(
7779
--endpoint-type chat \
7880
--input-file {trace_file} \
7981
--custom-dataset-type mooncake_trace \
80-
--request-count {defaults.request_count} \
81-
--concurrency {defaults.concurrency} \
82+
--request-count {request_count} \
83+
--fixed-schedule \
8284
--workers-max {defaults.workers_max} \
8385
--ui {defaults.ui}
8486
"""
8587
)
8688

87-
assert result.request_count == defaults.request_count
89+
assert result.request_count == request_count
8890
assert result.has_all_outputs
8991

9092
async def test_mooncake_trace_multi_turn_with_session_id(
@@ -94,33 +96,20 @@ async def test_mooncake_trace_multi_turn_with_session_id(
9496
tmp_path: Path,
9597
):
9698
"""Test Mooncake trace with session_id for multi-turn conversations."""
99+
# First turn of each session needs timestamp; subsequent turns use delay
97100
traces = [
98-
# Session 1: Two-turn conversation
99-
{"session_id": "session-1", "input_length": 100, "output_length": 40},
100-
{
101-
"session_id": "session-1",
102-
"delay": 500,
103-
"input_length": 150,
104-
"output_length": 50,
105-
},
106-
# Session 2: Single-turn
107-
{"session_id": "session-2", "input_length": 200, "output_length": 60},
108-
# Session 3: Three-turn conversation
109-
{"session_id": "session-3", "input_length": 80, "output_length": 30},
110-
{
111-
"session_id": "session-3",
112-
"delay": 300,
113-
"input_length": 120,
114-
"output_length": 45,
115-
},
116-
{
117-
"session_id": "session-3",
118-
"delay": 400,
119-
"input_length": 90,
120-
"output_length": 35,
121-
},
122-
]
101+
# Session 1: Two-turn conversation (starts at t=0)
102+
{"session_id": "session-1", "timestamp": 0, "input_length": 100, "output_length": 40},
103+
{"session_id": "session-1", "delay": 500, "input_length": 150, "output_length": 50},
104+
# Session 2: Single-turn (starts at t=100)
105+
{"session_id": "session-2", "timestamp": 100, "input_length": 200, "output_length": 60},
106+
# Session 3: Three-turn conversation (starts at t=200)
107+
{"session_id": "session-3", "timestamp": 200, "input_length": 80, "output_length": 30},
108+
{"session_id": "session-3", "delay": 300, "input_length": 120, "output_length": 45},
109+
{"session_id": "session-3", "delay": 400, "input_length": 90, "output_length": 35},
110+
] # fmt: skip
123111
trace_file = create_mooncake_trace_file(tmp_path, traces)
112+
request_count = len(traces) # Each turn is a request
124113

125114
result = await cli.run(
126115
f"""
@@ -130,12 +119,12 @@ async def test_mooncake_trace_multi_turn_with_session_id(
130119
--endpoint-type chat \
131120
--input-file {trace_file} \
132121
--custom-dataset-type mooncake_trace \
133-
--request-count {defaults.request_count} \
134-
--concurrency {defaults.concurrency} \
122+
--request-count {request_count} \
123+
--fixed-schedule \
135124
--workers-max {defaults.workers_max} \
136125
--ui {defaults.ui}
137126
"""
138127
)
139128

140-
assert result.request_count == defaults.request_count
129+
assert result.request_count == request_count
141130
assert result.has_all_outputs

tests/integration/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def create_mooncake_trace_file(
3030
Path to the created trace file
3131
"""
3232
trace_file = tmp_path / filename
33-
with open(trace_file, "w") as f:
33+
with open(trace_file, "wb") as f:
3434
for trace in traces:
35-
f.write(orjson.dumps(trace).decode("utf-8") + "\n")
35+
f.write(orjson.dumps(trace) + b"\n")
3636
return trace_file
3737

3838

0 commit comments

Comments
 (0)