-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix require.Eventually gotchas #31861
Conversation
Test changes on VMUse this command from test-infra-definitions to manually test this PR changes on a VM: inv aws.create-vm --pipeline-id=50645090 --os-family=ubuntu Note: This applies to commit 05195f4 |
Regression DetectorRegression Detector ResultsMetrics dashboard Baseline: 00f8f5b Optimization Goals: ✅ No significant changes detected
|
perf | experiment | goal | Δ mean % | Δ mean % CI | trials | links |
---|---|---|---|---|---|---|
➖ | quality_gate_idle_all_features | memory utilization | +2.30 | [+2.20, +2.41] | 1 | Logs bounds checks dashboard |
➖ | file_to_blackhole_1000ms_latency | egress throughput | +0.38 | [-0.39, +1.16] | 1 | Logs |
➖ | tcp_syslog_to_blackhole | ingress throughput | +0.30 | [+0.24, +0.36] | 1 | Logs |
➖ | file_to_blackhole_0ms_latency | egress throughput | +0.13 | [-0.73, +0.98] | 1 | Logs |
➖ | file_to_blackhole_1000ms_latency_linear_load | egress throughput | +0.10 | [-0.37, +0.56] | 1 | Logs |
➖ | file_to_blackhole_100ms_latency | egress throughput | +0.03 | [-0.70, +0.76] | 1 | Logs |
➖ | file_to_blackhole_300ms_latency | egress throughput | +0.02 | [-0.60, +0.65] | 1 | Logs |
➖ | tcp_dd_logs_filter_exclude | ingress throughput | -0.00 | [-0.01, +0.01] | 1 | Logs |
➖ | uds_dogstatsd_to_api | ingress throughput | -0.01 | [-0.11, +0.09] | 1 | Logs |
➖ | file_to_blackhole_500ms_latency | egress throughput | -0.07 | [-0.85, +0.71] | 1 | Logs |
➖ | file_tree | memory utilization | -0.28 | [-0.42, -0.15] | 1 | Logs |
➖ | quality_gate_idle | memory utilization | -0.46 | [-0.50, -0.42] | 1 | Logs bounds checks dashboard |
➖ | uds_dogstatsd_to_api_cpu | % cpu utilization | -0.47 | [-1.18, +0.25] | 1 | Logs |
➖ | otel_to_otel_logs | ingress throughput | -0.73 | [-1.44, -0.03] | 1 | Logs |
➖ | quality_gate_logs | % cpu utilization | -2.19 | [-5.08, +0.71] | 1 | Logs |
Bounds Checks: ❌ Failed
perf | experiment | bounds_check_name | replicates_passed | links |
---|---|---|---|---|
❌ | file_to_blackhole_0ms_latency | lost_bytes | 8/10 | |
✅ | file_to_blackhole_0ms_latency | memory_usage | 10/10 | |
✅ | file_to_blackhole_1000ms_latency | memory_usage | 10/10 | |
✅ | file_to_blackhole_1000ms_latency_linear_load | 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_300ms_latency | lost_bytes | 10/10 | |
✅ | file_to_blackhole_300ms_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 | memory_usage | 10/10 | bounds checks dashboard |
✅ | quality_gate_idle_all_features | memory_usage | 10/10 | bounds checks dashboard |
✅ | quality_gate_logs | lost_bytes | 10/10 | |
✅ | quality_gate_logs | memory_usage | 10/10 |
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 memory_usage: 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 lost_bytes: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
@@ -198,12 +198,13 @@ func (s *TracerSuite) TestTCPSendAndReceive() { | |||
require.NoError(t, err) | |||
|
|||
var conn *network.ConnectionStats | |||
require.Eventually(t, func() bool { | |||
require.EventuallyWithT(t, func(collect *assert.CollectT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this one need to be changed? I don't see any require.*
calls instead the Eventually
loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, as connections := getConnections(t, tr)
has require.NoError
in it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting when I tried something like this earlier, I discovered that when getConnections(collect, tr)
fails, it will panic because of the require call (not assert) and the resulting panic is mostly unreadable compared to using getConnections(t, tr)
. It doesn't properly turn the panic into a readable test failure. Maybe because collect
doesn't expect to ever use require
, not sure. For me, I just used t
with getConnections
inside Eventually since I am fine with it failing if getConnections
errors even once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just changed require.NoError
to require.Error
in getConnections
just to bring an output of a failure in such a case -
=== RUN TestTracerSuite/CO-RE/TestTCPSendAndReceive
tracer_test.go:201:
Error Trace: /home/guy/dd/datadog-agent/pkg/network/tracer/tracer_test.go:973
/home/guy/dd/datadog-agent/pkg/network/tracer/tracer_test.go:203
/home/guy/go/pkg/mod/golang.org/[email protected]/src/runtime/asm_amd64.s:1700
Error: An error is expected but got nil.
tracer_test.go:201:
Error Trace: /home/guy/dd/datadog-agent/pkg/network/tracer/tracer_test.go:201
Error: Condition never satisfied
Test: TestTracerSuite/CO-RE/TestTCPSendAndReceive
Messages: failed to find connection
--- FAIL: TestTracerSuite/CO-RE/TestTCPSendAndReceive (5.99s)
There's no panic, and the output seems reasonable
assert.NoError(c, err) | ||
require.Eventually(t, func() bool { | ||
clientIP, clientPort, _, err = testdns.SendDNSQueries([]string{destDomain}, destAddr, "udp") | ||
return err == nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these ones where we are checking the error are better with EventuallyWithT
since we will get these errors in the test failure output. Here if there is an error, we won't see the actual error when the test fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
if !assert.NoError(t, err) { | ||
return false | ||
} | ||
require.NoError(collect, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't return right? We don't need to continue if there is an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.*
will halt the execution immediately and fail the iteration, so we won't proceed beyond that line if there's an error
@@ -1421,7 +1423,7 @@ func (s *TracerSuite) TestUDPPythonReusePort() { | |||
|
|||
t.Log(conns) | |||
|
|||
return len(conns) == 4 | |||
require.Len(collect, conns, 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be assert.*
? The FailNow
method on CollectT
exits the program (https://github.com/stretchr/testify/blob/master/assert/assertions.go#L1975), so I am not sure this does what is intended in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we're providing collect
, require.*
will halt the execution of the current iteration, but we will retry after the sleep interval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to test this? Just looking at the code for CollectT.FailNow
(which gets called from any require.*
call), I see runtime.Goexit
being called which would just exit the program (and not continuing after the sleep?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you can try with this example
func TestExample(t *testing.T) {
i := 0
require.EventuallyWithT(t, func(ct *assert.CollectT) {
i++
t.Log("running iteration", i)
require.Greater(ct, i, 5)
require.Equal(ct, 0, i%2)
t.Log("iteration", i, "done")
}, time.Second, 100*time.Millisecond)
}
The output is
=== RUN TestExample
tracer_linux_test.go:691: running iteration 1
tracer_linux_test.go:691: running iteration 2
tracer_linux_test.go:691: running iteration 3
tracer_linux_test.go:691: running iteration 4
tracer_linux_test.go:691: running iteration 5
tracer_linux_test.go:691: running iteration 6
tracer_linux_test.go:694: iteration 6 done
--- PASS: TestExample (0.60s)
PASS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, runtime.Goexit
just terminates the current goroutine, so this should be fine.
/merge |
Devflow running:
|
/merge |
Devflow running:
|
What does this PR do?
Using
require.*
functions witht *testing.T
insiderequire.Eventually
will lead to early return (and test failure) even if the condition will be fulfilled in the next iteration. To userequire.*
methods insiderequire.Eventually
we need to userequire.EventuallyWithT
and passedcollect *assert.CollectT
instead oft *testing.T
.Motivation
Fix possible test failures due to early abort.
Describe how you validated your changes
Possible Drawbacks / Trade-offs
Additional Notes