refactor(tests): Replace assert with require for guard assertions#46913
Conversation
Files inventory check summaryFile checks results against ancestor cfd74cd9: Results for datadog-agent_7.78.0~devel.git.137.172c742.pipeline.99461255-1_amd64.deb:No change detected |
Static quality checks✅ Please find below the results from static quality gates 31 successful checks with minimal change (< 2 KiB)
On-wire sizes (compressed)
|
Regression DetectorRegression Detector ResultsMetrics dashboard Baseline: d1a622c Optimization Goals: ✅ No significant changes detected
|
| perf | experiment | goal | Δ mean % | Δ mean % CI | trials | links |
|---|---|---|---|---|---|---|
| ➖ | docker_containers_cpu | % cpu utilization | -0.50 | [-3.63, +2.64] | 1 | Logs |
Fine details of change detection per experiment
| perf | experiment | goal | Δ mean % | Δ mean % CI | trials | links |
|---|---|---|---|---|---|---|
| ➖ | quality_gate_logs | % cpu utilization | +2.99 | [+1.48, +4.50] | 1 | Logs bounds checks dashboard |
| ➖ | ddot_logs | memory utilization | +0.71 | [+0.65, +0.77] | 1 | Logs |
| ➖ | ddot_metrics_sum_cumulative | memory utilization | +0.57 | [+0.43, +0.71] | 1 | Logs |
| ➖ | quality_gate_metrics_logs | memory utilization | +0.41 | [+0.19, +0.63] | 1 | Logs bounds checks dashboard |
| ➖ | ddot_metrics_sum_cumulativetodelta_exporter | memory utilization | +0.14 | [-0.09, +0.36] | 1 | Logs |
| ➖ | quality_gate_idle | memory utilization | +0.10 | [+0.06, +0.14] | 1 | Logs bounds checks dashboard |
| ➖ | ddot_metrics_sum_delta | memory utilization | +0.09 | [-0.08, +0.25] | 1 | Logs |
| ➖ | uds_dogstatsd_20mb_12k_contexts_20_senders | memory utilization | +0.07 | [+0.01, +0.13] | 1 | Logs |
| ➖ | otlp_ingest_metrics | memory utilization | +0.05 | [-0.10, +0.21] | 1 | Logs |
| ➖ | quality_gate_idle_all_features | memory utilization | +0.04 | [+0.01, +0.08] | 1 | Logs bounds checks dashboard |
| ➖ | file_tree | memory utilization | +0.03 | [-0.02, +0.07] | 1 | Logs |
| ➖ | file_to_blackhole_500ms_latency | egress throughput | +0.01 | [-0.37, +0.39] | 1 | Logs |
| ➖ | uds_dogstatsd_to_api | ingress throughput | +0.00 | [-0.13, +0.13] | 1 | Logs |
| ➖ | uds_dogstatsd_to_api_v3 | ingress throughput | -0.00 | [-0.13, +0.12] | 1 | Logs |
| ➖ | tcp_dd_logs_filter_exclude | ingress throughput | -0.00 | [-0.10, +0.09] | 1 | Logs |
| ➖ | file_to_blackhole_0ms_latency | egress throughput | -0.01 | [-0.49, +0.46] | 1 | Logs |
| ➖ | ddot_metrics | memory utilization | -0.01 | [-0.19, +0.17] | 1 | Logs |
| ➖ | file_to_blackhole_100ms_latency | egress throughput | -0.04 | [-0.08, +0.00] | 1 | Logs |
| ➖ | file_to_blackhole_1000ms_latency | egress throughput | -0.06 | [-0.49, +0.36] | 1 | Logs |
| ➖ | tcp_syslog_to_blackhole | ingress throughput | -0.10 | [-0.17, -0.02] | 1 | Logs |
| ➖ | docker_containers_memory | memory utilization | -0.25 | [-0.32, -0.18] | 1 | Logs |
| ➖ | otlp_ingest_logs | memory utilization | -0.45 | [-0.54, -0.35] | 1 | Logs |
| ➖ | docker_containers_cpu | % cpu utilization | -0.50 | [-3.63, +2.64] | 1 | Logs |
Bounds Checks: ✅ Passed
| perf | experiment | bounds_check_name | replicates_passed | links |
|---|---|---|---|---|
| ✅ | docker_containers_cpu | simple_check_run | 10/10 | |
| ✅ | docker_containers_memory | memory_usage | 10/10 | |
| ✅ | docker_containers_memory | simple_check_run | 10/10 | |
| ✅ | file_to_blackhole_0ms_latency | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_0ms_latency | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_1000ms_latency | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_1000ms_latency | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_100ms_latency | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_100ms_latency | memory_usage | 10/10 | |
| ✅ | file_to_blackhole_500ms_latency | lost_bytes | 10/10 | |
| ✅ | file_to_blackhole_500ms_latency | memory_usage | 10/10 | |
| ✅ | quality_gate_idle | intake_connections | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_idle | memory_usage | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | intake_connections | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | memory_usage | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_logs | intake_connections | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_logs | lost_bytes | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_logs | memory_usage | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | cpu_usage | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | intake_connections | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | lost_bytes | 10/10 | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | memory_usage | 10/10 | bounds checks dashboard |
Explanation
Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%
Performance changes are noted in the perf column of each table:
- ✅ = significantly better comparison variant performance
- ❌ = significantly worse comparison variant performance
- ➖ = no significant change in performance
A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".
For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:
-
Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.
-
Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.
-
Its configuration does not mark it "erratic".
CI Pass/Fail Decision
✅ Passed. All Quality Gates passed.
- quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
3cb6e00 to
b84e9b1
Compare
…e calls require functions don't return a value (unlike assert which returns bool), so they can't be used in || expressions. Split combined conditions into separate require calls.
b84e9b1 to
93c1301
Compare
- Fix gofmt import ordering in process_collector_test.go - Remove unused getCheckNames function in process_autodiscovery_test.go (was only used in debug logging lines that were removed) - Revert require.Equal back to assert.Equal in end_to_end_test.go where the variable t is assert.TestingT (which lacks FailNow required by require)
93c1301 to
3d5a831
Compare
|
All contributors have signed the CLA ✍️ ✅ |
6b455ff to
8dfe6d5
Compare
…ch calls logs in their loops
What does this PR do?
Replaces
if !assert.XXX(...) { return }guard patterns withrequire.XXX(...)across test files.The testify PR stretchr/testify#1481 (merged June 2024, included in testify v1.11.1) made
requirework safely with*assert.CollectTinsideEventuallyWithTcallbacks.CollectT.FailNow()callsruntime.Goexit()which exits the callback goroutine — this is caught by theEventuallyWithTretry loop, so the test continues retrying as expected.Changes across 31 test files (~115 replacements):
test/new-e2e/tests/containers/—base_test.go,ecs_test.go,k8s_test.gotest/new-e2e/tests/—discovery/,agent-runtimes/,cspm/,cws/,npm/,netpath/,remote-config/,windows/,agent-health/,agent-log-pipelines/pkg/network/tracer/,pkg/dyninst/,pkg/util/,comp/core/telemetry/, etc.// Can be replaced by require... once PR #1481 is mergedcommentsImportant:
requiremust not be used inside raw goroutinesWhile
requireis safe insideEventuallyWithTcallbacks (thanks toCollectT.FailNow()integration), it must not be used inside rawgo func()blocks or HTTP handler callbacks.t.FailNow()callsruntime.Goexit()to stop the current goroutine. The official Gotestingdocumentation states:EventuallyWithTis a special case: testify runs the condition viago checkCond(), butCollectTimplements its ownFailNow()that safely exits the callback goroutine and lets the retry loop continue.Not converted (intentionally left as
assert):go func()blocks (e.g.,pkg/util/winutil/eventlog/tests)boolorerror(not test flow control)Motivation
Using
assertas a guard is error-prone: if someone forgets theif !... { return }wrapper, the test continues and panics when accessing nil/empty results (e.g.,metrics[len(metrics)-1]on an empty slice).requiremakes the "stop on failure" intent explicit and eliminates the boilerplate.Describe how you validated your changes
requireworks correctly insideEventuallyWithTcallbacks (viaCollectT.FailNow()→runtime.Goexit()caught by retry loop)go func()call sites were left unchangedrequirestops execution on failure, which is exactly what theif !assert... { return }pattern was doing manuallyAdditional Notes
The remaining
if !assertoccurrences across other files were reviewed and intentionally kept because they serve different purposes (returning values from helper functions, setting flags, logging diagnostics without stopping, running inside raw goroutines, etc.).