From c3576579dd8e022ff6824b5c89667867279b8974 Mon Sep 17 00:00:00 2001 From: Leonardo Di Giovanna Date: Wed, 22 Jan 2025 10:36:32 +0100 Subject: [PATCH] fix(decl/runners): fix host runner delegation logic Signed-off-by: Leonardo Di Giovanna --- pkg/test/runner/host/host.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/test/runner/host/host.go b/pkg/test/runner/host/host.go index 300f0e87..d41b408a 100644 --- a/pkg/test/runner/host/host.go +++ b/pkg/test/runner/host/host.go @@ -100,9 +100,14 @@ func (r *hostRunner) Run(ctx context.Context, testID string, testDesc *loader.Te testLogger := r.logger.WithName("test") if testContext := testDesc.Context; testContext != nil { - if err := r.setUpContext(ctx, testLogger.WithName("context"), testID, testDesc); err != nil { + delegated, err := r.setUpContext(ctx, testLogger.WithName("context"), testID, testDesc) + if err != nil { return fmt.Errorf("error setting up the context: %w", err) } + + if delegated { + return nil + } } // Build test. @@ -119,32 +124,33 @@ func (r *hostRunner) Run(ctx context.Context, testID string, testDesc *loader.Te return nil } -// setUpContext sets up the context specified in the provided test description. +// setUpContext sets up the context specified in the provided test description. The function returns a boolean +// indicating if the test execution was delegated to a container/child process. func (r *hostRunner) setUpContext(ctx context.Context, logger logr.Logger, testID string, - testDesc *loader.Test) error { + testDesc *loader.Test) (delegated bool, err error) { testContext := testDesc.Context // Delegate to container if the user specified a container context. if testContext.Container != nil { logger := logger.WithName("container") if err := r.delegateToContainer(ctx, logger, testID, testDesc); err != nil { - return fmt.Errorf("error delegating to container: %w", err) + return false, fmt.Errorf("error delegating to container: %w", err) } - return nil + return true, nil } // Delegate to child process if we are not at the end of the process chain. if len(testDesc.Context.Processes) != 0 { logger := logger.WithName("process") if err := r.delegateToProcess(ctx, logger, testID, testDesc); err != nil { - return fmt.Errorf("error delegating to child process: %w", err) + return false, fmt.Errorf("error delegating to child process: %w", err) } - return nil + return true, nil } - return nil + return false, nil } // delegateToContainer delegates the execution of the test to a container, created and tuned as per test specification.