Skip to content
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

usm: process monitor: tests: Handle test flakiness #32714

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions pkg/process/monitor/process_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,24 @@ func waitForProcessMonitor(t *testing.T, pm *ProcessMonitor) {
exitRecorder := newPidRecorder()
registerCallback(t, pm, false, getProcessCallback(exitRecorder))

for i := 0; i < 10; i++ {
const (
iterationInterval = 100 * time.Millisecond
iterations = 10
)

// Trying for 10 seconds (100 iterations * 100ms) to capture exec and exit events.
require.EventuallyWithT(t, func(ct *assert.CollectT) {
cmd := exec.Command("/bin/echo")
require.NoError(t, cmd.Run())
require.NotZero(t, cmd.Process.Pid)
require.NoError(ct, cmd.Run())
require.NotZero(ct, cmd.Process.Pid)
t.Logf("running %d", cmd.Process.Pid)
require.EventuallyWithT(t, func(ct *assert.CollectT) {
require.Truef(ct, execRecorder.has(uint32(cmd.Process.Pid)), "didn't capture exec event %d", cmd.Process.Pid)
require.True(ct, exitRecorder.has(uint32(cmd.Process.Pid)), "didn't capture exit event %d", cmd.Process.Pid)
}, 1*time.Second, 100*time.Millisecond)
}
// Trying for a second (10 iterations * 100ms) to capture exec and exit events.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this duplicates the previous comment, I would suggest removing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not the same, we have two require.Eventually, inner and outer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would clarify the difference between them, as the comment currently says the same thing ("to capture exec and exit events").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the goal is quite the same, we create a binary, and waiting up to a second to capture exit/exec events for this PID
in case we fail, we try (outer loop) up to 10 times, as the process monitor logic is not sequential

// If we failed, try to run the command again.
require.EventuallyWithT(ct, func(innerCt *assert.CollectT) {
require.Truef(innerCt, execRecorder.has(uint32(cmd.Process.Pid)), "didn't capture exec event %d", cmd.Process.Pid)
require.True(innerCt, exitRecorder.has(uint32(cmd.Process.Pid)), "didn't capture exit event %d", cmd.Process.Pid)
}, iterations*iterationInterval, iterationInterval)
}, iterations*iterations*iterationInterval, iterationInterval)
}

func initializePM(t *testing.T, pm *ProcessMonitor, useEventStream bool) {
Expand Down
Loading