@@ -19,7 +19,6 @@ import (
1919 "slices"
2020 "strconv"
2121 "strings"
22- "sync"
2322 "syscall"
2423 "testing"
2524 "text/tabwriter"
@@ -53,6 +52,7 @@ import (
5352 "go.podman.io/storage/pkg/idtools"
5453 "go.podman.io/storage/pkg/ioutils"
5554 "go.podman.io/storage/pkg/reexec"
55+ "golang.org/x/sync/errgroup"
5656)
5757
5858const (
@@ -152,7 +152,6 @@ func TestMain(m *testing.M) {
152152}
153153
154154func 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
197196func 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 }
@@ -232,28 +236,25 @@ func testConformanceInternal(t *testing.T, dateStamp string, testIndex int, muta
232236 // copy either a directory or just a Dockerfile into the temporary directory
233237 pipeReader , pipeWriter := io .Pipe ()
234238 var getErr , putErr error
235- var wg sync.WaitGroup
236- wg .Add (1 )
237- go func () {
239+ var eg errgroup.Group
240+ eg .Go (func () error {
238241 if test .contextDir != "" {
239242 getErr = copier .Get ("" , testDataDir , copier.GetOptions {}, []string {test .contextDir }, pipeWriter )
240243 } else if test .dockerfile != "" {
241244 getErr = copier .Get ("" , testDataDir , copier.GetOptions {}, []string {test .dockerfile }, pipeWriter )
242245 }
243- pipeWriter .Close ()
244- wg .Done ()
245- }()
246- wg .Add (1 )
247- go func () {
246+ return errors .Join (getErr , pipeWriter .Close ())
247+ })
248+ eg .Go (func () error {
248249 if test .contextDir != "" || test .dockerfile != "" {
249250 putErr = copier .Put ("" , contextDir , copier.PutOptions {}, pipeReader )
250251 } else {
251252 putErr = os .Mkdir (contextDir , 0o755 )
252253 }
253- pipeReader .Close ()
254- wg . Done ( )
255- } ()
256- wg . Wait ( )
254+ return errors . Join ( putErr , pipeReader .Close () )
255+ } )
256+ err = eg . Wait ()
257+ assert . NoErrorf ( t , err , "error copying build info from %q" , filepath . Join ( "testdata" , test . dockerfile ) )
257258 assert .NoErrorf (t , getErr , "error reading build info from %q" , filepath .Join ("testdata" , test .dockerfile ))
258259 assert .NoErrorf (t , putErr , "error writing build info to %q" , contextDir )
259260 if t .Failed () {
@@ -295,12 +296,12 @@ func testConformanceInternal(t *testing.T, dateStamp string, testIndex int, muta
295296 }
296297 store , err := storage .GetStore (options )
297298 require .NoErrorf (t , err , "error creating buildah storage at %q" , rootDir )
298- defer func () {
299+ t . Cleanup ( func () {
299300 if store != nil {
300301 _ , err := store .Shutdown (true )
301302 require .NoError (t , err , "error shutting down storage for buildah" )
302303 }
303- }( )
304+ })
304305 storageDriver := store .GraphDriverName ()
305306 storageRoot := store .GraphRoot ()
306307
@@ -460,13 +461,13 @@ func testConformanceInternalBuild(ctx context.Context, t *testing.T, cwd string,
460461 if compareImagebuilder && ! test .withoutImagebuilder {
461462 imagebuilderRef , imagebuilderLog = buildUsingImagebuilder (t , client , test , imagebuilderImage , contextDir , dockerfileName , line , finalOfSeveral )
462463 if imagebuilderRef != nil {
463- defer func () {
464+ t . Cleanup ( func () {
464465 err := client .RemoveImageExtended (imagebuilderImage , docker.RemoveImageOptions {
465466 Context : ctx ,
466467 Force : true ,
467468 })
468469 assert .Nil (t , err , "error deleting newly-built-by-imagebuilder image %q" , imagebuilderImage )
469- }( )
470+ })
470471 }
471472 saveReport (ctx , t , imagebuilderRef , filepath .Join (imagebuilderDir , t .Name ()), dockerfileContents , imagebuilderLog , dockerVersion )
472473 if finalOfSeveral && compareLayers {
@@ -481,10 +482,10 @@ func testConformanceInternalBuild(ctx context.Context, t *testing.T, cwd string,
481482 // always build using buildah
482483 buildahRef , buildahLog = buildUsingBuildah (ctx , t , store , test , buildahImage , contextDir , dockerfileName , line , finalOfSeveral )
483484 if buildahRef != nil {
484- defer func () {
485+ t . Cleanup ( func () {
485486 err := buildahRef .DeleteImage (ctx , nil )
486487 assert .Nil (t , err , "error deleting newly-built-by-buildah image %q" , buildahImage )
487- }( )
488+ })
488489 }
489490 saveReport (ctx , t , buildahRef , filepath .Join (buildahDir , t .Name ()), dockerfileContents , buildahLog , nil )
490491 if finalOfSeveral && compareLayers {
@@ -1449,6 +1450,7 @@ type (
14491450
14501451 fsSkipCompatVolumesTrue []string // more expected filesystem differences when compatVolumes=true
14511452 buildArgs map [string ]string // build args to supply, as if --build-arg was used
1453+ dontParallelize bool // uses shared state managed elsewhere
14521454 }
14531455)
14541456
@@ -3794,20 +3796,22 @@ var internalTestCases = []testCase{
37943796 },
37953797 {
37963798 name : "mount-cache-by-ownership" ,
3799+ dontParallelize : true , // the docker build seems to fail without this?
37973800 dockerUseBuildKit : true ,
37983801 dockerfileContents : strings .Join ([]string {
37993802 "FROM mirror.gcr.io/busybox" ,
38003803 "USER 10" ,
38013804 "RUN --mount=type=cache,uid=10,target=/cache touch /cache/10.txt" ,
38023805 "USER 0" ,
38033806 "RUN --mount=type=cache,target=/cache touch /cache/0.txt" ,
3807+ "RUN --mount=type=cache,uid=10,target=/cache touch /cache/0+10.txt" ,
38043808 "RUN mkdir -m 770 /results /results/0 /results/10 /results/0+10" ,
38053809 "RUN chown -R 10 /results" ,
3806- "RUN --mount=type=cache,target=/cache cp -a /cache/* /results/0" ,
3810+ "RUN --mount=type=cache,target=/cache cp -av /cache/* /results/0" ,
38073811 "USER 10" ,
3808- "RUN --mount=type=cache,uid=10,target=/cache cp -a /cache/* /results/10" ,
3812+ "RUN --mount=type=cache,uid=10,target=/cache cp -av /cache/* /results/10" ,
38093813 "USER 0" ,
3810- "RUN --mount=type=cache,uid=10,target=/cache cp -a /cache/* /results/0+10" ,
3814+ "RUN --mount=type=cache,uid=10,target=/cache cp -av /cache/* /results/0+10" ,
38113815 "RUN touch -r /bin `find /results -print`" ,
38123816 }, "\n " ),
38133817 },
@@ -3895,12 +3899,12 @@ var internalTestCases = []testCase{
38953899}
38963900
38973901func TestCommit (t * testing.T ) {
3898- t .Parallel ()
38993902 testCases := []struct {
39003903 description string
39013904 baseImage string
39023905 changes , derivedChanges []string
39033906 config , derivedConfig * docker.Config
3907+ dontParallelize bool // uses shared state that lives elsewhere
39043908 }{
39053909 {
39063910 description : "defaults" ,
@@ -4239,16 +4243,20 @@ func TestCommit(t *testing.T) {
42394243 }
42404244 store , err := storage .GetStore (options )
42414245 require .NoErrorf (t , err , "error creating buildah storage at %q" , rootDir )
4242- defer func () {
4246+ t . Cleanup ( func () {
42434247 if store != nil {
42444248 _ , err := store .Shutdown (true )
42454249 require .NoErrorf (t , err , "error shutting down storage for buildah" )
42464250 }
4247- }( )
4251+ })
42484252
42494253 // walk through test cases
42504254 for testIndex , testCase := range testCases {
42514255 t .Run (testCase .description , func (t * testing.T ) {
4256+ if ! testCase .dontParallelize {
4257+ t .Parallel ()
4258+ }
4259+
42524260 test := testCases [testIndex ]
42534261
42544262 // create the test container, then commit it, using the docker client
0 commit comments