Skip to content

Commit

Permalink
test: reduce the number of builds
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Aug 18, 2023
1 parent 00b08f2 commit c5acb3b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion jsonnetsecure/jsonnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func JsonnetTestBinary(t testing.TB) string {
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil || stderr.Len() != 0 {
t.Fatalf("building the Go binary returned error: %v\n%s", err, string(stderr.String()))
t.Fatalf("building the Go binary returned error: %v\n%s", err, stderr.String())
}

return outPath
Expand Down
4 changes: 2 additions & 2 deletions jsonnetsecure/jsonnet_processvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func NewProcessVM(opts *vmOptions) VM {
}
}

func (p *ProcessVM) EvaluateAnonymousSnippet(filename string, snippet string) (string, error) {
func (p *ProcessVM) EvaluateAnonymousSnippet(filename string, snippet string) (_ string, err error) {
tracer := trace.SpanFromContext(p.ctx).TracerProvider().Tracer("")
ctx, span := tracer.Start(p.ctx, "jsonnetsecure.ProcessVM.EvaluateAnonymousSnippet", trace.WithAttributes(attribute.String("filename", filename)))
defer span.End()
defer otelx.End(span, &err)

// We retry the process creation, because it sometimes times out.
const processVMTimeout = 1 * time.Second
Expand Down
9 changes: 6 additions & 3 deletions jsonnetsecure/jsonnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import (
)

func TestSecureVM(t *testing.T) {
testBinary := JsonnetTestBinary(t)

for _, optCase := range []struct {
name string
opts []Option
}{
{"none", []Option{}},
{"process vm", []Option{
WithProcessIsolatedVM(context.Background()),
WithJsonnetBinary(JsonnetTestBinary(t)),
WithJsonnetBinary(testBinary),
}},
} {
t.Run("options="+optCase.name, func(t *testing.T) {
Expand Down Expand Up @@ -114,7 +116,7 @@ func TestSecureVM(t *testing.T) {
defer cancel()
vm := MakeSecureVM(
WithProcessIsolatedVM(ctx),
WithJsonnetBinary(JsonnetTestBinary(t)),
WithJsonnetBinary(testBinary),
)
result, err := vm.EvaluateAnonymousSnippet("test", snippet)
require.Error(t, err)
Expand Down Expand Up @@ -161,12 +163,13 @@ func assertEqualVMOutput(t *testing.T, run func(factory func(t *testing.T) VM) s
func TestCreateMultipleProcessVMs(t *testing.T) {
ctx := context.Background()
wg := new(errgroup.Group)
testBinary := JsonnetTestBinary(t)

for i := 0; i < 100; i++ {
wg.Go(func() error {
vm := MakeSecureVM(
WithProcessIsolatedVM(ctx),
WithJsonnetBinary(JsonnetTestBinary(t)),
WithJsonnetBinary(testBinary),
)
_, err := vm.EvaluateAnonymousSnippet("test", "{a:1}")

Expand Down

0 comments on commit c5acb3b

Please sign in to comment.