Commit 0b532b2
test(metrics): eliminate coverage theater with exact value assertions (#147)
* test(metrics): eliminate coverage theater with exact value assertions
- Extract MetricCollectionHarness to shared file (remove 2 duplicate copies)
- Create OTelTestHelper for InMemoryExporter-based unit tests
- Strengthen MultipleNamedCaches: assert exact per-cache hit/miss counts
- Strengthen WithCacheName: assert ALL measurements have correct tag
- Strengthen EstimatedSize: assert exact value (42) not just non-empty
- Strengthen EvictionAfterDisposal: assert counter NOT incremented post-dispose
- Strengthen MeterFactory: verify metrics emitted through factory meter
- Strengthen AdditionalTags: assert tag contents (whitespace excluded, duplicates excluded)
- Add OpenTelemetry.Exporter.InMemory to Unit.csproj
- Net -417 lines (deduplication + stronger assertions)
* fix(test): address PR #147 review findings
- Delete dead OTelTestHelper.cs (zero callers, YAGNI)
- Remove 3 unused OTel packages from Unit.csproj
- Fix double-lookup in MetricCollectionHarness (TryGetValue)
- Fix unnecessary allocation in GetMeasurements (Array.Empty)
- Make Collect() atomic (lock spans clear+record)
- Replace Task.Yield() with Task.Delay(10, CancellationToken.None)
- Remove duplicate assertions in 3 test methods
- Add using to all MeteredMemoryCache instances (12 total)
- Fix typo in XML doc comment
All 226 tests pass (208 unit + 18 integration).
* fix: remove unused OTelTestHelper and fix vacuously true eviction test
- Delete unused OTelTestHelper.cs class (dead code with no callers)
- Remove unnecessary OpenTelemetry NuGet packages that supported it
- Fix MeteredMemoryCache_EvictionCallback_AfterDisposal_NoMetricUpdate test:
- Use CancellationChangeToken to trigger TokenExpired eviction
- TokenExpired IS counted by _evictionCount, unlike Remove
- This properly tests the disposal guard (the original test using
inner.Remove triggered EvictionReason.Removed which is excluded
from the counter regardless of disposal guard)
* fix(tests): Add Assert.NotEmpty guard in AssertAllMeasurementsHaveTags
Fix vacuous assertion that would pass when no measurements exist. The
Assert.All call passes trivially on an empty collection, allowing a
broken implementation emitting zero 'cache.requests' measurements to
pass the test.
Added Assert.NotEmpty(measurements) guard before Assert.All to ensure
the test fails if no measurements are emitted, consistent with the
pattern used in CoverageGapTests.cs for AdditionalTags tests.
* fix(test): address PR #147 review findings (round 2)
- Eliminate coverage theater: replace Assert.Contains(true,...) with AssertAllMeasurementsHaveTags in 3 shared test methods
- Fix double-lookup in GetMeasurementsWithTags (TryGetValue pattern)
- Remove DRY violation: AssertMeasurementCount delegates to AssertAggregatedCount
- Add AggregateException catch in Collect() for post-disposal safety
- Improve comment accuracy for type-mismatch and eviction scenarios
226 tests pass (208 unit + 18 integration), 0 warnings.
* fix(tests): replace remaining Assert.Contains(true,...) theater in MeteredMemoryCacheTests
Boy Scout Rule: 6 instances of Assert.Contains(true, ...Select(m => m.Tags.Any(...)))
verified 'any measurement has tag' instead of 'ALL measurements have tag'.
Added AssertAllMeasurementsHaveTag to TestListener with NotEmpty guard.
Replaced all 6 instances across 4 tests:
- WithCacheName_EmitsCacheNameTag
- OptionsConstructor_WithAdditionalTags_EmitsAllTagsOnMetrics
- TryGetValue_Generic_WithNamedCache_RecordsMetricsWithCacheName
- GetOrCreate_WithNamedCache_RecordsMetricsWithCacheName
Zero Assert.Contains(true,...) patterns remain in the test suite.
---------
Co-authored-by: Richard Murillo <rjmurillo@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>1 parent d0fbe25 commit 0b532b2
File tree
7 files changed
+503
-601
lines changed- tests/Unit
7 files changed
+503
-601
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
223 | | - | |
224 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
225 | 232 | | |
226 | 233 | | |
227 | 234 | | |
| |||
250 | 257 | | |
251 | 258 | | |
252 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
253 | 275 | | |
254 | 276 | | |
255 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
256 | 282 | | |
257 | 283 | | |
258 | 284 | | |
| 285 | + | |
259 | 286 | | |
260 | 287 | | |
261 | 288 | | |
262 | 289 | | |
263 | | - | |
264 | | - | |
265 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
266 | 297 | | |
267 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
268 | 306 | | |
269 | 307 | | |
270 | 308 | | |
| |||
288 | 326 | | |
289 | 327 | | |
290 | 328 | | |
291 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
292 | 344 | | |
293 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
294 | 361 | | |
295 | 362 | | |
296 | 363 | | |
| |||
310 | 377 | | |
311 | 378 | | |
312 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
313 | 395 | | |
314 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
315 | 417 | | |
316 | 418 | | |
317 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
| 82 | + | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 111 | + | |
| 112 | + | |
114 | 113 | | |
115 | 114 | | |
116 | 115 | | |
| |||
132 | 131 | | |
133 | 132 | | |
134 | 133 | | |
135 | | - | |
136 | | - | |
137 | | - | |
| 134 | + | |
| 135 | + | |
138 | 136 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
144 | 141 | | |
145 | 142 | | |
146 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
132 | 144 | | |
133 | 145 | | |
134 | 146 | | |
| |||
214 | 226 | | |
215 | 227 | | |
216 | 228 | | |
217 | | - | |
218 | | - | |
219 | | - | |
| 229 | + | |
| 230 | + | |
220 | 231 | | |
221 | 232 | | |
222 | 233 | | |
| |||
860 | 871 | | |
861 | 872 | | |
862 | 873 | | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
872 | 878 | | |
873 | 879 | | |
874 | 880 | | |
| |||
1025 | 1031 | | |
1026 | 1032 | | |
1027 | 1033 | | |
1028 | | - | |
1029 | | - | |
| 1034 | + | |
1030 | 1035 | | |
1031 | 1036 | | |
1032 | 1037 | | |
| |||
1052 | 1057 | | |
1053 | 1058 | | |
1054 | 1059 | | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
| 1060 | + | |
| 1061 | + | |
1058 | 1062 | | |
1059 | 1063 | | |
1060 | 1064 | | |
| |||
0 commit comments