Skip to content
Open
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
19 changes: 18 additions & 1 deletion playground/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ import (
"path/filepath"
"regexp"
"strings"
"sync"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestRecipeOpstackSimple(t *testing.T) {
t.Parallel()

tt := newTestFramework(t)
defer tt.Close()

tt.test(&OpRecipe{}, nil)
}

func TestRecipeOpstackExternalBuilder(t *testing.T) {
t.Parallel()

tt := newTestFramework(t)
defer tt.Close()

Expand All @@ -32,6 +37,8 @@ func TestRecipeOpstackExternalBuilder(t *testing.T) {
}

func TestRecipeOpstackEnableForkAfter(t *testing.T) {
t.Parallel()

tt := newTestFramework(t)
defer tt.Close()

Expand All @@ -46,13 +53,17 @@ func TestRecipeOpstackEnableForkAfter(t *testing.T) {
}

func TestRecipeL1Simple(t *testing.T) {
t.Parallel()

tt := newTestFramework(t)
defer tt.Close()

tt.test(&L1Recipe{}, nil)
}

func TestRecipeL1UseNativeReth(t *testing.T) {
t.Parallel()

tt := newTestFramework(t)
defer tt.Close()

Expand All @@ -62,6 +73,8 @@ func TestRecipeL1UseNativeReth(t *testing.T) {
}

func TestComponentBuilderHub(t *testing.T) {
t.Parallel()

tt := newTestFramework(t)
defer tt.Close()

Expand All @@ -83,6 +96,8 @@ func newTestFramework(t *testing.T) *testFramework {
return &testFramework{t: t}
}

var artifactsLock sync.Mutex

func (tt *testFramework) test(s ServiceGen, args []string) *Manifest {
t := tt.t

Expand Down Expand Up @@ -114,7 +129,10 @@ func (tt *testFramework) test(s ServiceGen, args []string) *Manifest {
err := recipe.Flags().Parse(args)
require.NoError(t, err)

artifactsLock.Lock()
_, err = recipe.Artifacts().OutputDir(e2eTestDir).Build()
artifactsLock.Unlock()

require.NoError(t, err)
}

Expand All @@ -136,7 +154,6 @@ func (tt *testFramework) test(s ServiceGen, args []string) *Manifest {
dockerRunner, err := NewLocalRunner(cfg)
require.NoError(t, err)

dockerRunner.cleanupNetwork = true
tt.runner = dockerRunner

err = dockerRunner.Run(context.Background())
Expand Down
30 changes: 13 additions & 17 deletions playground/local_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ type LocalRunner struct {
manifest *Manifest
client *client.Client

// reservedPorts is a map of port numbers reserved for each service to avoid conflicts
// since we reserve ports for all the services before they are used
reservedPorts map[int]bool

// handles stores the references to the processes that are running on host machine
// they are executed sequentially so we do not need to lock the handles
handles []*exec.Cmd
Expand All @@ -57,9 +53,6 @@ type LocalRunner struct {
// tasks tracks the status of each service
tasksMtx sync.Mutex
tasks map[string]*task

// whether to remove the network name after execution (used in testing)
cleanupNetwork bool
}

type task struct {
Expand Down Expand Up @@ -147,14 +140,13 @@ func NewLocalRunner(cfg *RunnerConfig) (*LocalRunner, error) {
}

d := &LocalRunner{
config: cfg,
out: cfg.Out,
manifest: cfg.Manifest,
client: client,
reservedPorts: map[int]bool{},
handles: []*exec.Cmd{},
tasks: tasks,
exitErr: make(chan error, 2),
config: cfg,
out: cfg.Out,
manifest: cfg.Manifest,
client: client,
handles: []*exec.Cmd{},
tasks: tasks,
exitErr: make(chan error, 2),
}

return d, nil
Expand Down Expand Up @@ -247,12 +239,16 @@ func (d *LocalRunner) Stop() error {
return nil
}

var (
reservedPorts sync.Map
)

// reservePort finds the first available port from the startPort and reserves it
// Note that we have to keep track of the port in 'reservedPorts' because
// the port allocation happens before the services uses it and binds to it.
func (d *LocalRunner) reservePort(startPort int, protocol string) int {
for i := startPort; i < startPort+1000; i++ {
if _, ok := d.reservedPorts[i]; ok {
if _, ok := reservedPorts.Load(i); ok {
continue
}

Expand Down Expand Up @@ -280,7 +276,7 @@ func (d *LocalRunner) reservePort(startPort int, protocol string) int {
panic(fmt.Sprintf("invalid protocol: %s", protocol))
}

d.reservedPorts[i] = true
reservedPorts.Store(i, true)
return i
}
panic("BUG: could not reserve a port")
Expand Down
Loading