Skip to content

Commit c60883e

Browse files
committed
PR 1 Task 1.5: smoke test for multi-measure-per-slug merge
Adds two cases to tests/t_bench_latency.nim that validate the end-to-end shape Track 1 ships: a single slug carries BOTH `throughput_ops_ms` (from bench_throughput's BMF fragment) and `latency_p50_ns` / `latency_p99_ns` (from bench_latency) AFTER `merge_bmf.py` unions the two fragments. 1. Multi-measure union — writes synthetic throughput + latency fragments on the same slug, runs python3 benchmarks/merge_bmf.py, and asserts the merged JSON carries all three measures with their original values intact. 2. Collision guard — re-declares `throughput_ops_ms` on the same slug across both inputs and asserts merge_bmf.py exits 1 with a 'collision' message in stderr. This regression-tests PR 0 Task 0.7's collision guard against silent overwrites that would erase one of the colliding measures. Both tests use createTempDir + defer removeDir for isolated, leak-free fixtures and run in <200ms because they bypass the bench compile + execute path entirely. Plan reference: impl plan Track 1 Task 1.5 (line 368-376).
1 parent 512df02 commit c60883e

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

tests/t_bench_latency.nim

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,92 @@ suite "bench_latency --bmf-out integration (Task 1.2)":
123123
let cmd = bin & " bogus_variant"
124124
let (_, exitCode) = execCmdEx(cmd)
125125
check exitCode == 1
126+
127+
# ---------- Task 1.5: multi-measure-per-slug merge ----------
128+
#
129+
# Validates the end-to-end shape that Track 1 ships: a single slug
130+
# carries BOTH `throughput_ops_ms` (from bench_throughput's BMF
131+
# fragment) and `latency_p50_ns` / `latency_p99_ns` (from bench_latency)
132+
# AFTER `merge_bmf.py` unions the two fragments. Production CI does this
133+
# with real bench output; the test uses two synthetic fragments so it
134+
# stays fast and deterministic.
135+
136+
const MergeBmfPath = RepoRoot / "benchmarks" / "merge_bmf.py"
137+
138+
suite "bench_latency multi-measure-per-slug merge (Task 1.5)":
139+
test "merge_bmf.py unions throughput + latency on shared slug":
140+
let dir = createTempDir("bench_latency_t15_", "")
141+
defer: removeDir(dir)
142+
let throughputPath = dir / "throughput.json"
143+
let latencyPath = dir / "latency.json"
144+
let mergedPath = dir / "merged.json"
145+
let slug = "lockfreequeues_sipsic/spsc/1p1c"
146+
147+
# Synthetic throughput fragment.
148+
writeFile(throughputPath,
149+
"""{
150+
"lockfreequeues_sipsic/spsc/1p1c": {
151+
"throughput_ops_ms": {
152+
"value": 1234.5,
153+
"lower_value": 1200.0,
154+
"upper_value": 1270.0
155+
}
156+
}
157+
}""")
158+
# Synthetic latency fragment on the SAME slug, distinct measures.
159+
writeFile(latencyPath,
160+
"""{
161+
"lockfreequeues_sipsic/spsc/1p1c": {
162+
"latency_p50_ns": { "value": 250.0 },
163+
"latency_p99_ns": { "value": 875.0 }
164+
}
165+
}""")
166+
167+
let cmd = "python3 " & MergeBmfPath & " " & mergedPath &
168+
" " & throughputPath & " " & latencyPath
169+
let (output, exitCode) = execCmdEx(cmd)
170+
check exitCode == 0
171+
if exitCode != 0:
172+
echo "merge stdout/stderr:\n", output
173+
check fileExists(mergedPath)
174+
175+
let node = parseJson(readFile(mergedPath))
176+
check node.hasKey(slug)
177+
let s = node[slug]
178+
# All three measures from BOTH fragments must coexist on the shared slug.
179+
check s.hasKey("throughput_ops_ms")
180+
check s.hasKey("latency_p50_ns")
181+
check s.hasKey("latency_p99_ns")
182+
check s["throughput_ops_ms"]["value"].getFloat() == 1234.5
183+
check s["latency_p50_ns"]["value"].getFloat() == 250.0
184+
check s["latency_p99_ns"]["value"].getFloat() == 875.0
185+
186+
test "merge_bmf.py exits 1 on collision when same measure key in both inputs":
187+
# Sanity: the per-slug union union semantics are NOT a free-for-all;
188+
# ensure the collision guard from PR 0 Task 0.7 still fires when the
189+
# latency fragment accidentally re-declares throughput_ops_ms on the
190+
# same slug. This guards against silent overwrites that would erase
191+
# one of the measures.
192+
let dir = createTempDir("bench_latency_t15_collide_", "")
193+
defer: removeDir(dir)
194+
let aPath = dir / "a.json"
195+
let bPath = dir / "b.json"
196+
let mergedPath = dir / "merged.json"
197+
198+
writeFile(aPath,
199+
"""{
200+
"lockfreequeues_sipsic/spsc/1p1c": {
201+
"throughput_ops_ms": { "value": 100.0 }
202+
}
203+
}""")
204+
writeFile(bPath,
205+
"""{
206+
"lockfreequeues_sipsic/spsc/1p1c": {
207+
"throughput_ops_ms": { "value": 200.0 }
208+
}
209+
}""")
210+
let cmd = "python3 " & MergeBmfPath & " " & mergedPath &
211+
" " & aPath & " " & bPath
212+
let (output, exitCode) = execCmdEx(cmd)
213+
check exitCode == 1
214+
check output.contains("collision")

0 commit comments

Comments
 (0)