integration: add concurrent sandbox limit

Default parallelization seems off in CI

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.8
Tonis Tiigi 2020-07-17 19:20:06 -07:00
parent f825fea268
commit adb68c2764
2 changed files with 16 additions and 1 deletions

View File

@ -23,8 +23,15 @@ import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sync/semaphore"
)
var sandboxLimiter *semaphore.Weighted
func init() {
sandboxLimiter = semaphore.NewWeighted(int64(runtime.GOMAXPROCS(0)))
}
// Backend is the minimal interface that describes a testing backend.
type Backend interface {
Address() string
@ -148,6 +155,9 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
if !strings.HasSuffix(fn, "NoParallel") {
t.Parallel()
}
require.NoError(t, sandboxLimiter.Acquire(context.TODO(), 1))
defer sandboxLimiter.Release(1)
sb, closer, err := newSandbox(br, mirror, mv)
require.NoError(t, err)
defer func() {

View File

@ -3,6 +3,7 @@ package integration
import (
"bytes"
"context"
"fmt"
"net"
"os"
"os/exec"
@ -24,6 +25,8 @@ func startCmd(cmd *exec.Cmd, logs map[string]*bytes.Buffer) (func() error, error
cmd.Stderr = b
}
fmt.Fprintf(cmd.Stderr, "> startCmd %v %+v\n", time.Now(), cmd.Args)
if err := cmd.Start(); err != nil {
return nil, err
}
@ -32,7 +35,8 @@ func startCmd(cmd *exec.Cmd, logs map[string]*bytes.Buffer) (func() error, error
stopped := make(chan struct{})
stop := make(chan struct{})
eg.Go(func() error {
_, err := cmd.Process.Wait()
st, err := cmd.Process.Wait()
fmt.Fprintf(cmd.Stderr, "> stopped %v %+v %v\n", time.Now(), st, st.ExitCode())
close(stopped)
select {
case <-stop:
@ -47,6 +51,7 @@ func startCmd(cmd *exec.Cmd, logs map[string]*bytes.Buffer) (func() error, error
case <-ctx.Done():
case <-stopped:
case <-stop:
fmt.Fprintf(cmd.Stderr, "> sending sigterm %v\n", time.Now())
cmd.Process.Signal(syscall.SIGTERM)
go func() {
select {