From f3731b9258b4352fa9657f3fb021b0f9cc55be3f Mon Sep 17 00:00:00 2001 From: AydarZaynutdinov Date: Mon, 10 Jan 2022 18:42:55 +0300 Subject: [PATCH 1/2] [BEAM-13623][Playground] Add getting of error's output from `RunOutput` in case unit test is failed --- .../internal/code_processing/code_processing.go | 13 +++++++++---- .../backend/internal/streaming/run_output_writer.go | 9 ++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/playground/backend/internal/code_processing/code_processing.go b/playground/backend/internal/code_processing/code_processing.go index 56d660d9b901..6959bf82d78b 100644 --- a/playground/backend/internal/code_processing/code_processing.go +++ b/playground/backend/internal/code_processing/code_processing.go @@ -189,8 +189,13 @@ func Process(ctx context.Context, cacheService cache.Cache, lc *fs_tool.LifeCycl return } if !ok { - if runOutput.Error != nil { - runError.Write([]byte(runOutput.Error.Error())) + // If unit test has some error then error output is placed as RunOutput + if isUnitTest { + output, err := GetProcessingOutput(ctx, cacheService, pipelineId, cache.RunOutput, "") + if err == nil { + runError.Write([]byte(output)) + } + } // Run step is finished, but code contains some error (divide by 0 for example) if sdkEnv.ApacheBeamSdk == pb.Sdk_SDK_GO { @@ -431,7 +436,7 @@ func processError(ctx context.Context, errorChannel chan error, pipelineId uuid. func processErrorWithSavingOutput(ctx context.Context, err error, errorOutput []byte, pipelineId uuid.UUID, subKey cache.SubKey, cacheService cache.Cache, errorTitle string, newStatus pb.Status) error { logger.Errorf("%s: %s(): err: %s, output: %s\n", pipelineId, errorTitle, err.Error(), errorOutput) - if err := utils.SetToCache(ctx, cacheService, pipelineId, subKey, fmt.Sprintf("error: %s, output: %s", err.Error(), errorOutput)); err != nil { + if err := utils.SetToCache(ctx, cacheService, pipelineId, subKey, fmt.Sprintf("error: %s\noutput: %s", err.Error(), errorOutput)); err != nil { return err } @@ -446,7 +451,7 @@ func processRunError(ctx context.Context, errorChannel chan error, errorOutput [ err := <-errorChannel logger.Errorf("%s: Run(): err: %s, output: %s\n", pipelineId, err.Error(), errorOutput) - if err := utils.SetToCache(ctx, cacheService, pipelineId, cache.RunError, fmt.Sprintf("error: %s, output: %s", err.Error(), string(errorOutput))); err != nil { + if err := utils.SetToCache(ctx, cacheService, pipelineId, cache.RunError, fmt.Sprintf("error: %s\noutput: %s", err.Error(), string(errorOutput))); err != nil { return err } diff --git a/playground/backend/internal/streaming/run_output_writer.go b/playground/backend/internal/streaming/run_output_writer.go index 36b129371733..378e2b0ecc9b 100644 --- a/playground/backend/internal/streaming/run_output_writer.go +++ b/playground/backend/internal/streaming/run_output_writer.go @@ -27,7 +27,6 @@ type RunOutputWriter struct { Ctx context.Context CacheService cache.Cache PipelineId uuid.UUID - Error error } // Write writes len(p) bytes from p to cache with cache.RunOutput subKey. @@ -46,8 +45,8 @@ func (row *RunOutputWriter) Write(p []byte) (int, error) { prevOutput, err := row.CacheService.GetValue(row.Ctx, row.PipelineId, cache.RunOutput) if err != nil { - row.Error = err - return 0, err + customErr := fmt.Errorf("error during saving output: %s", err) + return 0, customErr } // concat prevValue and new value @@ -56,8 +55,8 @@ func (row *RunOutputWriter) Write(p []byte) (int, error) { // set new cache value err = row.CacheService.SetValue(row.Ctx, row.PipelineId, cache.RunOutput, str) if err != nil { - row.Error = err - return 0, err + customErr := fmt.Errorf("error during saving output: %s", err) + return 0, customErr } return len(p), nil } From ea54381bc9f3335f58a9740e50de9316fc3820d3 Mon Sep 17 00:00:00 2001 From: AydarZaynutdinov Date: Mon, 10 Jan 2022 18:55:02 +0300 Subject: [PATCH 2/2] [BEAM-13623][Playground] fix of tests --- .../backend/internal/code_processing/code_processing_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/playground/backend/internal/code_processing/code_processing_test.go b/playground/backend/internal/code_processing/code_processing_test.go index 7c7184ddb07a..dab32017cc40 100644 --- a/playground/backend/internal/code_processing/code_processing_test.go +++ b/playground/backend/internal/code_processing/code_processing_test.go @@ -172,7 +172,7 @@ func Test_Process(t *testing.T) { code: "MOCK_CODE", cancelFunc: false, expectedStatus: pb.Status_STATUS_COMPILE_ERROR, - expectedCompileOutput: "error: exit status 1, output: %s:1: error: reached end of file while parsing\nMOCK_CODE\n^\n1 error\n", + expectedCompileOutput: "error: exit status 1\noutput: %s:1: error: reached end of file while parsing\nMOCK_CODE\n^\n1 error\n", expectedRunOutput: nil, expectedRunError: nil, args: args{ @@ -193,7 +193,7 @@ func Test_Process(t *testing.T) { expectedStatus: pb.Status_STATUS_RUN_ERROR, expectedCompileOutput: "", expectedRunOutput: "", - expectedRunError: "error: exit status 1, output: Exception in thread \"main\" java.lang.ArithmeticException: / by zero\n\tat HelloWorld.main(%s.java:3)\n", + expectedRunError: "error: exit status 1\noutput: Exception in thread \"main\" java.lang.ArithmeticException: / by zero\n\tat HelloWorld.main(%s.java:3)\n", args: args{ ctx: context.Background(), appEnv: appEnvs,