Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hariso committed Jan 4, 2024
1 parent 4d6beef commit 4d28fb0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
4 changes: 0 additions & 4 deletions pkg/plugin/processor/standalone/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -24,8 +22,6 @@ import (
"github.com/matryer/is"
)

var testPluginDir = "./test/wasm_processors/"

func TestRegistry_List(t *testing.T) {
is := is.New(t)

Expand Down
39 changes: 39 additions & 0 deletions pkg/plugin/processor/standalone/standalone_test.go
Original file line number Diff line number Diff line change
@@ -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())
}
12 changes: 10 additions & 2 deletions pkg/plugin/processor/standalone/wasm_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}

Expand Down Expand Up @@ -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(
Expand Down
19 changes: 0 additions & 19 deletions pkg/plugin/processor/standalone/wasm_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ package standalone

import (
"context"
"fmt"
"os"
"os/exec"

//nolint:depguard // needed to test external error
"errors"
"testing"
Expand All @@ -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()
Expand Down

0 comments on commit 4d28fb0

Please sign in to comment.