diff --git a/pkg/observer/observertesthelper/observer_test_helper.go b/pkg/observer/observertesthelper/observer_test_helper.go index fbcebbb20b5..1d7ea1ebcfb 100644 --- a/pkg/observer/observertesthelper/observer_test_helper.go +++ b/pkg/observer/observertesthelper/observer_test_helper.go @@ -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 { @@ -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 }