diff --git a/test/pkg/debug/setup.go b/test/pkg/debug/setup.go index 0329029195..5867d2df2e 100644 --- a/test/pkg/debug/setup.go +++ b/test/pkg/debug/setup.go @@ -34,12 +34,20 @@ const ( var m *Monitor var e *EventClient +func BeforeSuite(ctx context.Context, config *rest.Config, kubeClient client.Client) { + m = New(ctx, config, kubeClient) + m.MustStart() +} + +func AfterSuite(ctx context.Context, config *rest.Config, kubeClient client.Client) { + m.Stop() +} + func BeforeEach(ctx context.Context, config *rest.Config, kubeClient client.Client) { // If the test is labeled as NoWatch, then the node/pod monitor will just list at the beginning // of the test rather than perform a watch during it - if !lo.Contains(ginkgo.CurrentSpecReport().Labels(), NoWatch) { - m = New(ctx, config, kubeClient) - m.MustStart() + if lo.Contains(ginkgo.CurrentSpecReport().Labels(), NoWatch) { + m.Stop() } if !lo.Contains(ginkgo.CurrentSpecReport().Labels(), NoEvents) { e = NewEventClient(kubeClient) @@ -47,8 +55,8 @@ func BeforeEach(ctx context.Context, config *rest.Config, kubeClient client.Clie } func AfterEach(ctx context.Context) { - if !lo.Contains(ginkgo.CurrentSpecReport().Labels(), NoWatch) { - m.Stop() + if lo.Contains(ginkgo.CurrentSpecReport().Labels(), NoWatch) { + m.MustStart() } if !lo.Contains(ginkgo.CurrentSpecReport().Labels(), NoEvents) { Expect(e.DumpEvents(ctx)).To(Succeed()) diff --git a/test/suites/perf/suite_test.go b/test/suites/perf/suite_test.go index ecc1b0ea7e..0d150ca0c5 100644 --- a/test/suites/perf/suite_test.go +++ b/test/suites/perf/suite_test.go @@ -46,12 +46,14 @@ func TestPerf(t *testing.T) { RegisterFailHandler(Fail) BeforeSuite(func() { env = common.NewEnvironment(t) + debug.BeforeSuite(env.Context, env.Config, env.Client) }) AfterSuite(func() { // Write out the timestamps from our tests if err := debug.WriteTimestamps(env.OutputDir, env.TimeIntervalCollector); err != nil { log.FromContext(env).Info(fmt.Sprintf("Failed to write timestamps to files, %s", err)) } + debug.AfterSuite(env.Context, env.Config, env.Client) env.Stop() }) RunSpecs(t, "Perf")