Skip to content

Commit

Permalink
Review: use retry instead of for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
spikat committed Dec 27, 2023
1 parent 57d583e commit 5292b3b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/security/tests/module_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"time"
"unsafe"

"github.com/avast/retry-go/v4"
"github.com/cihub/seelog"
"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -1133,11 +1134,14 @@ func newTestModule(t testing.TB, macroDefs []*rules.MacroDefinition, ruleDefs []

if opts.staticOpts.enableEBPFLess {
t.Logf("EBPFLess mode, waiting for a client to connect\n")
for i := 0; i < 120; i++ {
err := retry.Do(func() error {
if testMod.probe.PlatformProbe.(*probe.EBPFLessProbe).GetClientsCount() > 0 {
break
return nil
}
time.Sleep(time.Second)
return errors.New("No client connected, aborting")
}, retry.Delay(time.Second), retry.Attempts(120))
if err != nil {
return nil, err
}
time.Sleep(time.Second * 2) // sleep another sec to let tests starting before the tracing is ready
t.Logf("client connected\n")
Expand Down

0 comments on commit 5292b3b

Please sign in to comment.