Skip to content

Commit 8c8538f

Browse files
committed
conformance tests: more parallelization
Parallelize more subtests. Use t.Cleanup() instead of "defer" for a few cleanups. CI: don't run "make all" before making the test target; we fixed the target dependencies in the Makefile so that targets ensure that what they need has been built before use. CI: build the buildah binary for the buildah_version and buildah_info tasks. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
1 parent 4ae6396 commit 8c8538f

4 files changed

Lines changed: 39 additions & 35 deletions

File tree

contrib/ci/logcollector.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ case $1 in
3333
df) showrun df -lhTx tmpfs ;;
3434
journal) showrun journalctl -b ;;
3535
podman) showrun podman system info ;;
36-
buildah_version) showrun "$GOSRC/bin/buildah" version ;;
37-
buildah_info) showrun "$GOSRC/bin/buildah" info ;;
36+
buildah_version) make bin/buildah && showrun "$GOSRC/bin/buildah" version ;;
37+
buildah_info) make bin/buildah && showrun "$GOSRC/bin/buildah" info ;;
3838
golang) showrun go version ;;
3939
packages)
4040
PKG_NAMES=(\

contrib/ci/runner.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@ function run_conformance() {
9898
}
9999

100100
function run_integration() {
101-
make all
102101
$SUDO make test-integration
103102
}
104103

105104
function run_in_podman() {
106105
export IN_PODMAN=true
107106
export BUILDAH_ISOLATION=chroot
108107
export STORAGE_DRIVER=vfs
109-
make all
110108
$SUDO make test-integration
111109
}
112110

tests/conformance/conformance_test.go

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ func TestMain(m *testing.M) {
152152
}
153153

154154
func TestConformance(t *testing.T) {
155-
t.Parallel()
156155
dateStamp := fmt.Sprintf("%d", time.Now().UnixNano())
157156
for i := range internalTestCases {
158157
t.Run(internalTestCases[i].name, func(t *testing.T) {
@@ -196,6 +195,11 @@ func TestConformance(t *testing.T) {
196195

197196
func testConformanceInternal(t *testing.T, dateStamp string, testIndex int, mutate func(*testCase)) {
198197
test := internalTestCases[testIndex]
198+
199+
if !test.dontParallelize {
200+
t.Parallel()
201+
}
202+
199203
if mutate != nil {
200204
mutate(&test)
201205
}
@@ -231,31 +235,26 @@ func testConformanceInternal(t *testing.T, dateStamp string, testIndex int, muta
231235

232236
// copy either a directory or just a Dockerfile into the temporary directory
233237
pipeReader, pipeWriter := io.Pipe()
234-
var getErr, putErr error
235238
var wg sync.WaitGroup
236-
wg.Add(1)
237-
go func() {
239+
wg.Go(func() {
238240
if test.contextDir != "" {
239-
getErr = copier.Get("", testDataDir, copier.GetOptions{}, []string{test.contextDir}, pipeWriter)
241+
err := copier.Get("", testDataDir, copier.GetOptions{}, []string{test.contextDir}, pipeWriter)
242+
assert.NoErrorf(t, err, "reading context directory %q", filepath.Join("testdata", test.contextDir))
240243
} else if test.dockerfile != "" {
241-
getErr = copier.Get("", testDataDir, copier.GetOptions{}, []string{test.dockerfile}, pipeWriter)
244+
err := copier.Get("", testDataDir, copier.GetOptions{}, []string{test.dockerfile}, pipeWriter)
245+
assert.NoErrorf(t, err, "reading dockerfile %q", filepath.Join("testdata", test.dockerfile))
242246
}
243-
pipeWriter.Close()
244-
wg.Done()
245-
}()
246-
wg.Add(1)
247-
go func() {
247+
})
248+
wg.Go(func() {
248249
if test.contextDir != "" || test.dockerfile != "" {
249-
putErr = copier.Put("", contextDir, copier.PutOptions{}, pipeReader)
250+
err := copier.Put("", contextDir, copier.PutOptions{}, pipeReader)
251+
assert.NoErrorf(t, err, "extracting build context at %q", contextDir)
250252
} else {
251-
putErr = os.Mkdir(contextDir, 0o755)
253+
err := os.Mkdir(contextDir, 0o755)
254+
assert.NoErrorf(t, err, "creating dummy context directory at %q", contextDir)
252255
}
253-
pipeReader.Close()
254-
wg.Done()
255-
}()
256+
})
256257
wg.Wait()
257-
assert.NoErrorf(t, getErr, "error reading build info from %q", filepath.Join("testdata", test.dockerfile))
258-
assert.NoErrorf(t, putErr, "error writing build info to %q", contextDir)
259258
if t.Failed() {
260259
t.FailNow()
261260
}
@@ -295,12 +294,12 @@ func testConformanceInternal(t *testing.T, dateStamp string, testIndex int, muta
295294
}
296295
store, err := storage.GetStore(options)
297296
require.NoErrorf(t, err, "error creating buildah storage at %q", rootDir)
298-
defer func() {
297+
t.Cleanup(func() {
299298
if store != nil {
300299
_, err := store.Shutdown(true)
301300
require.NoError(t, err, "error shutting down storage for buildah")
302301
}
303-
}()
302+
})
304303
storageDriver := store.GraphDriverName()
305304
storageRoot := store.GraphRoot()
306305

@@ -460,13 +459,13 @@ func testConformanceInternalBuild(ctx context.Context, t *testing.T, cwd string,
460459
if compareImagebuilder && !test.withoutImagebuilder {
461460
imagebuilderRef, imagebuilderLog = buildUsingImagebuilder(t, client, test, imagebuilderImage, contextDir, dockerfileName, line, finalOfSeveral)
462461
if imagebuilderRef != nil {
463-
defer func() {
462+
t.Cleanup(func() {
464463
err := client.RemoveImageExtended(imagebuilderImage, docker.RemoveImageOptions{
465464
Context: ctx,
466465
Force: true,
467466
})
468467
assert.Nil(t, err, "error deleting newly-built-by-imagebuilder image %q", imagebuilderImage)
469-
}()
468+
})
470469
}
471470
saveReport(ctx, t, imagebuilderRef, filepath.Join(imagebuilderDir, t.Name()), dockerfileContents, imagebuilderLog, dockerVersion)
472471
if finalOfSeveral && compareLayers {
@@ -481,10 +480,10 @@ func testConformanceInternalBuild(ctx context.Context, t *testing.T, cwd string,
481480
// always build using buildah
482481
buildahRef, buildahLog = buildUsingBuildah(ctx, t, store, test, buildahImage, contextDir, dockerfileName, line, finalOfSeveral)
483482
if buildahRef != nil {
484-
defer func() {
483+
t.Cleanup(func() {
485484
err := buildahRef.DeleteImage(ctx, nil)
486485
assert.Nil(t, err, "error deleting newly-built-by-buildah image %q", buildahImage)
487-
}()
486+
})
488487
}
489488
saveReport(ctx, t, buildahRef, filepath.Join(buildahDir, t.Name()), dockerfileContents, buildahLog, nil)
490489
if finalOfSeveral && compareLayers {
@@ -1449,6 +1448,7 @@ type (
14491448

14501449
fsSkipCompatVolumesTrue []string // more expected filesystem differences when compatVolumes=true
14511450
buildArgs map[string]string // build args to supply, as if --build-arg was used
1451+
dontParallelize bool // uses shared state managed elsewhere
14521452
}
14531453
)
14541454

@@ -3794,20 +3794,22 @@ var internalTestCases = []testCase{
37943794
},
37953795
{
37963796
name: "mount-cache-by-ownership",
3797+
dontParallelize: true, // the docker build seems to fail without this?
37973798
dockerUseBuildKit: true,
37983799
dockerfileContents: strings.Join([]string{
37993800
"FROM mirror.gcr.io/busybox",
38003801
"USER 10",
38013802
"RUN --mount=type=cache,uid=10,target=/cache touch /cache/10.txt",
38023803
"USER 0",
38033804
"RUN --mount=type=cache,target=/cache touch /cache/0.txt",
3805+
"RUN --mount=type=cache,uid=10,target=/cache touch /cache/0+10.txt",
38043806
"RUN mkdir -m 770 /results /results/0 /results/10 /results/0+10",
38053807
"RUN chown -R 10 /results",
3806-
"RUN --mount=type=cache,target=/cache cp -a /cache/* /results/0",
3808+
"RUN --mount=type=cache,target=/cache cp -av /cache/* /results/0",
38073809
"USER 10",
3808-
"RUN --mount=type=cache,uid=10,target=/cache cp -a /cache/* /results/10",
3810+
"RUN --mount=type=cache,uid=10,target=/cache cp -av /cache/* /results/10",
38093811
"USER 0",
3810-
"RUN --mount=type=cache,uid=10,target=/cache cp -a /cache/* /results/0+10",
3812+
"RUN --mount=type=cache,uid=10,target=/cache cp -av /cache/* /results/0+10",
38113813
"RUN touch -r /bin `find /results -print`",
38123814
}, "\n"),
38133815
},
@@ -3895,12 +3897,12 @@ var internalTestCases = []testCase{
38953897
}
38963898

38973899
func TestCommit(t *testing.T) {
3898-
t.Parallel()
38993900
testCases := []struct {
39003901
description string
39013902
baseImage string
39023903
changes, derivedChanges []string
39033904
config, derivedConfig *docker.Config
3905+
dontParallelize bool // uses shared state that lives elsewhere
39043906
}{
39053907
{
39063908
description: "defaults",
@@ -4239,16 +4241,20 @@ func TestCommit(t *testing.T) {
42394241
}
42404242
store, err := storage.GetStore(options)
42414243
require.NoErrorf(t, err, "error creating buildah storage at %q", rootDir)
4242-
defer func() {
4244+
t.Cleanup(func() {
42434245
if store != nil {
42444246
_, err := store.Shutdown(true)
42454247
require.NoErrorf(t, err, "error shutting down storage for buildah")
42464248
}
4247-
}()
4249+
})
42484250

42494251
// walk through test cases
42504252
for testIndex, testCase := range testCases {
42514253
t.Run(testCase.description, func(t *testing.T) {
4254+
if !testCase.dontParallelize {
4255+
t.Parallel()
4256+
}
4257+
42524258
test := testCases[testIndex]
42534259

42544260
// create the test container, then commit it, using the docker client

tests/conformance/testdata/Dockerfile.edgecases

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Note: Hopefully a registries.conf alias redirects this to quay.io/libpod/mirror.gcr.io/busybox
1+
# Note: Hopefully a registries.conf alias redirects this to quay.io/libpod/busybox
22
FROM mirror.gcr.io/busybox
33

44
MAINTAINER docker <docker@docker.io>

0 commit comments

Comments
 (0)