From 02caee5409378f69acfb50ea427ab71313f10046 Mon Sep 17 00:00:00 2001 From: Kornilios Kourtis Date: Wed, 11 Sep 2024 11:04:13 +0200 Subject: [PATCH] observer_test_helper: properly clenup base sensor 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 --- pkg/observer/observertesthelper/observer_test_helper.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/observer/observertesthelper/observer_test_helper.go b/pkg/observer/observertesthelper/observer_test_helper.go index fbcebbb20b..1d7ea1ebcf 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 }