From 4d28fb068150861eb86e846be1d6d75ec4cd7bfc Mon Sep 17 00:00:00 2001 From: Haris Osmanagic Date: Thu, 4 Jan 2024 15:19:22 +0100 Subject: [PATCH] pr feedback --- .../processor/standalone/registry_test.go | 4 -- .../processor/standalone/standalone_test.go | 39 +++++++++++++++++++ .../processor/standalone/wasm_processor.go | 12 +++++- .../standalone/wasm_processor_test.go | 19 --------- 4 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 pkg/plugin/processor/standalone/standalone_test.go diff --git a/pkg/plugin/processor/standalone/registry_test.go b/pkg/plugin/processor/standalone/registry_test.go index d13a2903e..375861604 100644 --- a/pkg/plugin/processor/standalone/registry_test.go +++ b/pkg/plugin/processor/standalone/registry_test.go @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:generate ./test/build-test-processors.sh - package standalone import ( @@ -24,8 +22,6 @@ import ( "github.com/matryer/is" ) -var testPluginDir = "./test/wasm_processors/" - func TestRegistry_List(t *testing.T) { is := is.New(t) diff --git a/pkg/plugin/processor/standalone/standalone_test.go b/pkg/plugin/processor/standalone/standalone_test.go new file mode 100644 index 000000000..f2aa01693 --- /dev/null +++ b/pkg/plugin/processor/standalone/standalone_test.go @@ -0,0 +1,39 @@ +// Copyright © 2023 Meroxa, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package standalone + +import ( + "fmt" + "os" + "os/exec" + "testing" +) + +var testPluginDir = "./test/wasm_processors/" + +func TestMain(m *testing.M) { + cmd := exec.Command("bash", "./test/build-test-processors.sh") + + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + // Run the command + err := cmd.Run() + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "error executing bash script: %v", err) + os.Exit(1) + } + + os.Exit(m.Run()) +} diff --git a/pkg/plugin/processor/standalone/wasm_processor.go b/pkg/plugin/processor/standalone/wasm_processor.go index 3fbd8af42..8d6aa7af6 100644 --- a/pkg/plugin/processor/standalone/wasm_processor.go +++ b/pkg/plugin/processor/standalone/wasm_processor.go @@ -55,7 +55,11 @@ func NewWASMProcessor(ctx context.Context, logger zerolog.Logger, wasmPath strin runtimeCtx, wazero.NewRuntimeConfig().WithCloseOnContextDone(true), ) - wasi_snapshot_preview1.MustInstantiate(ctx, r) + _, err := wasi_snapshot_preview1.Instantiate(ctx, r) + if err != nil { + runtimeCancel() + return nil, cerrors.Errorf("failed instantiating wasi_snapshot_preview1: %w", err) + } p := &wasmProcessor{ logger: logger, @@ -67,13 +71,15 @@ func NewWASMProcessor(ctx context.Context, logger zerolog.Logger, wasmPath strin runModStopped: make(chan struct{}), } - err := p.exportFunctions(ctx) + err = p.exportFunctions(ctx) if err != nil { + runtimeCancel() return nil, fmt.Errorf("failed exporting processor functions: %w", err) } err = p.run(ctx, wasmPath) if err != nil { + runtimeCancel() return nil, fmt.Errorf("failed running WASM module: %w", err) } @@ -121,12 +127,14 @@ func (p *wasmProcessor) write(_ context.Context, mod api.Module, ptr uint32, siz p.logger.Trace(). Int("total_bytes", len(bytes)). Uint32("allocated_size", sizeAllocated). + Str("module_name", mod.Name()). Msgf("writing command to module memory") if sizeAllocated < uint32(len(bytes)) { p.logger.Error(). Int("total_bytes", len(bytes)). Uint32("allocated_size", sizeAllocated). + Str("module_name", mod.Name()). Msgf("insufficient memory") p.replyErr <- fmt.Errorf( diff --git a/pkg/plugin/processor/standalone/wasm_processor_test.go b/pkg/plugin/processor/standalone/wasm_processor_test.go index 666c11208..79665e3d9 100644 --- a/pkg/plugin/processor/standalone/wasm_processor_test.go +++ b/pkg/plugin/processor/standalone/wasm_processor_test.go @@ -16,10 +16,6 @@ package standalone import ( "context" - "fmt" - "os" - "os/exec" - //nolint:depguard // needed to test external error "errors" "testing" @@ -29,21 +25,6 @@ import ( "github.com/rs/zerolog" ) -func TestMain(m *testing.M) { - cmd := exec.Command("bash", "./test/build-test-processors.sh") - - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - // Run the command - err := cmd.Run() - if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "error executing bash script: %v", err) - os.Exit(1) - } - - os.Exit(m.Run()) -} - func TestWASMProcessor_MalformedProcessor(t *testing.T) { is := is.New(t) ctx := context.Background()