Skip to content

Commit

Permalink
observer_test_helper: properly clenup base sensor
Browse files Browse the repository at this point in the history
During a test failure, where loading a sensor failed, the next test
would also fail because the base sensor existed already.

Fix this by registering a cleanup function to unload the base sensor
rogjt after we load it.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Sep 12, 2024
1 parent 28d7d30 commit 02caee5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/observer/observertesthelper/observer_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ func loadObserver(tb testing.TB, ctx context.Context, base *sensors.Sensor,
if err := base.Load(option.Config.BpfDir); err != nil {
tb.Fatalf("Load base error: %s\n", err)
}
tb.Cleanup(func() {
base.Unload()
})

if tp != nil {
if err := observer.GetSensorManager().AddTracingPolicy(ctx, tp); err != nil {
Expand All @@ -432,7 +435,6 @@ func loadObserver(tb testing.TB, ctx context.Context, base *sensors.Sensor,

tb.Cleanup(func() {
observer.RemoveSensors(ctx)
base.Unload()
})
return nil
}
Expand Down

0 comments on commit 02caee5

Please sign in to comment.