Skip to content

Commit 511471b

Browse files
committed
testutil: improve initializing mirrors
Instead of running a mirror for each `integration.Run` call, only run it if there is actual sandboxed test running. This speeds up running tests with a filter as if all the tests from a given suite are inactive, no time is spent running the mirror. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 76945ca commit 511471b

File tree

1 file changed

+17
-5
lines changed
  • util/testutil/integration

1 file changed

+17
-5
lines changed

util/testutil/integration/run.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"runtime"
1414
"sort"
1515
"strings"
16+
"sync"
1617
"testing"
1718
"time"
1819

@@ -161,10 +162,7 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
161162
o(&tc)
162163
}
163164

164-
mirror, cleanup, err := runMirror(t, tc.mirroredImages)
165-
require.NoError(t, err)
166-
167-
t.Cleanup(func() { _ = cleanup() })
165+
getMirror := lazyMirrorRunnerFunc(t, tc.mirroredImages)
168166

169167
matrix := prepareValueMatrix(tc)
170168

@@ -200,7 +198,7 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
200198
ctx, cancel := context.WithCancelCause(ctx)
201199
defer cancel(errors.WithStack(context.Canceled))
202200

203-
sb, closer, err := newSandbox(ctx, br, mirror, mv)
201+
sb, closer, err := newSandbox(ctx, br, getMirror(), mv)
204202
require.NoError(t, err)
205203
t.Cleanup(func() { _ = closer() })
206204
defer func() {
@@ -329,6 +327,20 @@ func WriteConfig(updaters []ConfigUpdater) (string, error) {
329327
return filepath.Join(tmpdir, buildkitdConfigFile), nil
330328
}
331329

330+
func lazyMirrorRunnerFunc(t *testing.T, images map[string]string) func() string {
331+
var once sync.Once
332+
var mirror string
333+
return func() string {
334+
once.Do(func() {
335+
host, cleanup, err := runMirror(t, images)
336+
require.NoError(t, err)
337+
t.Cleanup(func() { _ = cleanup() })
338+
mirror = host
339+
})
340+
return mirror
341+
}
342+
}
343+
332344
func runMirror(t *testing.T, mirroredImages map[string]string) (host string, _ func() error, err error) {
333345
mirrorDir := os.Getenv("BUILDKIT_REGISTRY_MIRROR_DIR")
334346

0 commit comments

Comments
 (0)