Skip to content

Commit 5d50928

Browse files
committed
tetragon: Unflake the TestGeneratedExecEvents test
On slow server the test might fails to start exporter fast enough making the test fail, because events did not get stored. Moving the tetragonExecuteCtx into separate process and adding extra 5 tries on checking up on the exported file. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent acc6fb7 commit 5d50928

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

cmd/tetragon/main_test.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package main
66
import (
77
"context"
88
"os"
9+
"sync"
910
"testing"
11+
"time"
1012

1113
ec "github.com/cilium/tetragon/api/v1/tetragon/codegen/eventchecker"
1214
"github.com/cilium/tetragon/pkg/defaults"
@@ -27,9 +29,6 @@ func TestMain(m *testing.M) {
2729
// exec events generated, make sure it's done.
2830
func TestGeneratedExecEvents(t *testing.T) {
2931
ctx, cancel := context.WithCancel(context.Background())
30-
ready := func() {
31-
cancel()
32-
}
3332

3433
// Minimal config to start tetragon
3534
option.Config.ExportRateLimit = -1
@@ -52,15 +51,39 @@ func TestGeneratedExecEvents(t *testing.T) {
5251
}
5352
option.Config.ExportFilename = fname
5453

55-
err = tetragonExecuteCtx(ctx, cancel, ready)
56-
assert.NoError(t, err)
54+
var wg sync.WaitGroup
55+
wg.Add(1)
56+
ready := func() {
57+
wg.Done()
58+
}
59+
60+
// Start tetragon in separate process so we can keep the whole
61+
// export/server machinery running until we get expected results.
62+
go func() {
63+
err = tetragonExecuteCtx(ctx, cancel, ready)
64+
assert.NoError(t, err)
65+
}()
66+
67+
// Wait till tetragon's observer is up and running
68+
wg.Wait()
5769

5870
// Make sure exec event with pid 1 was generated
5971
checker := ec.NewUnorderedEventChecker(
6072
ec.NewProcessExecChecker("").WithProcess(
6173
ec.NewProcessChecker().WithPid(1)),
6274
)
6375

64-
err = jsonchecker.JsonTestCheck(t, checker)
76+
// Try it 5 times and make sure exporter is up and processed all data
77+
// in case it lags for some reason like slow CI server.
78+
cnt := 0
79+
for cnt < 5 {
80+
if err = jsonchecker.JsonTestCheck(t, checker); err == nil {
81+
break
82+
}
83+
time.Sleep(time.Second)
84+
cnt++
85+
}
86+
87+
cancel()
6588
assert.NoError(t, err)
6689
}

0 commit comments

Comments
 (0)