Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
1.18.10,
1.19.13,
1.20.14,
1.21.10,
1.22.3,
1.21.12,
1.22.5,
]
permissions:
contents: read
Expand Down
4 changes: 4 additions & 0 deletions ctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"go.uber.org/zap"
)

// DoNotCompare prevents == and != comparisons on the containing struct.
type DoNotCompare [0]func()

// StarlarkFunc is a function that can be called from Starlark.
type StarlarkFunc func(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Expand All @@ -30,6 +33,7 @@ type DynamicModuleLoader func(string) (starlet.ModuleLoader, error)

// Starbox is a wrapper of starlet.Machine with additional features.
type Starbox struct {
_ DoNotCompare
mac *starlet.Machine
mu sync.RWMutex
hasExec bool
Expand Down
31 changes: 31 additions & 0 deletions exec_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package starbox_test

import (
"fmt"
"net/http"
"reflect"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -1237,6 +1239,22 @@ func TestAddHTTPContext(t *testing.T) {
}
}

func TestConcurrentRun(t *testing.T) {
b := starbox.New("test")
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
_, err := b.Run(fmt.Sprintf(`a = (%d * (1 << 20)) * %d; print(a)`, i+1, i+2))
if err != nil {
t.Error(err)
}
}(i)
}
wg.Wait()
}

func BenchmarkRunBox(b *testing.B) {
s := hereDoc(`
a = 10
Expand All @@ -1260,6 +1278,19 @@ func BenchmarkRunBox(b *testing.B) {
}
}

func BenchmarkRunSimpleScript(b *testing.B) {
box := starbox.New("test")
b.ReportAllocs()
b.ResetTimer()
script := `a = 10; b = 20; c = a + b`
for i := 0; i < b.N; i++ {
_, err := box.Run(script)
if err != nil {
b.Error(err)
}
}
}

func BenchmarkRunScript(b *testing.B) {
s := hereDoc(`
a = 10
Expand Down
1 change: 1 addition & 0 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (

// RunnerConfig defines the execution configuration for a Starbox instance.
type RunnerConfig struct {
_ DoNotCompare
box *Starbox
fileName string
script []byte
Expand Down