From 09e8a06c049bca688d06547a74bd2f991aa2a66c Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 2 Mar 2020 22:35:29 -0800 Subject: [PATCH] client: improve cache key loop test Signed-off-by: Tonis Tiigi --- client/client_test.go | 52 ++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index 7c7776a62b54..2947851d2889 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -61,7 +61,7 @@ func TestIntegration(t *testing.T) { mirrors := integration.WithMirroredImages(integration.OfficialImages("busybox:latest", "alpine:latest")) integration.Run(t, []integration.Test{ - testLocalCacheExport, + testCacheExportCacheKeyLoop, testRelativeWorkDir, testFileOpMkdirMkfile, testFileOpCopyRm, @@ -136,7 +136,8 @@ func newContainerd(cdAddress string) (*containerd.Client, error) { return containerd.New(cdAddress, containerd.WithTimeout(60*time.Second), containerd.WithDefaultRuntime("io.containerd.runtime.v1.linux")) } -func testLocalCacheExport(t *testing.T, sb integration.Sandbox) { +// moby/buildkit#1336 +func testCacheExportCacheKeyLoop(t *testing.T, sb integration.Sandbox) { c, err := New(context.TODO(), sb.Address()) require.NoError(t, err) defer c.Close() @@ -148,27 +149,36 @@ func testLocalCacheExport(t *testing.T, sb integration.Sandbox) { err = ioutil.WriteFile(filepath.Join(tmpdir, "foo"), []byte("foodata"), 0600) require.NoError(t, err) - buildbase := llb.Image("alpine:latest").File(llb.Copy(llb.Local("mylocal"), "foo", "foo")) - intermed := llb.Image("alpine:latest").File(llb.Copy(buildbase, "foo", "foo")) - final := llb.Scratch().File(llb.Copy(intermed, "foo", "foooooo")) + for _, mode := range []bool{false, true} { + func(mode bool) { + t.Run(fmt.Sprintf("mode=%v", mode), func(t *testing.T) { + buildbase := llb.Image("alpine:latest").File(llb.Copy(llb.Local("mylocal"), "foo", "foo")) + if mode { // same cache keys with a separating node go to different code-path + buildbase = buildbase.Run(llb.Shlex("true")).Root() + } + intermed := llb.Image("alpine:latest").File(llb.Copy(buildbase, "foo", "foo")) + final := llb.Scratch().File(llb.Copy(intermed, "foo", "foooooo")) - def, err := final.Marshal() - require.NoError(t, err) + def, err := final.Marshal() + require.NoError(t, err) - _, err = c.Solve(context.TODO(), def, SolveOpt{ - CacheExports: []CacheOptionsEntry{ - { - Type: "local", - Attrs: map[string]string{ - "dest": filepath.Join(tmpdir, "cache"), - }, - }, - }, - LocalDirs: map[string]string{ - "mylocal": tmpdir, - }, - }, nil) - require.NoError(t, err) + _, err = c.Solve(context.TODO(), def, SolveOpt{ + CacheExports: []CacheOptionsEntry{ + { + Type: "local", + Attrs: map[string]string{ + "dest": filepath.Join(tmpdir, "cache"), + }, + }, + }, + LocalDirs: map[string]string{ + "mylocal": tmpdir, + }, + }, nil) + require.NoError(t, err) + }) + }(mode) + } } func testBridgeNetworking(t *testing.T, sb integration.Sandbox) {